Skip to content

Commit

Permalink
Don't fail on flattening collisions (#1608)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Porges authored Jun 28, 2021
1 parent 2a360fb commit 07deed3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion hack/generator/pkg/codegen/pipeline/flatten_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"

"github.com/pkg/errors"
"k8s.io/klog/v2"

"github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel"
)
Expand Down Expand Up @@ -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...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 07deed3

Please sign in to comment.