Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .spec.image nil pointer #178

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/v1alpha1/database_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
}
}

if database.Spec.Image == nil && database.Spec.Image.Name == "" {
if database.Spec.Image == nil {
database.Spec.Image = &PodImage{}
}

if database.Spec.Image.Name == "" {
if database.Spec.YDBVersion == "" {
database.Spec.Image.Name = fmt.Sprintf(ImagePathFormat, RegistryPath, DefaultTag)
} else {
Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha1/storage_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
storage := obj.(*Storage)
storagelog.Info("default", "name", storage.Name)

if storage.Spec.Image == nil || storage.Spec.Image.Name == "" {
if storage.Spec.Image == nil {
storage.Spec.Image = &PodImage{}
}

if storage.Spec.Image.Name == "" {
if storage.Spec.YDBVersion == "" {
storage.Spec.Image.Name = fmt.Sprintf(ImagePathFormat, RegistryPath, DefaultTag)
} else {
Expand Down
20 changes: 10 additions & 10 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.4.40
version: 0.4.41

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.4.40"
appVersion: "0.4.41"
14 changes: 9 additions & 5 deletions deploy/ydb-operator/crds/database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2266,8 +2266,8 @@ spec:
labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/'
type: object
nodeSets:
description: (Optional) NodeSet inline configuration to split into
multiple StatefulSets
description: '(Optional) NodeSet inline configuration to split into
multiple StatefulSets Default: (not specified)'
items:
description: DatabaseNodeSetSpecInline describes an group nodes
object inside parent object
Expand Down Expand Up @@ -3327,6 +3327,10 @@ spec:
type: object
type: array
type: object
terminationGracePeriodSeconds:
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
format: int64
type: integer
tolerations:
description: (Optional) If specified, the pod's tolerations.
items:
Expand Down Expand Up @@ -4063,13 +4067,13 @@ spec:
required:
- name
type: object
storageEndpoint:
description: YDB Storage Node broker address
type: string
terminationGracePeriodSeconds:
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
format: int64
type: integer
storageEndpoint:
description: YDB Storage Node broker address
type: string
tolerations:
description: (Optional) If specified, the pod's tolerations.
items:
Expand Down
4 changes: 4 additions & 0 deletions deploy/ydb-operator/crds/databasenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,10 @@ spec:
storageEndpoint:
description: YDB Storage Node broker address
type: string
terminationGracePeriodSeconds:
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
format: int64
type: integer
tolerations:
description: (Optional) If specified, the pod's tolerations.
items:
Expand Down
4 changes: 4 additions & 0 deletions deploy/ydb-operator/crds/storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3607,6 +3607,10 @@ spec:
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
terminationGracePeriodSeconds:
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
format: int64
type: integer
tolerations:
description: (Optional) If specified, the pod's tolerations.
items:
Expand Down
4 changes: 4 additions & 0 deletions deploy/ydb-operator/crds/storagenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,10 @@ spec:
required:
- name
type: object
terminationGracePeriodSeconds:
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
format: int64
type: integer
tolerations:
description: (Optional) If specified, the pod's tolerations.
items:
Expand Down
25 changes: 25 additions & 0 deletions e2e/tests/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,31 @@ var _ = Describe("Operator smoke test", func() {
Expect(installOperatorWithHelm(testobjects.YdbNamespace)).Should(BeTrue())
})

It("Check webhook defaulter", func() {
storageSample.Spec.Image = nil
storageSample.Spec.Resources = nil
storageSample.Spec.Service = nil
storageSample.Spec.Monitoring = nil
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
defer func() {
Expect(k8sClient.Delete(ctx, storageSample)).Should(Succeed())
}()

databaseSample.Spec.StorageClusterRef.Namespace = ""
databaseSample.Spec.Image = nil
databaseSample.Spec.Service = nil
databaseSample.Spec.Domain = ""
databaseSample.Spec.Path = ""
databaseSample.Spec.Encryption = nil
databaseSample.Spec.Datastreams = nil
databaseSample.Spec.Monitoring = nil
databaseSample.Spec.StorageEndpoint = ""
Expect(k8sClient.Create(ctx, databaseSample)).Should(Succeed())
defer func() {
Expect(k8sClient.Delete(ctx, databaseSample)).Should(Succeed())
}()
})

It("general smoke pipeline, create storage + database", func() {
By("issuing create commands...")
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
Expand Down