Kong / charts

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

Test jobs are always created in the default namespace #605

Open dlouzan opened 2 years ago

dlouzan commented 2 years ago

Hello, this might be a misconfiguration on my end, though I have tried multiple configuration options to no avail. Anytime I deploy the helm chart, I get some test jobs on the default namespace, even though I want and set this to be on a fixed kong namespace (the default namespace is also used, but for other tasks):

Sample values.yml:

namespace: kong

Sample CLI call:

helm template kong/kong --namespace kong --values ./values.yml --version=2.8.2

In the output, everything is namespaced except these three pods:

# Source: kong/templates/tests/test-jobs.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "release-name-test-ingress"
  annotations:
    "helm.sh/hook": test
spec:
  restartPolicy: OnFailure
  containers:
    - name: "release-name-curl"
      image: curlimages/curl
      command:
        - curl
        - "http://release-name-kong-proxy.kong.svc.cluster.local/httpbin"
---
# Source: kong/templates/tests/test-jobs.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "release-name-test-ingress-v1beta1"
  annotations:
    "helm.sh/hook": test
spec:
  restartPolicy: OnFailure
  containers:
    - name: "release-name-curl"
      image: curlimages/curl
      command:
        - curl
        - "http://release-name-kong-proxy.kong.svc.cluster.local/httpbin-v1beta1"
---
# Source: kong/templates/tests/test-jobs.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "release-name-test-httproute"
  annotations:
    "helm.sh/hook": test
spec:
  restartPolicy: OnFailure
  containers:
    - name: "release-name-curl"
      image: curlimages/curl
      command:
        - curl
        - "http://release-name-kong-proxy.kong.svc.cluster.local/httpbin-httproute"

This is kind-of related to https://github.com/Kong/charts/pull/599, but in principle I'd like to keep the tests, just that they should respect the namespace setting ๐Ÿ˜…

It is not a huge issue, it just contaminates a bit the default namespace, since I wanted to keep everything ingress-related into the kong namespace.

Thanks for the awesome work!

pmalek commented 2 years ago

Hi @dlouzan ๐Ÿ‘‹

You're right that the manifests themselves won't have the namespace specified but regardless of that if you specify the --namespace flag in the helm invocation (just as you've done in the linked snippet) those objects will land in the designated namespace on the cluster.

Please let us know if that works for you

dlouzan commented 2 years ago

@pmalek Since the resources do not add the namespace to their definitions, they will end up in whatever the default namespace is, which does not have to match what is passed in the helm invocation. In an invocation where multiple resources in (possibly) different namespaces are involved e.g. with kustomize, this is an issue. ๐Ÿ™‡

pmalek commented 2 years ago

Hm perhaps this might be an issue with kustomize (not sure, haven't checked it) but to illustrate my testing method you can see (and try it yourself) that those test objects indeed land in the designated namespace event though there's a different default namespace set for context that's being used:

$ k config get-contexts kind-kong
CURRENT   NAME        CLUSTER     AUTHINFO    NAMESPACE
*         kind-kong   kind-kong   kind-kong   kong4
$ helm install --create-namespace --namespace kong3 kong-test1 --values ./charts/kong/values.yaml ./charts/kong
NAME: kong-test1
LAST DEPLOYED: Thu Jun 23 12:34:53 2022
NAMESPACE: kong3
STATUS: deployed
REVISION: 1
NOTES:
To connect to Kong, please execute the following commands:

HOST=$(kubectl get svc --namespace kong3 kong-test1-kong-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
PORT=$(kubectl get svc --namespace kong3 kong-test1-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/
$ k get pods -A | grep kong
kong3                kong-test1-httpbin                           0/1     CrashLoopBackOff   1 (10s ago)   14s
kong3                kong-test1-kong-c6447d86c-bggjj              1/2     CrashLoopBackOff   1 (12s ago)   14s