krane icon indicating copy to clipboard operation
krane copied to clipboard

fix: validate that contexts exists before trying to build client

Open philippeboyd opened this issue 2 months ago • 0 comments

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 avatar Dec 10 '25 21:12 philippeboyd