Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR enables the conversion webhooks in preparation for the
v1.0.0
release, which will be introducing thev1beta2
versions of some API groups together with their associated conversion functions. This PR also adds the--certs-dir
command-line options to the family's resource providers, with the following protocol for configuring the conversion Webhook TLS certificate & key:--certs-dir
command-line option is supplied, it's used.--certs-dir
command-line option is not supplied, the following environment variables are used in the given order:CERTS_DIR
(for consistency with theupbound/provider-aws
),TLS_SERVER_CERTS_DIR
(the new environment variable, which has replaced theWEBHOOK_TLS_CERT_DIR
env. variable in Crossplane), andWEBHOOK_TLS_CERT_DIR
(for backwards-compatibility)./tls/server
.It also incorporates the resolver transformer from crossplane/upjet#331 to prevent the import cycles that frequently occur when a managed resource's API version is bumped leaving some other managed resources in its group at their previous versions. The transformer is run as part of the code generation pipeline defined in
apis/generate.go
as follows:The dynamic reference source initialization is implemented using a type registry in
internal/apis/scheme.go
When
--certs-dir
is set to the empty string (--certs-dir=""
), the conversion webhooks are disabled to facilitate the local development of resources.--certs-dir=""
is also used for therun
make target so that developers running the provider locally will not need to bother with configuring the webhook TLS certificates. When running the webhooks are needed for local development,--certs-dir
can be set to the folder containing thetls.crt
and thetls.key
files.Apart from the discussion in crossplane/upjet#321, this PR takes care of generating CRDs with the conversion strategy set to
Webhook
. However, the generated CRDs containing the conversion strategy are not stored underpackage/crds
under the repo root. That path still contains the generated CRDs but without theconversion
stanzas and they can still be used during development of the managed resources, and for running the provider process locally without the need to configure any TLS certificates. While developing the implementation of a managed resource, there's generally no need to involve the conversion webhooks and the conversion function chains they invoke, unless you're specifically interested in the conversion functions (or the upjet generated spoke implementations). Although the generated CRDs atpackage/crds
do not contain theconversion
stanzas, if there's at least one resource in the provider with multiple API versions, the provider, by default, attempts to start the conversion Webhook server, which will fail if the TLS certificates are not properly configured. In such cases, if you'd like to run the provider with the Webhook server disabled, then you can just set the--certs-dir
command line argument to an empty string to disable the conversion webhook server, i.e., by specifying--certs-dir=""
.The PR uses kustomize together with the yq to generate the CRDs with the proper
conversion
stanzas specifying the conversion strategy ofWebhook
for converting between the hub & spoke API versions. As discussed above, the CRDs specifying the conversion strategies are not stored at the pathpackage/crds
and instead, they can be found under the path_output/package/crds
in the repo root.yq
is used to split the multi-doc YAML output fromkustomize
as theup xpkg batch
command relies on the generated CRD filenames while preparing the provider family (resource) packages. Various alternatives have been considered instead of incorporatingyq
in the code generation pipeline as detailed in the description of upbound/build#249. Notably a shell script implementation of the split function was considerably slower than theyq --split-exp
command and we've chosen to incorporateyq
into our code generation pipeline.yq
has been incorporated as a kustomize plugin with the nameSplitTransformer
. Another alternative was to just pipe the output fromkustomize
(via a shell pipe) to theyq --split-exp
command. However, the plugin approach is better for bundling the kustomization transformations as a reusable module. We will consider moving the kustomization configuration for generating CRDs with the properconversion
stanzas as a reusable component to uptest (where there are already some reusable components related with the official provider repos' build pipelines) or to upjet.I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested
make run
succeeds to provision aServiceAccount.cloudplatform
resource after the CRDs without theconversion
stanzas are applied with the commandkubectl apply -f package/crds
in the repo root.