Skip to content

Commit a1060e6

Browse files
committed
address review: validate immutability of contained spec in CRD API
Signed-off-by: Bogdan-Adrian Burciu <bogdanadrian.burciu@yahoo.com>
1 parent 803b7e9 commit a1060e6

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

apis/cluster/mssql/v1alpha1/user_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type UserStatus struct {
3636

3737
// UserParameters define the desired state of a MSSQL user instance.
3838
// +kubebuilder:validation:XValidation:rule="!(has(self.contained) && self.contained == true && (has(self.loginDatabase) || has(self.loginDatabaseRef) || has(self.loginDatabaseSelector)))",message="contained users cannot specify loginDatabase, loginDatabaseRef, or loginDatabaseSelector"
39+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.contained) || self.contained == oldSelf.contained",message="contained field is immutable after creation"
3940
type UserParameters struct {
4041
// Database allows you to specify the name of the Database the USER is created for.
4142
// +crossplane:generate:reference:type=Database

apis/namespaced/mssql/v1alpha1/user_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type UserStatus struct {
3737

3838
// UserParameters define the desired state of a MSSQL user instance.
3939
// +kubebuilder:validation:XValidation:rule="!(has(self.contained) && self.contained == true && (has(self.loginDatabase) || has(self.loginDatabaseRef) || has(self.loginDatabaseSelector)))",message="contained users cannot specify loginDatabase, loginDatabaseRef, or loginDatabaseSelector"
40+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.contained) || self.contained == oldSelf.contained",message="contained field is immutable after creation"
4041
type UserParameters struct {
4142
// Database allows you to specify the name of the Database the USER is created for.
4243
// +crossplane:generate:reference:type=Database

package/crds/mssql.sql.crossplane.io_users.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ spec:
265265
or loginDatabaseSelector
266266
rule: '!(has(self.contained) && self.contained == true && (has(self.loginDatabase)
267267
|| has(self.loginDatabaseRef) || has(self.loginDatabaseSelector)))'
268+
- message: contained field is immutable after creation
269+
rule: '!has(oldSelf.contained) || self.contained == oldSelf.contained'
268270
managementPolicies:
269271
default:
270272
- '*'

package/crds/mssql.sql.m.crossplane.io_users.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ spec:
254254
or loginDatabaseSelector
255255
rule: '!(has(self.contained) && self.contained == true && (has(self.loginDatabase)
256256
|| has(self.loginDatabaseRef) || has(self.loginDatabaseSelector)))'
257+
- message: contained field is immutable after creation
258+
rule: '!has(oldSelf.contained) || self.contained == oldSelf.contained'
257259
managementPolicies:
258260
default:
259261
- '*'

0 commit comments

Comments
 (0)