Skip to content

Commit f41825e

Browse files
authored
[release/2.1.x] chart: fix rendering webhook-certs volume and volume mount when ko-crds.enabled=false (#3228) (#3411)
1 parent 1b3a743 commit f41825e

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

.github/workflows/charts-tests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ jobs:
172172
- name: Install cert-manager
173173
run: make install.helm.cert-manager
174174

175+
- name: Install CRDs
176+
run: make install.crds
177+
175178
- name: Run chart-testing (install)
176179
run: |
177180
kubectl create ns kong-test
178-
make install.helm.cert-manager
179181
make test.charts.ct.install CHART_NAME=${{ matrix.chart-name}}
180182
# No need to delete the ns the cluster is scrapped after the job anyway.
181183

Makefile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,20 +872,23 @@ test.charts.golden.update:
872872

873873
.PHONY: test.charts.ct.install
874874
test.charts.ct.install:
875-
# NOTE: We add ko-crds.keep=false below because allowing the chart to manage CRDs
875+
# NOTE: We add ko-crds.enabled=false below to handle CRD management outside of ct.
876+
# This is to work around the flaky CRD uninstall behavior of ct.
877+
# Without this, CRDs created by one test helm release installation
878+
# would sometimes not get removed upon uninstalling the release,
876879
# and keep them around after helm uninstall would yield ownership issues.
877880
# Error: INSTALLATION FAILED: Unable to continue with install: CustomResourceDefinition "aigateways.gateway-operator.konghq.com" in namespace ""
878881
# exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-name"
879882
# must equal "kong-operator-h39gau9scc": current value is "kong-operator-tiptva339m"
880883
#
881-
# NOTE: We add the --wait below to ensure that we wait for all objects to get removed
882-
# for each release. Without this, some objects like CRDs can still be around
883-
# when another test helm release is being installed and the above mentioned
884-
# ownership error will be returned.
884+
# This could potentially be solved by setting the --cascade foreground option
885+
# to helm uninstall command in ct, but ct does not currently support passing
886+
# extra args to helm uninstall.
887+
# There's an open PR for this: https://github.com/helm/chart-testing/pull/806
885888

886889
ct install --target-branch main \
887890
--debug \
888-
--helm-extra-set-args "--set=ko-crds.keep=false" \
891+
--helm-extra-set-args "--set=ko-crds.enabled=false" \
889892
--helm-extra-args "--wait" \
890893
--helm-extra-args "--timeout=3m" \
891894
--charts charts/$(CHART_NAME) \
@@ -1071,6 +1074,10 @@ uninstall.helm.cert-manager: download.helm
10711074
# Install CRDs into the K8s cluster specified in ~/.kube/config.
10721075
.PHONY: install
10731076
install: install.helm.cert-manager manifests kustomize install.gateway-api-crds
1077+
$(MAKE) install.crds
1078+
1079+
.PHONY: install.crds
1080+
install.crds: kustomize
10741081
$(KUSTOMIZE) build config/crd | kubectl apply --server-side -f -
10751082

10761083
# Install RBACs from config/rbac into the K8s cluster specified in ~/.kube/config.
@@ -1087,8 +1094,11 @@ install.all: install.helm.cert-manager manifests kustomize install.gateway-api-c
10871094
# Call with ignore-not-found=true to ignore resource not found errors during deletion.
10881095
.PHONY: uninstall
10891096
uninstall: manifests kustomize uninstall.gateway-api-crds uninstall.helm.cert-manager
1090-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
1097+
$(MAKE) uninstall.crds
10911098

1099+
.PHONY: uninstall.crds
1100+
uninstall.crds: kustomize
1101+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
10921102

10931103
# Uninstall standard and experimental CRDs from the K8s cluster specified in ~/.kube/config.
10941104
# Call with ignore-not-found=true to ignore resource not found errors during deletion.

charts/kong-operator/templates/_helpers.tpl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,14 @@ The dict maps raw env variable key to the suggested variable path.
161161

162162
{{- define "kong.volumes" -}}
163163
{{ if .Values.global.webhooks.conversion.enabled }}
164-
{{- /* This volume is conditional on ko-crds being enabled because the certificate */ -}}
165-
{{- /* Secret is placed in that subchart. The reason for this is explained in */ -}}
166-
{{- /* https://github.com/Kong/kong-operator/blob/e555dbc0b6e57beecbb72cf79018ef8fdbe11ffa/hack/generators/conversion-webhook/main.go#L88-L95 */ -}}
167-
{{ $kocrds := (index .Values "ko-crds") }}
168-
{{ if $kocrds.enabled }}
164+
{{- /* Depending on the global.webhooks.options.certManager.enabled being true or false */ -}}
165+
{{- /* certificate below will either be sourced from chart generated Secret */ -}}
166+
{{- /* or from cert-manager generated Secret */ -}}
169167
- name: webhook-certs
170168
secret:
171169
defaultMode: 420
172170
secretName: {{ template "kong.webhookCertSecretName" . }}
173171
{{ end }}
174-
{{ end }}
175172
{{ if .Values.global.webhooks.validating.enabled }}
176173
- name: validating-webhook-certs
177174
secret:
@@ -188,16 +185,13 @@ The dict maps raw env variable key to the suggested variable path.
188185

189186
{{- define "kong.volumeMounts" -}}
190187
{{ if .Values.global.webhooks.conversion.enabled }}
191-
{{- /* This mount is conditional on ko-crds being enabled because the certificate */ -}}
192-
{{- /* Secret is placed in that subchart. The reason for this is explained in */ -}}
193-
{{- /* https://github.com/Kong/kong-operator/blob/e555dbc0b6e57beecbb72cf79018ef8fdbe11ffa/hack/generators/conversion-webhook/main.go#L88-L95 */ -}}
194-
{{ $kocrds := (index .Values "ko-crds") }}
195-
{{ if $kocrds.enabled }}
188+
{{- /* Depending on the global.webhooks.options.certManager.enabled being true or false */ -}}
189+
{{- /* certificate below will either be sourced from chart generated Secret */ -}}
190+
{{- /* or from cert-manager generated Secret */ -}}
196191
- name: webhook-certs
197192
mountPath: /tmp/k8s-webhook-server/serving-certs
198193
readOnly: true
199194
{{ end }}
200-
{{ end }}
201195
{{ if .Values.global.webhooks.validating.enabled }}
202196
- name: validating-webhook-certs
203197
mountPath: /tmp/k8s-webhook-server/serving-certs/validating-admission-webhook

0 commit comments

Comments
 (0)