Skip to content

Commit 2e7e7b7

Browse files
authored
Fix .spec.image nil pointer (#178)
* fix .spec.image nil pointer * bump helm chart version * add tests for webhook defaulter
1 parent 102d4ae commit 2e7e7b7

File tree

9 files changed

+68
-19
lines changed

9 files changed

+68
-19
lines changed

api/v1alpha1/database_webhook.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
6868
}
6969
}
7070

71-
if database.Spec.Image == nil && database.Spec.Image.Name == "" {
71+
if database.Spec.Image == nil {
72+
database.Spec.Image = &PodImage{}
73+
}
74+
75+
if database.Spec.Image.Name == "" {
7276
if database.Spec.YDBVersion == "" {
7377
database.Spec.Image.Name = fmt.Sprintf(ImagePathFormat, RegistryPath, DefaultTag)
7478
} else {

api/v1alpha1/storage_webhook.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
7575
storage := obj.(*Storage)
7676
storagelog.Info("default", "name", storage.Name)
7777

78-
if storage.Spec.Image == nil || storage.Spec.Image.Name == "" {
78+
if storage.Spec.Image == nil {
79+
storage.Spec.Image = &PodImage{}
80+
}
81+
82+
if storage.Spec.Image.Name == "" {
7983
if storage.Spec.YDBVersion == "" {
8084
storage.Spec.Image.Name = fmt.Sprintf(ImagePathFormat, RegistryPath, DefaultTag)
8185
} else {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/ydb-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.4.40
18+
version: 0.4.41
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.4.40"
24+
appVersion: "0.4.41"

deploy/ydb-operator/crds/database.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,8 +2266,8 @@ spec:
22662266
labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/'
22672267
type: object
22682268
nodeSets:
2269-
description: (Optional) NodeSet inline configuration to split into
2270-
multiple StatefulSets
2269+
description: '(Optional) NodeSet inline configuration to split into
2270+
multiple StatefulSets Default: (not specified)'
22712271
items:
22722272
description: DatabaseNodeSetSpecInline describes an group nodes
22732273
object inside parent object
@@ -3333,6 +3333,10 @@ spec:
33333333
type: object
33343334
type: array
33353335
type: object
3336+
terminationGracePeriodSeconds:
3337+
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
3338+
format: int64
3339+
type: integer
33363340
tolerations:
33373341
description: (Optional) If specified, the pod's tolerations.
33383342
items:
@@ -4069,13 +4073,13 @@ spec:
40694073
required:
40704074
- name
40714075
type: object
4076+
storageEndpoint:
4077+
description: YDB Storage Node broker address
4078+
type: string
40724079
terminationGracePeriodSeconds:
40734080
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
40744081
format: int64
40754082
type: integer
4076-
storageEndpoint:
4077-
description: YDB Storage Node broker address
4078-
type: string
40794083
tolerations:
40804084
description: (Optional) If specified, the pod's tolerations.
40814085
items:

deploy/ydb-operator/crds/databasenodeset.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,6 +2791,10 @@ spec:
27912791
storageEndpoint:
27922792
description: YDB Storage Node broker address
27932793
type: string
2794+
terminationGracePeriodSeconds:
2795+
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
2796+
format: int64
2797+
type: integer
27942798
tolerations:
27952799
description: (Optional) If specified, the pod's tolerations.
27962800
items:

deploy/ydb-operator/crds/storage.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,10 @@ spec:
36133613
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
36143614
type: object
36153615
type: object
3616+
terminationGracePeriodSeconds:
3617+
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
3618+
format: int64
3619+
type: integer
36163620
tolerations:
36173621
description: (Optional) If specified, the pod's tolerations.
36183622
items:

deploy/ydb-operator/crds/storagenodeset.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,10 @@ spec:
27842784
required:
27852785
- name
27862786
type: object
2787+
terminationGracePeriodSeconds:
2788+
description: (Optional) If specified, the pod's terminationGracePeriodSeconds.
2789+
format: int64
2790+
type: integer
27872791
tolerations:
27882792
description: (Optional) If specified, the pod's tolerations.
27892793
items:

e2e/tests/smoke_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,31 @@ var _ = Describe("Operator smoke test", func() {
210210
Expect(installOperatorWithHelm(testobjects.YdbNamespace)).Should(BeTrue())
211211
})
212212

213+
It("Check webhook defaulter", func() {
214+
storageSample.Spec.Image = nil
215+
storageSample.Spec.Resources = nil
216+
storageSample.Spec.Service = nil
217+
storageSample.Spec.Monitoring = nil
218+
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
219+
defer func() {
220+
Expect(k8sClient.Delete(ctx, storageSample)).Should(Succeed())
221+
}()
222+
223+
databaseSample.Spec.StorageClusterRef.Namespace = ""
224+
databaseSample.Spec.Image = nil
225+
databaseSample.Spec.Service = nil
226+
databaseSample.Spec.Domain = ""
227+
databaseSample.Spec.Path = ""
228+
databaseSample.Spec.Encryption = nil
229+
databaseSample.Spec.Datastreams = nil
230+
databaseSample.Spec.Monitoring = nil
231+
databaseSample.Spec.StorageEndpoint = ""
232+
Expect(k8sClient.Create(ctx, databaseSample)).Should(Succeed())
233+
defer func() {
234+
Expect(k8sClient.Delete(ctx, databaseSample)).Should(Succeed())
235+
}()
236+
})
237+
213238
It("general smoke pipeline, create storage + database", func() {
214239
By("issuing create commands...")
215240
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())

0 commit comments

Comments
 (0)