Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller-gen can now update CRDs like before #3989

Merged
merged 1 commit into from
May 12, 2021

Conversation

maelvls
Copy link
Member

@maelvls maelvls commented May 11, 2021

Fixes #3943. The controller-gen tool is quite rude and won't tell you when one of the CRD manifests cannot be parsed when the option schemapatch is used. As an example, the following:

sed -i 's/RFC8555/RFC8556/g' pkg/apis/certmanager/v1/types_issuer.go
controller-gen schemapatch:manifests=./deploy/crds output:dir=./deploy/crds paths=./pkg/apis/...

should trigger a change in the crd-clusterissuers.yaml:

--- a/deploy/crds/crd-clusterissuers.yaml
+++ b/deploy/crds/crd-clusterissuers.yaml
@@ -3184,7 +3184,7 @@ spec:
               type: object
               properties:
                 acme:
-                  description: ACME configures this issuer to communicate with a RFC8555 (ACME) server to obtain signed x509 certificates.
+                  description: ACME configures this issuer to communicate with a RFC8556 (ACME) server to obtain signed x509 certificates.
                   type: object
--- a/deploy/crds/crd-issuers.yaml
+++ b/deploy/crds/crd-issuers.yaml
@@ -3184,7 +3184,7 @@ spec:
               type: object
               properties:
                 acme:
-                  description: ACME configures this issuer to communicate with a RFC8555 (ACME) server to obtain signed x509 certificates.
+                  description: ACME configures this issuer to communicate with a RFC8556 (ACME) server to obtain signed x509 certificates.
                   type: object

Unfortunately, controller-gen v0.2.9 (645d44dc) silently skips faulty CRD manifests. In our case, the CRD had become a non-YAML file (we need to use some if statements):

  {{- if .Values.webhook.url.host }}
  url: https://{{ .Values.webhook.url.host }}/convert
  {{- else }}
  service:
    name: {{ template "webhook.fullname" . }}
    namespace: {{ .Release.Namespace | quote }}
    path: /convert
  {{- end }}

Two issues can be found (we can use a YAML parser like yq for that):

  1. The pipe "|" used in .Release.Namespace | quote makes it an invalid YAML file. We could rewrite that to

      {{ quote .Release.Namespace }}

    but I decided to go with actual quotes like with the rest of the file:

      "{{ .Release.Namespace }}"
  2. The {{ if }}, {{ else }} and {{ end }} are also invalid YAML syntax, and one easy workaround is to comment them.

/kind cleanup
/milestone v1.4

NONE

The controller-gen tool is quite rude and won't tell you when one of the
CRD manifests cannot be parsed when the option schemapatch is used. As
an example, the following:

  sed -i 's/RFC8555/RFC8556/g' pkg/apis/certmanager/v1/types_issuer.go
  controller-gen schemapatch:manifests=./deploy/crds output:dir=./deploy/crds paths=./pkg/apis/...

should trigger a change in the crd-clusterissuers.yaml:

  @@ -3184,7 +3184,7 @@ spec:
                 type: object
                 properties:
                   acme:
  -                  description: ACME [...] communicate with a RFC8555
  +                  description: ACME [...] communicate with a RFC8556
                     type: object

Unfortunately, controller-gen v0.2.9-0.20200414181213-645d44dca7c0
silently skips faulty CRD manifests. In our case, the CRD had become a
non-YAML file (we need to use some if statements):

  {{- if .Values.webhook.url.host }}
  url: https://{{ .Values.webhook.url.host }}/convert
  {{- else }}
  service:
    name: {{ template "webhook.fullname" . }}
    namespace: {{ .Release.Namespace | quote }}
    path: /convert
  {{- end }}

Two issues can be found (we can use a YAML parser like yq for that):

1. The pipe "|" used in ".Release.Namespace | quote" makes it an invalid
   YAML file. We could rewrite that to

     {{ quote .Release.Namespace }}

  but I decided to go with actual quotes like with the rest of the
  file.

2. The {{ if }}, {{ else }} and {{ end }} are also invalid YAML syntax,
   and one easy workaround is to comment them.

So many workarounds... but it now works!

Signed-off-by: Maël Valais <mael@vls.dev>
@jetstack-bot jetstack-bot added this to the v1.4 milestone May 11, 2021
@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. area/deploy Indicates a PR modifies deployment configuration approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 11, 2021
@jetstack-bot jetstack-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 11, 2021
@maelvls
Copy link
Member Author

maelvls commented May 11, 2021

Not sure I went in the right direction with this fix 😅 @irbekrm @jakexks is that what was expected?

@maelvls
Copy link
Member Author

maelvls commented May 11, 2021

Weird, tests are passing on my machine 😅 Seems like some form of flakiness...

% ./devel/cluster/create-kind.sh
% ./devel/setup-e2e-deps.sh
% bazel run //test/integration/ctl:go_default_test -- -test.v
Executing tests from //test/integration/ctl:go_default_test
-----------------------------------------------------------------------------
--- FAIL: TestCtlRenew (88.19s)
    testwebhook.go:110: Waiting for ListenPort to be allocated (got error: Run() must be called before Port())
    apiserver.go:75: Found CRD with name "certificaterequests.cert-manager.io"
    apiserver.go:75: Found CRD with name "certificates.cert-manager.io"
    apiserver.go:75: Found CRD with name "challenges.acme.cert-manager.io"
    apiserver.go:75: Found CRD with name "clusterissuers.cert-manager.io"
    apiserver.go:75: Found CRD with name "issuers.cert-manager.io"
    apiserver.go:75: Found CRD with name "orders.acme.cert-manager.io"
    --- FAIL: TestCtlRenew/--all_and_namespace_given (1.12s)
        ctl_renew_test.go:157: Post "http://127.0.0.1:40339/apis/cert-manager.io/v1/namespaces/testns-1/certificates": context deadline exceeded

/retest

@maelvls maelvls requested a review from irbekrm May 11, 2021 18:12
Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

I tested it locally and verified that the CRDs are updated properly.

/lgtm

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label May 12, 2021
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maelvls, wallrj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@maelvls
Copy link
Member Author

maelvls commented May 12, 2021

Note: I reported the issue in kubernetes-sigs/controller-tools#571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/deploy Indicates a PR modifies deployment configuration dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hack/update-crds.sh no longer updates CRDs
3 participants