Skip to content

Conversation

@philippeboyd
Copy link

@philippeboyd philippeboyd commented Dec 10, 2025

What are you trying to accomplish with this PR?

If the first file in environment variable KUBECONFIG is "empty" with simply the following structure

apiVersion: v1
clusters: null
contexts: null
current-context: some-cluster
kind: Config
preferences: {}
users: null

krane will crash with the following error when trying to access contexts in gem kubeclient because contexts is set to null in the empty config.

'Kubeclient::Config#contexts': undefined method 'map' for nil (NoMethodError)

      @kcfg['contexts'].map { |x| x['name'] }

How is this accomplished?
By adding validation when creating @kubeclient_configs to simply skip files in $KUBECONFIG that have null contexts. This does parse the file twice tough (once in krane for validation then in kubeclient).

Is this the right approach?

What could go wrong?
Nothing really, file with null contexts will be ignored when building the kube client.

@philippeboyd philippeboyd requested a review from a team as a code owner December 10, 2025 21:21
Copy link

@Mangara Mangara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once test failures are addressed.

@philippeboyd philippeboyd force-pushed the bugfix/validate-empty-context-kube-config branch from 659ad9d to 8dbfe0a Compare December 11, 2025 14:03
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.

2 participants