File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -666,6 +666,14 @@ func (m XValidation) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
666666 }
667667 }
668668
669+ // Check if this validation rule already exists to prevent duplication
670+ for _ , existingRule := range schema .XValidations {
671+ if existingRule .Rule == m .Rule {
672+ // Rule already exists, don't add it again
673+ return nil
674+ }
675+ }
676+
669677 schema .XValidations = append (schema .XValidations , apiext.ValidationRule {
670678 Rule : m .Rule ,
671679 Message : m .Message ,
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ type OneofSpec struct {
3636 TypeWithMultipleAtLeastOneofs * TypeWithMultipleAtLeastOneofs `json:"typeWithMultipleAtLeastOneOf,omitempty"`
3737
3838 TypeWithAllOneOf * TypeWithAllOneofs `json:"typeWithAllOneOf,omitempty"`
39+
40+ // The validation rule on TypeWithOneofs should not be duplicated.
41+ SameTypeWithOneof * TypeWithOneofs `json:"sameTypeWithOneof,omitempty"`
3942}
4043
4144// +kubebuilder:validation:XValidation:message="only one of foo|bar may be set",rule="!(has(self.foo) && has(self.bar))"
Original file line number Diff line number Diff line change 6060 - message : at most one of the fields in [foo bar] may be set
6161 rule : ' [has(self.foo),has(self.bar)].filter(x,x==true).size() <=
6262 1'
63+ sameTypeWithOneof :
64+ description : The validation rule on TypeWithOneofs should not be duplicated.
65+ properties :
66+ bar :
67+ type : string
68+ foo :
69+ type : string
70+ type : object
71+ x-kubernetes-validations :
72+ - message : only one of foo|bar may be set
73+ rule : ' !(has(self.foo) && has(self.bar))'
74+ - message : at most one of the fields in [foo bar] may be set
75+ rule : ' [has(self.foo),has(self.bar)].filter(x,x==true).size() <=
76+ 1'
6377 secondTypeWithExactOneof :
6478 properties :
6579 a :
You can’t perform that action at this time.
0 commit comments