Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Rashmi Gottipati <[email protected]>
  • Loading branch information
rashmigottipati committed Apr 12, 2024
1 parent 9f902a5 commit 51b6400
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/kapp/crdupgradesafety/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ func NoExistingFieldRemoved(old, new v1.CustomResourceDefinition) error {
}
}
if len(errSet) > 0 {
baseErr := errors.New("existing field in the CRD schema cannot be removed for safe CRD upgrades")
return errors.Join(append([]error{baseErr}, errSet...)...)
return errors.Join(errSet...)
}

return nil
Expand Down
60 changes: 60 additions & 0 deletions pkg/kapp/crdupgradesafety/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,66 @@ func TestNoExistingFieldRemoved(t *testing.T) {
},
shouldError: true,
},
{
name: "new version is added with the field removed, no error",
old: apiextensionsv1.CustomResourceDefinition{
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha1",
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Properties: map[string]apiextensionsv1.JSONSchemaProps{
"fieldOne": {
Type: "string",
},
"fieldTwo": {
Type: "string",
},
},
},
},
},
},
},
},
new: apiextensionsv1.CustomResourceDefinition{
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha1",
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Properties: map[string]apiextensionsv1.JSONSchemaProps{
"fieldOne": {
Type: "string",
},
"fieldTwo": {
Type: "string",
},
},
},
},
},
{
Name: "v1alpha2",
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Properties: map[string]apiextensionsv1.JSONSchemaProps{
"fieldOne": {
Type: "string",
},
},
},
},
},
},
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
err := NoExistingFieldRemoved(tc.old, tc.new)
Expand Down

0 comments on commit 51b6400

Please sign in to comment.