Skip to content

Commit 8287505

Browse files
committed
validation for autoscaling and unit test
1 parent c77334a commit 8287505

File tree

9 files changed

+92
-9
lines changed

9 files changed

+92
-9
lines changed

config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25399,6 +25399,11 @@ spec:
2539925399
enableVolumeScaling:
2540025400
type: boolean
2540125401
type: object
25402+
x-kubernetes-validations:
25403+
- message: autoscaling cannot be enabled when enableVolumeScaling
25404+
is disabled
25405+
rule: '!has(self.autoscaling) || !has(self.autoscaling.enabled)
25406+
|| !self.autoscaling.enabled || self.enableVolumeScaling'
2540225407
tls:
2540325408
properties:
2540425409
allowInvalidCertificates:

deploy/bundle.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26286,6 +26286,11 @@ spec:
2628626286
enableVolumeScaling:
2628726287
type: boolean
2628826288
type: object
26289+
x-kubernetes-validations:
26290+
- message: autoscaling cannot be enabled when enableVolumeScaling
26291+
is disabled
26292+
rule: '!has(self.autoscaling) || !has(self.autoscaling.enabled)
26293+
|| !self.autoscaling.enabled || self.enableVolumeScaling'
2628926294
tls:
2629026295
properties:
2629126296
allowInvalidCertificates:

deploy/cr.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ spec:
1212
# clusterServiceDNSMode: "Internal"
1313
# pause: true
1414
# unmanaged: false
15-
# storageScaling:
16-
# enableExternalAutoscaling: false
17-
# enableVolumeScaling: false
18-
# autoscaling:
19-
# enabled: false
20-
# triggerThresholdPercent: 80
21-
# growthStep: 2Gi
22-
# maxSize: "10Gi"
15+
storageScaling:
16+
enableExternalAutoscaling: false
17+
enableVolumeScaling: true
18+
autoscaling:
19+
enabled: true
20+
triggerThresholdPercent: 80
21+
growthStep: 2Gi
22+
maxSize: "10Gi"
2323
crVersion: 1.22.0
2424
image: perconalab/percona-server-mongodb-operator:main-mongod8.0
2525
imagePullPolicy: Always

deploy/crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26286,6 +26286,11 @@ spec:
2628626286
enableVolumeScaling:
2628726287
type: boolean
2628826288
type: object
26289+
x-kubernetes-validations:
26290+
- message: autoscaling cannot be enabled when enableVolumeScaling
26291+
is disabled
26292+
rule: '!has(self.autoscaling) || !has(self.autoscaling.enabled)
26293+
|| !self.autoscaling.enabled || self.enableVolumeScaling'
2628926294
tls:
2629026295
properties:
2629126296
allowInvalidCertificates:

deploy/cw-bundle.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26286,6 +26286,11 @@ spec:
2628626286
enableVolumeScaling:
2628726287
type: boolean
2628826288
type: object
26289+
x-kubernetes-validations:
26290+
- message: autoscaling cannot be enabled when enableVolumeScaling
26291+
is disabled
26292+
rule: '!has(self.autoscaling) || !has(self.autoscaling.enabled)
26293+
|| !self.autoscaling.enabled || self.enableVolumeScaling'
2628926294
tls:
2629026295
properties:
2629126296
allowInvalidCertificates:

e2e-tests/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ build_operator() {
4343
--build-arg GIT_COMMIT=$GIT_COMMIT \
4444
--build-arg GIT_BRANCH=$GIT_BRANCH \
4545
--build-arg GO_LDFLAGS="$GO_LDFLAGS" \
46-
--build-arg BASE_IMAGE="${BASE_IMAGE:-ubi10}" \
46+
--build-arg BASE_IMAGE="${BASE_IMAGE:-ubi9}" \
4747
--progress plain \
4848
$squash \
4949
$imgresult \

e2e-tests/version-service/conf/crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26286,6 +26286,11 @@ spec:
2628626286
enableVolumeScaling:
2628726287
type: boolean
2628826288
type: object
26289+
x-kubernetes-validations:
26290+
- message: autoscaling cannot be enabled when enableVolumeScaling
26291+
is disabled
26292+
rule: '!has(self.autoscaling) || !has(self.autoscaling.enabled)
26293+
|| !self.autoscaling.enabled || self.enableVolumeScaling'
2628926294
tls:
2629026295
properties:
2629126296
allowInvalidCertificates:

pkg/apis/psmdb/v1/psmdb_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ type StorageAutoscalingStatus struct {
10121012
}
10131013

10141014
// StorageScalingSpec defines the configuration for storage scaling behavior
1015+
// +kubebuilder:validation:XValidation:rule="!has(self.autoscaling) || !has(self.autoscaling.enabled) || !self.autoscaling.enabled || self.enableVolumeScaling",message="autoscaling cannot be enabled when enableVolumeScaling is disabled"
10151016
type StorageScalingSpec struct {
10161017
// EnableExternalAutoscaling delegates volume autoscaling to an external system (e.g., Kubernetes VPA)
10171018
// When enabled, the operator skips internal autoscaling and resize operations

pkg/controller/perconaservermongodb/psmdb_controller_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
"k8s.io/apimachinery/pkg/types"
1111
"sigs.k8s.io/controller-runtime/pkg/reconcile"
12+
13+
psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
1214
)
1315

1416
var _ = Describe("PerconaServerMongoDB", Ordered, func() {
@@ -52,3 +54,58 @@ var _ = Describe("PerconaServerMongoDB", Ordered, func() {
5254
Expect(err).To(Succeed())
5355
})
5456
})
57+
58+
var _ = Describe("PerconaServerMongoDB CRD Validation", Ordered, func() {
59+
ctx := context.Background()
60+
const ns = "psmdb-validation"
61+
namespace := &corev1.Namespace{
62+
ObjectMeta: metav1.ObjectMeta{
63+
Name: ns,
64+
Namespace: ns,
65+
},
66+
}
67+
68+
BeforeAll(func() {
69+
By("Creating the Namespace to perform the tests")
70+
err := k8sClient.Create(ctx, namespace)
71+
Expect(err).To(Not(HaveOccurred()))
72+
})
73+
74+
AfterAll(func() {
75+
By("Deleting the Namespace to perform the tests")
76+
_ = k8sClient.Delete(ctx, namespace)
77+
})
78+
79+
Context("StorageScaling validation", func() {
80+
It("should reject autoscaling enabled when enableVolumeScaling is disabled", func() {
81+
cr, err := readDefaultCR("psmdb-invalid-autoscaling", ns)
82+
Expect(err).NotTo(HaveOccurred())
83+
84+
cr.Spec.StorageScaling = &psmdbv1.StorageScalingSpec{
85+
EnableVolumeScaling: false,
86+
Autoscaling: &psmdbv1.AutoscalingSpec{
87+
Enabled: true,
88+
},
89+
}
90+
91+
err = k8sClient.Create(ctx, cr)
92+
Expect(err).To(HaveOccurred())
93+
Expect(err.Error()).To(ContainSubstring("autoscaling cannot be enabled when enableVolumeScaling is disabled"))
94+
})
95+
96+
It("should allow autoscaling enabled when enableVolumeScaling is enabled", func() {
97+
cr, err := readDefaultCR("psmdb-valid-autoscaling", ns)
98+
Expect(err).NotTo(HaveOccurred())
99+
100+
cr.Spec.StorageScaling = &psmdbv1.StorageScalingSpec{
101+
EnableVolumeScaling: true,
102+
Autoscaling: &psmdbv1.AutoscalingSpec{
103+
Enabled: true,
104+
},
105+
}
106+
107+
err = k8sClient.Create(ctx, cr)
108+
Expect(err).NotTo(HaveOccurred())
109+
})
110+
})
111+
})

0 commit comments

Comments
 (0)