0

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?

Fabrice Jammes
  • 2,275
  • 1
  • 26
  • 39

1 Answers1

2

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
}
Galletti_Lance
  • 509
  • 2
  • 4
  • 15