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 ensure default values for a field are not changed during an upgrade

rashmigottipati 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 another field change validation to the CRD Upgrade Safety checks to prevent changes to a fields default value for a given CRD version during an upgrade

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), 
 }, 

Closing as completed via PR merged into kapp: #950