k3s-io / k3s-ansible

Apache License 2.0
2.08k stars 822 forks source link

Fix kubeconfig merge with existing config #351

Open alankan-finocomp opened 4 months ago

alankan-finocomp commented 4 months ago

Changes

Since the existing config file was not in scope, the commands did not perform anything.

To fix it, I include the existing kubeconfig path in KUBECONFIG variable such that the YAML contents are merged when it prints out via kubectl config view --flatten

Also, replacing keyword "default" with ansible variable kube_config can also help replace the current-context in the kubeconfig file.

Linked Issues

https://github.com/k3s-io/k3s-ansible/issues/350

dereknola commented 4 months ago

~This function is not intended to merge with the default kubeconfig. That's why there is an explicit check~ This seems to be an error with the if statement, it should be reversed. https://github.com/k3s-io/k3s-ansible/blob/master/roles/k3s_server/tasks/main.yml#L160

The intention is that if supply a dedicated kubeconfig location for the k3s-ansible controlled clusters, we don't do any merging or overriding.

joaogbcravo commented 2 months ago

There is also the block which can cause a full overwrite.