mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #123171 from vrutkovs/kubeadm-issue3014
kubeadm: use current-context when validating kubelet kubeconfig
This commit is contained in:
commit
e7d84c9f08
@ -114,7 +114,17 @@ func runKubeletFinalizeCertRotation(c workflow.RunData) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform basic validation. The errors here can only happen if the kubelet.conf was corrupted.
|
// Perform basic validation. The errors here can only happen if the kubelet.conf was corrupted.
|
||||||
userName := fmt.Sprintf("%s%s", kubeadmconstants.NodesUserPrefix, cfg.NodeRegistration.Name)
|
if len(kubeconfig.CurrentContext) == 0 {
|
||||||
|
return errors.Errorf("the file %q does not have current context set", kubeconfigPath)
|
||||||
|
}
|
||||||
|
currentContext, ok := kubeconfig.Contexts[kubeconfig.CurrentContext]
|
||||||
|
if !ok {
|
||||||
|
return errors.Errorf("the file %q is not a valid kubeconfig: %q set as current-context, but not found in context list", kubeconfigPath, kubeconfig.CurrentContext)
|
||||||
|
}
|
||||||
|
userName := currentContext.AuthInfo
|
||||||
|
if len(userName) == 0 {
|
||||||
|
return errors.Errorf("the file %q is not a valid kubeconfig: empty username for current context", kubeconfigPath)
|
||||||
|
}
|
||||||
info, ok := kubeconfig.AuthInfos[userName]
|
info, ok := kubeconfig.AuthInfos[userName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.Errorf("the file %q does not contain authentication for user %q", kubeconfigPath, cfg.NodeRegistration.Name)
|
return errors.Errorf("the file %q does not contain authentication for user %q", kubeconfigPath, cfg.NodeRegistration.Name)
|
||||||
|
Loading…
Reference in New Issue
Block a user