Skip to content

Commit

Permalink
Improve validation message
Browse files Browse the repository at this point in the history
  • Loading branch information
grischperl committed Nov 21, 2023
1 parent e0b6bec commit cade3f8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/nats_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type Cluster struct {
// +kubebuilder:default:=3
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:validation:XValidation:rule="(self%2) != 0", message="size only accepts odd numbers"
// +kubebuilder:validation:XValidation:rule="!(oldSelf > 1 && self == 1)", message="size cannot be reduced to 1 once it was >1"
// +kubebuilder:validation:XValidation:rule="!(oldSelf > 1 && self == 1)", message="cannot be set to 1 if size was greater than 1"
Size int `json:"size,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/operator.kyma-project.io_nats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ spec:
x-kubernetes-validations:
- message: size only accepts odd numbers
rule: (self%2) != 0
- message: size cannot be reduced to 1 once it was >1
- message: cannot be set to 1 if size was greater than 1
rule: '!(oldSelf > 1 && self == 1)'
type: object
jetStream:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func Test_Validate_UpdateNATS(t *testing.T) {
Size: 1,
}),
},
wantErrMsg: "size cannot be reduced to 1 once it was >1",
wantErrMsg: "cannot be set to 1 if size was greater than 1",
},
{
name: `validation of cluster passes, if cluster.size was set to a value >1
Expand Down

0 comments on commit cade3f8

Please sign in to comment.