Skip to content

Commit 852cad5

Browse files
authored
removed CEL validations for StorageCapacity (#1032)
1 parent 71e2602 commit 852cad5

File tree

7 files changed

+27
-159
lines changed

7 files changed

+27
-159
lines changed

api/core/v1alpha1/crds/druid.gardener.cloud_etcds.yaml

-12
Original file line numberDiff line numberDiff line change
@@ -1840,9 +1840,6 @@ spec:
18401840
description: StorageCapacity defines the size of persistent volume.
18411841
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
18421842
x-kubernetes-int-or-string: true
1843-
x-kubernetes-validations:
1844-
- message: etcd.spec.storageCapacity is an immutable field
1845-
rule: self == oldSelf
18461843
storageClass:
18471844
description: |-
18481845
StorageClass defines the name of the StorageClass required by the claim.
@@ -1864,15 +1861,6 @@ spec:
18641861
- labels
18651862
- replicas
18661863
type: object
1867-
x-kubernetes-validations:
1868-
- message: If backups are enabled, then value of etcd.spec.storageCapacity
1869-
must be 3 times the value of etcd.spec.etcd.quota or more. If backups
1870-
are disabled, then value of etcd.spec.storageCapacity must be the
1871-
value of etcd.spec.etcd.quota or more.
1872-
rule: 'has(self.storageCapacity) && has(self.etcd.quota) ? (has(self.backup.store)
1873-
? ((quantity(self.storageCapacity).isLessThan(quantity(self.etcd.quota).add(quantity(self.etcd.quota)).add(quantity(self.etcd.quota)))
1874-
) ? false : true): (quantity(self.storageCapacity).isLessThan(quantity(self.etcd.quota))
1875-
? false : true) ): true'
18761864
status:
18771865
description: EtcdStatus defines the observed state of Etcd.
18781866
properties:

api/core/v1alpha1/etcd.go

-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ type SchedulingConstraints struct {
288288
}
289289

290290
// EtcdSpec defines the desired state of Etcd
291-
// +kubebuilder:validation:XValidation:message="If backups are enabled, then value of etcd.spec.storageCapacity must be 3 times the value of etcd.spec.etcd.quota or more. If backups are disabled, then value of etcd.spec.storageCapacity must be the value of etcd.spec.etcd.quota or more.",rule="has(self.storageCapacity) && has(self.etcd.quota) ? (has(self.backup.store) ? ((quantity(self.storageCapacity).isLessThan(quantity(self.etcd.quota).add(quantity(self.etcd.quota)).add(quantity(self.etcd.quota))) ) ? false : true): (quantity(self.storageCapacity).isLessThan(quantity(self.etcd.quota)) ? false : true) ): true"
292291
type EtcdSpec struct {
293292
// selector is a label query over pods that should match the replica count.
294293
// It must match the pod template's labels.
@@ -321,7 +320,6 @@ type EtcdSpec struct {
321320
StorageClass *string `json:"storageClass,omitempty"`
322321
// StorageCapacity defines the size of persistent volume.
323322
// +optional
324-
// +kubebuilder:validation:XValidation:message="etcd.spec.storageCapacity is an immutable field",rule="self == oldSelf"
325323
StorageCapacity *resource.Quantity `json:"storageCapacity,omitempty"`
326324
// VolumeClaimTemplate defines the volume claim template to be created
327325
// +optional

test/it/crdvalidation/etcd/helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
)
2828

2929
// common function used by all the test cases to create an etcd resource based on the individual test case's specifications.
30-
func validateEtcdCreation(t *testing.T, g *WithT, etcd *druidv1alpha1.Etcd, expectErr bool) {
30+
func validateEtcdCreation(g *WithT, etcd *druidv1alpha1.Etcd, expectErr bool) {
3131
cl := itTestEnv.GetClient()
3232
ctx := context.Background()
3333

@@ -38,7 +38,7 @@ func validateEtcdCreation(t *testing.T, g *WithT, etcd *druidv1alpha1.Etcd, expe
3838
g.Expect(cl.Create(ctx, etcd)).To(Succeed())
3939
}
4040

41-
func validateEtcdUpdation(t *testing.T, g *WithT, etcd *druidv1alpha1.Etcd, expectErr bool, ctx context.Context, cl client.Client) {
41+
func validateEtcdUpdate(g *WithT, etcd *druidv1alpha1.Etcd, expectErr bool, ctx context.Context, cl client.Client) {
4242
updateErr := cl.Update(ctx, etcd)
4343
if expectErr {
4444
g.Expect(updateErr).ToNot(BeNil())

test/it/crdvalidation/etcd/specbackup_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestValidateSpecBackupGarbageCollectionPolicy(t *testing.T) {
3333
t.Run(test.name, func(t *testing.T) {
3434
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
3535
etcd.Spec.Backup.GarbageCollectionPolicy = (*druidv1alpha1.GarbageCollectionPolicy)(&test.garbageCollectionPolicy)
36-
validateEtcdCreation(t, g, etcd, test.expectErr)
36+
validateEtcdCreation(g, etcd, test.expectErr)
3737
})
3838
}
3939
}
@@ -85,7 +85,7 @@ func TestValidateSpecBackupCompressionPolicy(t *testing.T) {
8585
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
8686
etcd.Spec.Backup.SnapshotCompression = &druidv1alpha1.CompressionSpec{}
8787
etcd.Spec.Backup.SnapshotCompression.Policy = (*druidv1alpha1.CompressionPolicy)(&test.policy)
88-
validateEtcdCreation(t, g, etcd, test.expectErr)
88+
validateEtcdCreation(g, etcd, test.expectErr)
8989
})
9090
}
9191
}
@@ -104,7 +104,7 @@ func TestValidateSpecBackupDeltaSnapshotRetentionPeriod(t *testing.T) {
104104
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
105105
etcd.Spec.Backup.DeltaSnapshotRetentionPeriod = duration
106106

107-
validateEtcdCreation(t, g, etcd, test.expectErr)
107+
validateEtcdCreation(g, etcd, test.expectErr)
108108
})
109109
}
110110
}
@@ -121,7 +121,7 @@ func TestValidateSpecBackupEtcdSnapshotTimeout(t *testing.T) {
121121
}
122122
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
123123
etcd.Spec.Backup.EtcdSnapshotTimeout = duration
124-
validateEtcdCreation(t, g, etcd, test.expectErr)
124+
validateEtcdCreation(g, etcd, test.expectErr)
125125
})
126126
}
127127
}
@@ -140,7 +140,7 @@ func TestValidateSpecBackupLeaderElectionReelectionPeriod(t *testing.T) {
140140
etcd.Spec.Backup.LeaderElection = &druidv1alpha1.LeaderElectionSpec{}
141141
etcd.Spec.Backup.LeaderElection.ReelectionPeriod = duration
142142

143-
validateEtcdCreation(t, g, etcd, test.expectErr)
143+
validateEtcdCreation(g, etcd, test.expectErr)
144144
})
145145
}
146146
}
@@ -159,7 +159,7 @@ func TestValidateSpecBackupLeaderElectionEtcdConnectionTimeout(t *testing.T) {
159159
etcd.Spec.Backup.LeaderElection = &druidv1alpha1.LeaderElectionSpec{}
160160
etcd.Spec.Backup.LeaderElection.EtcdConnectionTimeout = duration
161161

162-
validateEtcdCreation(t, g, etcd, test.expectErr)
162+
validateEtcdCreation(g, etcd, test.expectErr)
163163
})
164164
}
165165
}
@@ -177,7 +177,7 @@ func TestValidateSpecBackupGarbageCollectionPeriod(t *testing.T) {
177177
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
178178
etcd.Spec.Backup.GarbageCollectionPeriod = duration
179179

180-
validateEtcdCreation(t, g, etcd, test.expectErr)
180+
validateEtcdCreation(g, etcd, test.expectErr)
181181
})
182182
}
183183
}
@@ -195,7 +195,7 @@ func TestValidateSpecBackupDeltaSnapshotPeriod(t *testing.T) {
195195
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
196196
etcd.Spec.Backup.DeltaSnapshotPeriod = duration
197197

198-
validateEtcdCreation(t, g, etcd, test.expectErr)
198+
validateEtcdCreation(g, etcd, test.expectErr)
199199
})
200200
}
201201
}
@@ -250,7 +250,7 @@ func TestValidateSpecBackupGCDeltaSnapshotPeriodRelation(t *testing.T) {
250250
etcd.Spec.Backup.GarbageCollectionPeriod = garbageCollectionDuration
251251
etcd.Spec.Backup.DeltaSnapshotPeriod = deltaSnapshotDuration
252252

253-
validateEtcdCreation(t, g, etcd, test.expectErr)
253+
validateEtcdCreation(g, etcd, test.expectErr)
254254

255255
})
256256
}
@@ -265,7 +265,7 @@ func TestValidateSpecBackupFullSnapshotSchedule(t *testing.T) {
265265
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
266266
etcd.Spec.Backup.FullSnapshotSchedule = &test.value
267267

268-
validateEtcdCreation(t, g, etcd, test.expectErr)
268+
validateEtcdCreation(g, etcd, test.expectErr)
269269
})
270270
}
271271
}

test/it/crdvalidation/etcd/specetcd_test.go

+4-78
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import (
1111

1212
druidv1alpha1 "github.com/gardener/etcd-druid/api/core/v1alpha1"
1313
"github.com/gardener/etcd-druid/test/utils"
14-
15-
corev1 "k8s.io/api/core/v1"
16-
"k8s.io/apimachinery/pkg/api/resource"
1714
)
1815

1916
// runs the validation on the etcd.spec.etcd.etcdDefragTimeout field.
@@ -29,7 +26,7 @@ func TestValidateSpecEtcdEtcdDefragTimeout(t *testing.T) {
2926

3027
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
3128
etcd.Spec.Etcd.EtcdDefragTimeout = duration
32-
validateEtcdCreation(t, g, etcd, test.expectErr)
29+
validateEtcdCreation(g, etcd, test.expectErr)
3330
})
3431
}
3532

@@ -48,7 +45,7 @@ func TestValidateSpecEtcdHeartbeatDuration(t *testing.T) {
4845

4946
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
5047
etcd.Spec.Etcd.HeartbeatDuration = duration
51-
validateEtcdCreation(t, g, etcd, test.expectErr)
48+
validateEtcdCreation(g, etcd, test.expectErr)
5249
})
5350
}
5451

@@ -94,7 +91,7 @@ func TestValidateSpecEtcdMetrics(t *testing.T) {
9491
t.Run(test.name, func(t *testing.T) {
9592
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
9693
etcd.Spec.Etcd.Metrics = (*druidv1alpha1.MetricsLevel)(&test.metricsValue)
97-
validateEtcdCreation(t, g, etcd, test.expectErr)
94+
validateEtcdCreation(g, etcd, test.expectErr)
9895
})
9996
}
10097

@@ -108,79 +105,8 @@ func TestValidateSpecEtcdDefragmentationSchedule(t *testing.T) {
108105
t.Run(test.name, func(t *testing.T) {
109106
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
110107
etcd.Spec.Etcd.DefragmentationSchedule = &test.value
111-
validateEtcdCreation(t, g, etcd, test.expectErr)
112-
113-
})
114-
}
115-
}
116-
117-
// checks that if the values for etcd.spec.storageCapacity and etcd.spec.etcd.quota are valid, then if backups are enabled, the value of storageCapacity must be > 3x value of quota. If backups are not enabled, value of storageCapacity must be > quota
118-
func TestValidateSpecStorageCapacitySpecEtcdQuotaRelation(t *testing.T) {
119-
skipCELTestsForOlderK8sVersions(t)
120-
testNs, g := setupTestEnvironment(t)
121-
tests := []struct {
122-
name string
123-
etcdName string
124-
storageCapacity resource.Quantity
125-
quota resource.Quantity
126-
backupEnabled bool
127-
expectErr bool
128-
}{
129-
{
130-
name: "Valid #1: backups enabled",
131-
etcdName: "etcd-valid-1",
132-
storageCapacity: resource.MustParse("27Gi"),
133-
quota: resource.MustParse("8Gi"),
134-
backupEnabled: true,
135-
expectErr: false,
136-
},
137-
{
138-
name: "Valid #2: backups disabled",
139-
etcdName: "etcd-valid-2",
140-
storageCapacity: resource.MustParse("12Gi"),
141-
quota: resource.MustParse("8Gi"),
142-
backupEnabled: false,
143-
expectErr: false,
144-
},
145-
{
146-
name: "Invalid #1: backups enabled",
147-
etcdName: "etcd-invalid-1",
148-
storageCapacity: resource.MustParse("15Gi"),
149-
quota: resource.MustParse("8Gi"),
150-
backupEnabled: true,
151-
expectErr: true,
152-
},
153-
{
154-
name: "Invalid #2: backups disabled",
155-
etcdName: "etcd-invalid-2",
156-
storageCapacity: resource.MustParse("9Gi"),
157-
quota: resource.MustParse("10Gi"),
158-
backupEnabled: false,
159-
expectErr: true,
160-
},
161-
}
108+
validateEtcdCreation(g, etcd, test.expectErr)
162109

163-
for _, test := range tests {
164-
t.Run(test.name, func(t *testing.T) {
165-
etcd := utils.EtcdBuilderWithoutDefaults(test.etcdName, testNs).WithReplicas(3).Build()
166-
etcd.Spec.StorageCapacity = &test.storageCapacity
167-
etcd.Spec.Etcd.Quota = &test.quota
168-
169-
if test.backupEnabled {
170-
container := "etcd-bucket"
171-
provider := "Provider"
172-
etcd.Spec.Backup.Store = &druidv1alpha1.StoreSpec{
173-
Container: &container,
174-
Provider: (*druidv1alpha1.StorageProvider)(&provider),
175-
Prefix: "etcd-test",
176-
SecretRef: &corev1.SecretReference{
177-
Name: "test-secret",
178-
},
179-
}
180-
}
181-
182-
validateEtcdCreation(t, g, etcd, test.expectErr)
183110
})
184-
185111
}
186112
}

test/it/crdvalidation/etcd/specsharedconfig_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestValidateSpecSharedConfigAutoCompactionMode(t *testing.T) {
5555
etcd.Spec.Common = druidv1alpha1.SharedConfig{}
5656
etcd.Spec.Common.AutoCompactionMode = (*druidv1alpha1.CompactionMode)(&test.autoCompactionMode)
5757

58-
validateEtcdCreation(t, g, etcd, test.expectErr)
58+
validateEtcdCreation(g, etcd, test.expectErr)
5959
})
6060
}
6161
}

0 commit comments

Comments
 (0)