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

Replace AnyTypes with apiextensions.JSON #295

Merged
merged 8 commits into from
Oct 30, 2020

Conversation

babbageclunk
Copy link
Member

@babbageclunk babbageclunk commented Oct 29, 2020

Adds a pipeline stage to convert AnyTypes to k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1.JSON, which can store arbitrary JSON values in the API. This enables generating all of the packages that were previously being filtered out because they generated interface{} fields.

Removes the filterOutDefinitionsUsingAnyType stage, although leaves the ensureDefinitionsDoNotUseAnyTypes check at the end just in case later stages introduce AnyTypes again.

A lot of packages include fields that come out as map[string]map[string]v1.JSON (especially for UserAssignedIdentities fields), but controller-gen can't generate deep-copy code for these types. To handle these the stage collapses them down to map[string]v1.JSON as well. kubernetes-sigs/controller-tools#287

Adds special-case handling in the ARM conversion generation to ensure that JSON fields are deep-copied when converting to/from ARM types.

There are still a couple of packages that need to be excluded because the ARM conversion code generated for them has an issue or hits controller-gen limitations.

Fixes #133.


# Exclusions for packages that currently produce types including AnyType.
# TODO: get rid of these, either by chasing the teams generating
# weird json or by handling them differently in the generator.
anyTypePackages:
- microsoft.authorization/v20180301
Copy link
Member

Choose a reason for hiding this comment

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

wooh!

- action: exclude
group: microsoft.machinelearning
version: v20170101
because: ExampleRequest.Inputs is a map[string][][]map[string]v1.JSON, which controller-gen doesn't know how to handle.
Copy link
Member

Choose a reason for hiding this comment

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

oh wow

Copy link
Member

Choose a reason for hiding this comment

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

#mindboggling

@Porges
Copy link
Member

Porges commented Oct 29, 2020

This came out nicely!

- action: exclude
group: microsoft.machinelearning
version: v20170101
because: ExampleRequest.Inputs is a map[string][][]map[string]v1.JSON, which controller-gen doesn't know how to handle.
Copy link
Member

Choose a reason for hiding this comment

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

#mindboggling

assignmentHandler(params.destination, newSource),
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Once my Test Cases branch is merged, we should loop back here and use some of the helper methods I've written to simplify the code.

hack/generator/pkg/astmodel/json_type.go Outdated Show resolved Hide resolved
babbageclunk and others added 8 commits October 30, 2020 14:07
Allowing arbitrary JSON in these fields makes sense since they're
underconstrained in the ARM schemas.

Updated the golden tests accordingly.
These are converted to map[string]JSON, because controller-gen has
issues with maps of maps.
kubernetes-sigs/controller-tools#287
microsoft.machinelearning/v20170101: ExampleRequest.Input comes out as
a map[string][][]map[string]v1.JSON, which controller-gen can't
handle. (Our ARM conversion code generation is also wrong for this,
see https://github.com/Azure/k8s-infra/issues/289.)

microsoft.web/v20150801: ARM conversion needs to add type casting to
convert SitesSpecResourcesAppsettingsSpec.Name to
SitesSpecResourcesAppsettingsSpecName in a number of places. Or
possibly to just collapse the SitesSpecResourcesAppsettingsSpecName
type back to a string? I'm not sure why that one stays a type
alias when we change lots of other ones.

microsoft.datafactory/v20180601:
ExecuteSSISPackageActivityTypeProperties.PackageConnectionManagers is
a map[string]map[string]SSISExecutionParameter
It's not needed now that the replaceAnyTypeWithJSON stage is in the
pipeline. Keep the final check for AnyType though.
@coveralls
Copy link

coveralls commented Oct 30, 2020

Coverage Status

Coverage decreased (-2.8%) to 24.839% when pulling ad869ce on babbageclunk:json-fields into 155e5a4 on Azure:master.

@babbageclunk babbageclunk merged commit 15e310a into Azure:master Oct 30, 2020
@babbageclunk babbageclunk deleted the json-fields branch October 30, 2020 02:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix handling of "empty" types
4 participants