Skip to content

Use the client's kube context instead of the kubeconfig's current one - #3368

Open
pingxin403 wants to merge 1 commit into
devspace-sh:mainfrom
pingxin403:fix/kube-context-ignored
Open

pingxin403 wants to merge 1 commit into
devspace-sh:mainfrom
pingxin403:fix/kube-context-ignored

Conversation

@pingxin403

Copy link
Copy Markdown

Fixes #3362

What

Both symptoms come from the kubeconfig's own current-context being used instead of the context the client was created with.

  1. IsMinikubeKubernetes read rawConfig.Contexts[rawConfig.CurrentContext] and dereferenced the result without checking that the entry exists. With --kube-context naming a context the kubeconfig does not select, or a kubeconfig whose current-context is not defined, the lookup returns nil and devspace build panics in IsMinikubeKubernetes (reported stack: util.go:256). The context is now the client's CurrentContext(), and both the context and its cluster are checked before the cluster extensions are read.

  2. DeployConfig.buildManifests copies the raw kubeconfig into a temporary file and hands it to kubectl create through KUBECONFIG, but never updates CurrentContext, so kubectl queries whatever cluster the kubeconfig selects. The copy now sets CurrentContext to the client's context, so --kube-context applies to the kustomize/kubectl render as well.

Tests

TestIsMinikubeContext covers the four cases: a context the kubeconfig does not define (previously a nil dereference), a context whose cluster is missing, a cluster carrying the minikube provider extension, and a cluster without it.

Negative check: removing the existence check reproduces panic: runtime error: invalid memory address or nil pointer dereference in the first case.

go test ./pkg/devspace/kubectl/ ./pkg/devspace/deploy/deployer/kubectl/ passes.

IsMinikubeKubernetes indexed rawConfig.Contexts with the kubeconfig's own
current context without checking that the entry exists, so a context
selected with --kube-context panicked with a nil pointer when the
kubeconfig pointed at a context it does not define. The lookup now uses
the context the client was created with and checks both the context and
its cluster.

The kubectl manifest builder wrote the raw kubeconfig to a temporary file
without updating its current context, so kubectl queried the cluster the
kubeconfig selects rather than the one --kube-context names. The copied
config now carries the client's context.

Signed-off-by: pingxin403 <26605276+pingxin403@users.noreply.github.com>
@netlify

netlify Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devspace-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit b9205c7
🔍 Latest deploy log https://app.netlify.com/projects/devspace-docs/deploys/6b1397d867841fa16b80587f

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--kube-context is ignored in two places

1 participant