Kong / charts

Helm chart for Kong
Apache License 2.0
248 stars 480 forks source link

`kong`: Cannot install more than 1 ingress controller release with the same name in different namespace #910

Open pmalek opened 1 year ago

pmalek commented 1 year ago

Problem statement

When using kong chart, users cannot install more than 1 ingress controller releases with the same name in different namespaces.

$ helm upgrade --install --create-namespace -n kong kic --values ./v_kic.yaml ./charts/kong
Release "kic" does not exist. Installing it now.
NAME: kic
LAST DEPLOYED: Fri Oct 20 17:55:54 2023
NAMESPACE: kong
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
To connect to Kong, please execute the following commands:

HOST=$(kubectl get svc --namespace kong kic-kong-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
PORT=$(kubectl get svc --namespace kong kic-kong-proxy -o jsonpath='{.spec.ports[0].port}')
export PROXY_IP=${HOST}:${PORT}
curl $PROXY_IP

Once installed, please follow along the getting started guide to start using
Kong: https://docs.konghq.com/kubernetes-ingress-controller/latest/guides/getting-started/
$ helm upgrade --install --create-namespace -n kong1 kic --values ./v_kic.yaml ./charts/kong
Release "kic" does not exist. Installing it now.
Error: Unable to continue with install: ClusterRole "kic-kong" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-namespace" must equal "kong1": current value is "kong"

Trying to fix the ClusterRole issue by including the namespace in the name

diff --git a/charts/kong/templates/_helpers.tpl b/charts/kong/templates/_helpers.tpl
index 7564c2e..1a77fc8 100644
--- a/charts/kong/templates/_helpers.tpl
+++ b/charts/kong/templates/_helpers.tpl
@@ -18,7 +18,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this

 {{- define "kong.fullname" -}}
 {{- $name := default .Chart.Name .Values.nameOverride -}}
-{{- default (printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-") .Values.fullnameOverride -}}
+{{- default (printf "%s-%s-%s" .Release.Namespace .Release.Name $name | trunc 63 | trimSuffix "-") .Values.fullnameOverride -}}
 {{- end -}}

 {{- define "kong.chart" -}}

Doesn't solve the problem because then we're conflicting owners of the IngressClass

Error: Unable to continue with install: IngressClass "kong" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-namespace" must equal "kong1": current value is "kong"

Surprisingly, installing in the same namespace with different release name works. The helm annotations on the IngressClass are then retained to refer to the first release.

Proposed solution(s)