kubernetes: kubectl fails when duplicate context names are present

Is this a BUG REPORT or FEATURE REQUEST?:

/kind bug

What happened: I brought up an AKS cluster with name testcluster.Then ran azure-cli command az aks get-credentials to set the current kubectl context to point to the new cluster.The command ran successfully. Now on running kubectl get nodes, I was greeted with the following error

$ kubectl get nodes 
error: Error loading config file "/home/atom/.kube/config": error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name "testcluster" in list [{
...
...
 55 73 75 10 45 45 45 45 45 69 78 68 32 67 69 82 84 73 70 73 67 65 84 69 45 45 45 45 45 10] []}}]

What you expected to happen:

Expected kubectl to use the current cluster context and run the command.

How to reproduce it (as minimally and precisely as possible): I believe this was caused because contexts with the same name are exists. So testing in such an environment can bringup this issue.

Anything else we need to know?: When this bug happens, we can’t run any other commands. I believe this bug exists in a pre run hook.If this bug is valid I will be happy to work on a PR.

Environment:

  • Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.1", GitCommit:"b1b29978270dc22fecc592ac55d903350454310a", GitTreeState:"clean", BuildDate:"2018-07-17T18:53:20Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.9", GitCommit:"57729ea3d9a1b75f3fc7bbbadc597ba707d47c8a", GitTreeState:"clean", BuildDate:"2018-06-29T01:07:01Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

  • Cloud provider or hardware configuration: Azure AKS
  • OS (e.g. from /etc/os-release):
NAME="Ubuntu"
VERSION="18.04 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
  • Kernel (e.g. uname -a): Linux drogon 4.15.0-24-generic #26-Ubuntu SMP Wed Jun 13 08:44:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Yeah right. I just nuke the ~/.kube directory to make things right for me.