Merge pull request #123171 from vrutkovs/kubeadm-issue3014

kubeadm: use current-context when validating kubelet kubeconfig
This commit is contained in:
Kubernetes Prow Robot 2024-02-07 09:04:06 -08:00 committed by GitHub
commit e7d84c9f08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.
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]
if !ok {
return errors.Errorf("the file %q does not contain authentication for user %q", kubeconfigPath, cfg.NodeRegistration.Name)