From 51b64005ce47e75e822f08f1bda3e656320bf0c3 Mon Sep 17 00:00:00 2001 From: Rashmi Gottipati Date: Fri, 12 Apr 2024 10:11:29 -0400 Subject: [PATCH] Address review comments Signed-off-by: Rashmi Gottipati --- pkg/kapp/crdupgradesafety/validator.go | 3 +- pkg/kapp/crdupgradesafety/validator_test.go | 60 +++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/pkg/kapp/crdupgradesafety/validator.go b/pkg/kapp/crdupgradesafety/validator.go index 63d956803..9cb970b56 100644 --- a/pkg/kapp/crdupgradesafety/validator.go +++ b/pkg/kapp/crdupgradesafety/validator.go @@ -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 diff --git a/pkg/kapp/crdupgradesafety/validator_test.go b/pkg/kapp/crdupgradesafety/validator_test.go index cd45c2021..53da0c482 100644 --- a/pkg/kapp/crdupgradesafety/validator_test.go +++ b/pkg/kapp/crdupgradesafety/validator_test.go @@ -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)