Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Properly support enum Names in resources #326

Merged
merged 21 commits into from
Nov 19, 2020
Merged

Conversation

Porges
Copy link
Member

@Porges Porges commented Nov 12, 2020

Naming changes

Don't convert all resource Spec Name properties to string, and instead allow the following cases:

  • An enum with one value generates no AzureName property in the CRD as it cannot be changed. An AzureName() function is provided for ConvertToArm to invoke, which returns the fixed value.
    This only triggers for one resource currently:

    • Web HostingEnvironmentsMultiRolePool which must have a name of default
  • An enum with multiple values generates an AzureName property with an enum value. An AzureName() function is provided for ConvertToArm which casts the enum value to string.
    Example resources for this are:

    • Keyvault VaultsAccessPolicies which allows names of add, remove, and replace
    • API Management ServiceIdentityProvider which allows names of aad, aadB2C, facebook, google, microsoft, and twitter

All Spec Name properties are still converted to string for the corresponding ARM type, as we need to insert a full ARM ID including owning resource IDs, etc.

Serialization changes

Split ArmTransformer interface into two parts FromArmConverter/ToArmConverter and make it so that Status types only implement FromArmConverter.

Other cases

There are other cases to be solved; some services (like Storage) require a Name ending in default (which is actually more correct, as the Name is a full URI including parent resources). At the schema level this is enforced via a regex like ^.*/default$. We can recognize these cases and handle them; but that will be a different PR—we don’t yet support type validation properly.

@Porges Porges marked this pull request as draft November 12, 2020 23:28
@Porges Porges marked this pull request as ready for review November 13, 2020 00:14
@coveralls
Copy link

coveralls commented Nov 16, 2020

Coverage Status

Coverage increased (+22.08%) to 70.718% when pulling b62d84e on the-resource-named-default into 7e55f85 on master.

@Porges Porges changed the title Better support for non-string Names in resources Properly support non-string Names in resources Nov 16, 2020
@Porges Porges changed the title Properly support non-string Names in resources Properly support enum Names in resources Nov 16, 2020
@Porges Porges self-assigned this Nov 16, 2020
Copy link
Member

@matthchr matthchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but looks good

hack/generator/pkg/astmodel/armconversion/shared.go Outdated Show resolved Hide resolved
hack/generator/pkg/codegen/codegen_test.go Show resolved Hide resolved
iface, err := astmodel.NewKubernetesResourceInterfaceImpl(idFactory, specObj)
if err != nil {
return nil, errors.Wrapf(err, "Couldn't implement Kubernetes resource interface for %q", spec.Name())
// this is really very ugly; a better way?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make WithKubernetesResourceInterfaceImpl return a triplet with one return being an optional updated SpecType. It makes it a bit more obvious from the function signature that there's a possible modification? Or if the triplet result is too ugly you could make a little struct for it.

It's honestly not lots better but might be a bit better.

hack/generator/pkg/codegen/pipeline_create_arm_types.go Outdated Show resolved Hide resolved
@Porges Porges merged commit b3806d1 into master Nov 19, 2020
@Porges Porges deleted the the-resource-named-default branch November 19, 2020 04:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants