carvel-dev/kapp

Add validation to `CRDUpgradeSafety` preflight check to allow changing an existing required field to be optional

everettraven opened this issue · 0 comments

Now that there is a base CRDUpgradeSafety preflight check in place, we can continue adding validation logic based on the CRDUpgradeSafety preflight check proposal.

This issue focuses on adding a validation to ensure that updates to an existing field are allowed when the update performed is changing it from required to optional

As a potential source of inspiration, here is how a couple of the existing validations are implemented:

  • Definitions:
    func NoScopeChange(old, new v1.CustomResourceDefinition) error {
    if old.Spec.Scope != new.Spec.Scope {
    return fmt.Errorf("scope changed from %q to %q", old.Spec.Scope, new.Spec.Scope)
    }
    return nil
    }
    func NoStoredVersionRemoved(old, new v1.CustomResourceDefinition) error {
    newVersions := sets.New[string]()
    for _, version := range new.Spec.Versions {
    if !newVersions.Has(version.Name) {
    newVersions.Insert(version.Name)
    }
    }
    for _, storedVersion := range old.Status.StoredVersions {
    if !newVersions.Has(storedVersion) {
    return fmt.Errorf("stored version %q removed", storedVersion)
    }
    }
    return nil
    }
  • Consumption:
    Validations: []Validation{
    NewValidationFunc("NoScopeChange", NoScopeChange),
    NewValidationFunc("NoStoredVersionRemoved", NoStoredVersionRemoved),
    },

Note

It may be useful to consider a more generic check that allows for easily extending the validations that are run against updates to existing fields in a CRD schema