carvel-dev / kapp

kapp is a simple deployment tool focused on the concept of "Kubernetes application" — a set of resources with the same label

Home Page:https://carvel.dev/kapp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add validation to `CRDUpgradeSafety` preflight check to allow decreasing minimum values on existing fields

everettraven opened this issue · 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 a decrease in the minimum allowed values.

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