Skip to content

Commit 1f9d02f

Browse files
committed
add CEL ratcheting rule for serverless spec
1 parent df7e68a commit 1f9d02f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

api/v1/atlasdeployment_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
// Only one of DeploymentSpec, AdvancedDeploymentSpec and ServerlessSpec should be defined.
4444
// +kubebuilder:validation:XValidation:rule="(has(self.externalProjectRef) && !has(self.projectRef)) || (!has(self.externalProjectRef) && has(self.projectRef))",message="must define only one project reference through externalProjectRef or projectRef"
4545
// +kubebuilder:validation:XValidation:rule="(has(self.externalProjectRef) && has(self.connectionSecret)) || !has(self.externalProjectRef)",message="must define a local connection secret when referencing an external project"
46+
// +kubebuilder:validation:XValidation:rule="!has(self.serverlessSpec) || (oldSelf.hasValue() && oldSelf.value().serverlessSpec != null)",optionalOldSelf=true,message="serverlessSpec cannot be added - serverless instances are deprecated",fieldPath=.serverlessSpec
4647
type AtlasDeploymentSpec struct {
4748
// ProjectReference is the dual external or kubernetes reference with access credentials
4849
ProjectDualReference `json:",inline"`

api/v1/atlasdeployment_types_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,57 @@ func TestDeploymentCELChecks(t *testing.T) {
4949
},
5050
expectedErrors: []string{"spec.deploymentSpec.name: Invalid value: \"string\": Name cannot be modified after deployment creation"},
5151
},
52+
{
53+
title: "Cannot add a serverless deployment",
54+
old: nil,
55+
obj: &AtlasDeployment{
56+
Spec: AtlasDeploymentSpec{
57+
ServerlessSpec: &ServerlessSpec{
58+
Name: "my-serverless",
59+
},
60+
},
61+
},
62+
expectedErrors: []string{"spec.serverlessSpec: Invalid value: \"object\": serverlessSpec cannot be added - serverless instances are deprecated"},
63+
},
64+
{
65+
title: "Can modify to a serverless deployment",
66+
old: &AtlasDeployment{
67+
Spec: AtlasDeploymentSpec{
68+
ServerlessSpec: &ServerlessSpec{
69+
Name: "my-serverless",
70+
TerminationProtectionEnabled: false,
71+
},
72+
},
73+
},
74+
obj: &AtlasDeployment{
75+
Spec: AtlasDeploymentSpec{
76+
ServerlessSpec: &ServerlessSpec{
77+
Name: "my-serverless",
78+
TerminationProtectionEnabled: true,
79+
},
80+
},
81+
},
82+
},
83+
{
84+
title: "Existing serverless deployment can continue existing when not modified",
85+
old: &AtlasDeployment{
86+
Spec: AtlasDeploymentSpec{
87+
ServerlessSpec: &ServerlessSpec{
88+
Name: "my-serverless",
89+
TerminationProtectionEnabled: false,
90+
},
91+
},
92+
},
93+
obj: &AtlasDeployment{
94+
Spec: AtlasDeploymentSpec{
95+
BackupScheduleRef: common.ResourceRefNamespaced{},
96+
ServerlessSpec: &ServerlessSpec{
97+
Name: "my-serverless",
98+
TerminationProtectionEnabled: false,
99+
},
100+
},
101+
},
102+
},
52103
} {
53104
t.Run(tc.title, func(t *testing.T) {
54105
// inject a project to avoid other CEL validations being hit

0 commit comments

Comments
 (0)