'Is "current-context" a mandatory key in a kubeconfig file?

THE PLOT:

I am working on a kubernetes environment where we have PROD and ITG setup. The ITG setup has multi-cluster environment whereas PROD setup is a single-cluster environment. I am trying to automate some process using Python where I have to deal with kubeconfig file and I am using the kubernetes library for it.

THE PROBLEM:

The kubeconfig file for PROD has "current-context" key available but the same is missing from the kubeconfig file for ITG.

prdconfig:

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://cluster3.url.com:3600
  name: cluster-ABC
contexts:
- context:
    cluster: cluster-LMN
    user: cluster-user
  name: cluster-LMN-context
current-context: cluster-LMN-context
kind: Config
preferences: {}
users:
- name: cluster-user
  user:
    exec:
      command: kubectl
      apiVersion: <clientauth/version>
      args:
      - kubectl-custom-plugin
      - authenticate
      - https://cluster.url.com:8080
      - --user=user
      - --token=/api/v2/session/xxxx
      - --token-expiry=1000000000
      - --force-reauth=false
      - --insecure-skip-tls-verify=true

itgconfig:

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://cluster1.url.com:3600
  name: cluster-ABC
- cluster:
    insecure-skip-tls-verify: true
    server: https://cluster2.url.com:3601
  name: cluster-XYZ
contexts:
- context:
    cluster: cluster-ABC
    user: cluster-user
  name: cluster-ABC-context
- context:
    cluster: cluster-XYZ
    user: cluster-user
  name: cluster-XYZ-context
kind: Config
preferences: {}
users:
- name: cluster-user
  user:
    exec:
      command: kubectl
      apiVersion: <clientauth/version>
      args:
      - kubectl-custom-plugin
      - authenticate
      - https://cluster.url.com:8080
      - --user=user
      - --token=/api/v2/session/xxxx
      - --token-expiry=1000000000
      - --force-reauth=false
      - --insecure-skip-tls-verify=true

When I try loading the kubeconfig file for PROD using config.load_kube_config(os.path.expanduser('~/.kube/prdconfig')) it works.

And when I try loading the kubeconfig file for ITG using config.load_kube_config(os.path.expanduser('~/.kube/itgconfig')), I get the following error:

ConfigException: Invalid kube-config file. Expected key current-context in C:\Users<username>/.kube/itgconfig

Although it is very clear from the error message that it is considering the kubeconfig file as invalid, as it does not have "current-context" key in it.

THE SUB-PLOT:

When working with kubectl, the missing "current-context" does not make any difference as we can always specify context along with the command. But the 'load_kube_config()' function makes it mandatory to have "current-context" available.

THE QUESTION:

So, is "current-context" a mandatory key in kubeconfig file?

THE DISCLAIMER:

I am very new to kubernetes and have very little experience working with it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source