Fabrice Jammes
Fabrice Jammes

Reputation: 3205

Manage immutable fields in Kubebuilder validating webhook

According to Kubebuilder documentation, it is possible to implement immutable fields for a given CRD:

We separate out ValidateCreate from ValidateUpdate to allow behavior like making certain fields immutable, so that they can only be set on creation.

Would some of you have some examples or code samples about implementing this?

Upvotes: 0

Views: 1488

Answers (1)

Galletti_Lance
Galletti_Lance

Reputation: 559

Using the Kubebuilder example:

func (r *CronJob) ValidateUpdate(old runtime.Object) error {
    oldCronJob, _ := old.(*CronJob)
    if r.Spec.ImmutableField != oldCronJob.Spec.ImmutableField {
        // accumulate errors
    }
    ...
    // return all errors
}

Upvotes: 2

Related Questions