From 07deed326ad09b99758955cb13bb67bfccfc06f9 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 29 Jun 2021 09:48:06 +1200 Subject: [PATCH] Don't fail on flattening collisions (#1608) The new VMSS resources do this (a collision on `Type` property). Technically we can handle this case properly but it will require more work. We can handle the VMSS case because the user can't normally overwrite the top-level `Type` property, so any `Type` property in the CRD must point to the flattened `Type`. --- hack/generator/pkg/codegen/pipeline/flatten_properties.go | 4 +++- .../pkg/codegen/pipeline/flatten_properties_test.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hack/generator/pkg/codegen/pipeline/flatten_properties.go b/hack/generator/pkg/codegen/pipeline/flatten_properties.go index 4a8da5302c8..57db9d18021 100644 --- a/hack/generator/pkg/codegen/pipeline/flatten_properties.go +++ b/hack/generator/pkg/codegen/pipeline/flatten_properties.go @@ -9,6 +9,7 @@ import ( "context" "github.com/pkg/errors" + "k8s.io/klog/v2" "github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel" ) @@ -52,7 +53,8 @@ func makeFlatteningVisitor(defs astmodel.Types) astmodel.TypeVisitor { // safety check: if err := checkForDuplicateNames(newProps); err != nil { - return nil, err + klog.Warningf("Flattening caused duplicate property names, skipping flattening: %s", err) + return it, nil // nolint:nilerr } result := it.WithoutProperties().WithProperties(newProps...) diff --git a/hack/generator/pkg/codegen/pipeline/flatten_properties_test.go b/hack/generator/pkg/codegen/pipeline/flatten_properties_test.go index 3ca289ac32e..762606543f7 100644 --- a/hack/generator/pkg/codegen/pipeline/flatten_properties_test.go +++ b/hack/generator/pkg/codegen/pipeline/flatten_properties_test.go @@ -30,8 +30,9 @@ func TestDuplicateNamesAreCaught(t *testing.T) { types.Add(astmodel.MakeTypeDefinition(astmodel.MakeTypeName(placeholderPackage, "objType"), objType)) result, err := applyPropertyFlattening(context.Background(), types) - g.Expect(result).To(BeNil()) - g.Expect(err).To(MatchError("visit of type of \"prefix/group/version/objType\" failed: flattening caused duplicate property name \"duplicate\"")) + // We don't fail but flattening does not occur + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(result).To(Equal(types)) } func TestFlatteningWorks(t *testing.T) {