Skip to content

Commit

Permalink
controller-gen can now update CRDs like before
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
maelvls committed May 11, 2021
1 parent 2aa625e commit 39c9c66
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions deploy/crds/crd-certificaterequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ spec:
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
{{- if .Values.webhook.url.host }}
# {{- if .Values.webhook.url.host }}
url: https://{{ .Values.webhook.url.host }}/convert
{{- else }}
# {{- else }}
service:
name: {{ template "webhook.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
name: '{{ template "webhook.fullname" . }}'
namespace: "{{ .Release.Namespace }}"
path: /convert
{{- end }}
# {{- end }}
versions:
- name: v1alpha2
subresources:
Expand Down
10 changes: 5 additions & 5 deletions deploy/crds/crd-certificates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ spec:
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
{{- if .Values.webhook.url.host }}
# {{- if .Values.webhook.url.host }}
url: https://{{ .Values.webhook.url.host }}/convert
{{- else }}
# {{- else }}
service:
name: {{ template "webhook.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
name: '{{ template "webhook.fullname" . }}'
namespace: "{{ .Release.Namespace }}"
path: /convert
{{- end }}
# {{- end }}
versions:
- name: v1alpha2
subresources:
Expand Down
10 changes: 5 additions & 5 deletions deploy/crds/crd-challenges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ spec:
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
{{- if .Values.webhook.url.host }}
# {{- if .Values.webhook.url.host }}
url: https://{{ .Values.webhook.url.host }}/convert
{{- else }}
# {{- else }}
service:
name: {{ template "webhook.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
name: '{{ template "webhook.fullname" . }}'
namespace: "{{ .Release.Namespace }}"
path: /convert
{{- end }}
# {{- end }}
versions:
- additionalPrinterColumns:
- jsonPath: .status.state
Expand Down
10 changes: 5 additions & 5 deletions deploy/crds/crd-clusterissuers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ spec:
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
{{- if .Values.webhook.url.host }}
# {{- if .Values.webhook.url.host }}
url: https://{{ .Values.webhook.url.host }}/convert
{{- else }}
# {{- else }}
service:
name: {{ template "webhook.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
name: '{{ template "webhook.fullname" . }}'
namespace: "{{ .Release.Namespace }}"
path: /convert
{{- end }}
# {{- end }}
versions:
- name: v1alpha2
subresources:
Expand Down
10 changes: 5 additions & 5 deletions deploy/crds/crd-issuers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ spec:
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
{{- if .Values.webhook.url.host }}
# {{- if .Values.webhook.url.host }}
url: https://{{ .Values.webhook.url.host }}/convert
{{- else }}
# {{- else }}
service:
name: {{ template "webhook.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
name: '{{ template "webhook.fullname" . }}'
namespace: "{{ .Release.Namespace }}"
path: /convert
{{- end }}
# {{- end }}
versions:
- name: v1alpha2
subresources:
Expand Down
10 changes: 5 additions & 5 deletions deploy/crds/crd-orders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ spec:
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
{{- if .Values.webhook.url.host }}
# {{- if .Values.webhook.url.host }}
url: https://{{ .Values.webhook.url.host }}/convert
{{- else }}
# {{- else }}
service:
name: {{ template "webhook.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
name: '{{ template "webhook.fullname" . }}'
namespace: "{{ .Release.Namespace }}"
path: /convert
{{- end }}
# {{- end }}
versions:
- name: v1alpha2
subresources:
Expand Down

0 comments on commit 39c9c66

Please sign in to comment.