@@ -90,7 +90,8 @@ func (r *CronJob) Default() {
90
90
This marker is responsible for generating a validating webhook manifest.
91
91
*/
92
92
93
- // +kubebuilder:webhook:path=/validate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=vcronjob.kb.io
93
+ // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
94
+ // +kubebuilder:webhook:verbs=create;update,path=/validate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,versions=v1,name=vcronjob.kb.io
94
95
95
96
/*
96
97
To validate our CRD beyond what's possible with declarative validation.
@@ -103,11 +104,15 @@ schedule without making up a long regular expression.
103
104
If `webhook.Validator` interface is implemented, a webhook will automatically be
104
105
served that calls the validation.
105
106
106
- The `ValidateCreate` and `ValidateUpdate` methods are expected to validate that its
107
- receiver upon creation and update respectively. We separate out ValidateCreate
108
- from ValidateUpdate to allow behavior like making certain fields immutable, so
109
- that they can only be set on creation.
110
- Here, however, we just use the same shared validation.
107
+ The `ValidateCreate`, `ValidateUpdate` and `ValidateDelete` methods are expected
108
+ to validate that its receiver upon creation, update and deletion respectively.
109
+ We separate out ValidateCreate from ValidateUpdate to allow behavior like making
110
+ certain fields immutable, so that they can only be set on creation.
111
+ ValidateDelete is also separated from ValidateUpdate to allow different
112
+ validation behavior on deletion.
113
+ Here, however, we just use the same shared validation for `ValidateCreate` and
114
+ `ValidateUpdate`. And we do nothing in `ValidateDelete`, since we don't need to
115
+ validate anything on deletion.
111
116
*/
112
117
113
118
var _ webhook.Validator = & CronJob {}
@@ -126,6 +131,14 @@ func (r *CronJob) ValidateUpdate(old runtime.Object) error {
126
131
return r .validateCronJob ()
127
132
}
128
133
134
+ // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
135
+ func (r * CronJob ) ValidateDelete () error {
136
+ cronjoblog .Info ("validate delete" , "name" , r .Name )
137
+
138
+ // TODO(user): fill in your validation logic upon object deletion.
139
+ return nil
140
+ }
141
+
129
142
/*
130
143
We validate the name and the spec of the CronJob.
131
144
*/
0 commit comments