Skip to content

Commit 50be6ae

Browse files
committed
markers: add support for optionalOldSelf in XValidation marker
Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
1 parent 4e1fb05 commit 50be6ae

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

pkg/crd/markers/validation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ type XValidation struct {
335335
MessageExpression string `marker:"messageExpression,optional"`
336336
Reason string `marker:"reason,optional"`
337337
FieldPath string `marker:"fieldPath,optional"`
338+
OptionalOldSelf *bool `marker:"optionalOldSelf,optional"`
338339
}
339340

340341
func (m Maximum) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
@@ -603,6 +604,7 @@ func (m XValidation) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
603604
MessageExpression: m.MessageExpression,
604605
Reason: reason,
605606
FieldPath: m.FieldPath,
607+
OptionalOldSelf: m.OptionalOldSelf,
606608
})
607609
return nil
608610
}

pkg/crd/markers/zz_generated.markerhelp.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/crd/testdata/cronjob_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
const DefaultRefValue = "defaultRefValue"
4444

4545
// CronJobSpec defines the desired state of CronJob
46-
// +kubebuilder:validation:XValidation:rule="has(oldSelf.forbiddenInt) || !has(self.forbiddenInt)",message="forbiddenInt is not allowed",fieldPath=".forbiddenInt",reason="FieldValueForbidden"
46+
// +kubebuilder:validation:XValidation:rule="has(oldSelf.forbiddenInt) || !has(self.forbiddenInt)",message="forbiddenInt is not allowed",fieldPath=".forbiddenInt",reason="FieldValueForbidden",optionalOldSelf=true
4747
type CronJobSpec struct {
4848
// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
4949
Schedule string `json:"schedule"`

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9156,6 +9156,7 @@ spec:
91569156
x-kubernetes-validations:
91579157
- fieldPath: .forbiddenInt
91589158
message: forbiddenInt is not allowed
9159+
optionalOldSelf: true
91599160
reason: FieldValueForbidden
91609161
rule: has(oldSelf.forbiddenInt) || !has(self.forbiddenInt)
91619162
status:

0 commit comments

Comments
 (0)