Merge pull request #79165 from neolit123/kubeadm-1.16-fix-panic-kubeconfig

kubeadm: improve the kubeconfig file validation phase
This commit is contained in:
Kubernetes Prow Robot 2019-06-19 07:36:35 -07:00 committed by GitHub
commit 4683054ff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -224,7 +224,13 @@ func validateKubeConfig(outDir, filename string, config *clientcmdapi.Config) er
expectedCtx := config.CurrentContext
expectedCluster := config.Contexts[expectedCtx].Cluster
currentCtx := currentConfig.CurrentContext
if currentConfig.Contexts[currentCtx] == nil {
return errors.Errorf("failed to find CurrentContext in Contexts of the kubeconfig file %s", kubeConfigFilePath)
}
currentCluster := currentConfig.Contexts[currentCtx].Cluster
if currentConfig.Clusters[currentCluster] == nil {
return errors.Errorf("failed to find the given CurrentContext Cluster in Clusters of the kubeconfig file %s", kubeConfigFilePath)
}
// If the current CA cert on disk doesn't match the expected CA cert, error out because we have a file, but it's stale
if !bytes.Equal(currentConfig.Clusters[currentCluster].CertificateAuthorityData, config.Clusters[expectedCluster].CertificateAuthorityData) {