From c0fe21baa9ba7d97b3f0d2a3c332d3f4bc6cef7f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 7 Jul 2020 18:03:11 -0700 Subject: [PATCH] lib/resourcebuilder/apiext: Error on unrecognized CRD version Error for unrecognized CRD version, because that will be easier to debug than trying to figure out why a CRD manifest is being silently ignored by the CVO (which is what we've done since the version switch landed in 4ee7b07e99, Add apiextensions.k8s.io/v1 support for CRDs, 2019-10-22, #259). --- lib/resourcebuilder/apiext.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/resourcebuilder/apiext.go b/lib/resourcebuilder/apiext.go index 98f79bbf6..f0b147164 100644 --- a/lib/resourcebuilder/apiext.go +++ b/lib/resourcebuilder/apiext.go @@ -2,6 +2,7 @@ package resourcebuilder import ( "context" + "fmt" "k8s.io/klog" @@ -49,25 +50,27 @@ func (b *crdBuilder) Do(ctx context.Context) error { var err error var name string - switch crd := crd.(type) { + switch typedCRD := crd.(type) { case *apiextv1beta1.CustomResourceDefinition: if b.modifier != nil { - b.modifier(crd) + b.modifier(typedCRD) } - _, updated, err = resourceapply.ApplyCustomResourceDefinitionV1beta1(b.clientV1beta1, crd) + _, updated, err = resourceapply.ApplyCustomResourceDefinitionV1beta1(b.clientV1beta1, typedCRD) if err != nil { return err } - name = crd.Name + name = typedCRD.Name case *apiextv1.CustomResourceDefinition: if b.modifier != nil { - b.modifier(crd) + b.modifier(typedCRD) } - _, updated, err = resourceapply.ApplyCustomResourceDefinitionV1(b.clientV1, crd) + _, updated, err = resourceapply.ApplyCustomResourceDefinitionV1(b.clientV1, typedCRD) if err != nil { return err } - name = crd.Name + name = typedCRD.Name + default: + return fmt.Errorf("unrecognized CustomResourceDefinition version: %T", crd) } if updated {