carvel-dev / kapp

kapp is a simple deployment tool focused on the concept of "Kubernetes application" — a set of resources with the same label

Home Page:https://carvel.dev/kapp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kapp uses wrong default namespace when run in-cluster (with explicit `KUBECONFIG` env var)

hojerst opened this issue · comments

What steps did you take:

  • Prepare kapp/kctrl in a Pod of a Kubernetes cluster
  • set KUBECONFIG (and/or KAPP_KUBECONFIG) to another cluster where no default namespace is set
  • execute kapp ls or kapp deploy without a explicit namespace

What happened:
kapp will default to the namespace of the execution environment (pod it is running in), although the KUBECONFIG might point to a completely different cluster which doesn't have this namespace

What did you expect:
kapp will install the manifests into default namespace or the one explicitly configured inside the KUBECONFIG

Anything else you would like to add:
As a workaround it seems to explicitly unsetting KUBERNETES_SERVICE_HOST or KUBERNETES_SERVICE_PORT seems to fix this behaviour as https://github.com/kubernetes/client-go/blob/1517ffb8d37c99e6a3a2842bcdee0aa271f0332b/tools/clientcmd/client_config.go#L604-L609 seems to check for that (thanks to @cppforlife for pointing this out in Slack)

Environment:

  • kapp version (use kapp --version): kapp version 0.54.1
  • OS (e.g. from /etc/os-release): Debian 11 (doesn't seem to matter)
  • Kubernetes version (use kubectl version): not relevant

Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

After some discussion in slack, it seems this is a behaviour introduced by the upstream k8s go client. kubectl shows the same behaviour as well. I'll close this as it is not really a problem of kapp

kubernetes/client-go#1241