Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify kubeconfig for multiple clusters (kubernetes-sigs#112)
kubeadm does not currently allow to configure a user reference id, and instead always uses kubernetes-admin. This causes a problem when we create multiple clusters with Kind and want to use each corresponding kubeconfig file at the same time in KUBECONFIG. Until kubeadm supports configuring a user reference id, the only option to fix this for Kind is to modify the kubeconfig file that kubeadm provides. As Kind already did this with the server name, it made sense to take the logic further and also make the user reference id unique to a cluster. Three approaches were considered: 1- continue with the current approach of parsing each line of the admin.conf kubeconfig file, and make the modifications necessary. After implementing this approach, the solution seemed quite brittle as it uses regex but no yaml structure. 2- use the go package yaml.v2 to -fully- parse the yaml of the admin.conf kubeconfig file, make the modifications, and then output the new yaml kubeconfig file. This solution requires to define a detailed struct of every field contained in the original yaml file. Having to map every field in advance is brittle as any modification that kubeadm may make to the file in the future would require adaptation in Kind. 3- use the go package yaml.v2 to -generically- parse the yaml of the admin.conf kubeconfig file, make the modifications, and then output the new yaml kubeconfig file. This solution only accesses the yaml fields that are required to be modified. Although any future changes from kubeadm to those fields would require modifications in Kind, modifications to all other fields would not. This commit implements solution #3 which was felt to be the most future-proof and least brittle of the three. Signed-off-by: Marc Khouzam <[email protected]>