From 57646c941f9412d13a12aa23925b82cfc7383ae9 Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Wed, 22 Jun 2022 10:36:11 +0800 Subject: [PATCH] kubeadm: Honor `cert-dir` for cert operations - `cert-dir` could be specified to a value other than the default value - we have tests that should be executed successfully on the working cluster Signed-off-by: Dave Chen --- cmd/kubeadm/app/cmd/certs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/kubeadm/app/cmd/certs.go b/cmd/kubeadm/app/cmd/certs.go index 62cf2fcdf0c..fffa9d7a381 100644 --- a/cmd/kubeadm/app/cmd/certs.go +++ b/cmd/kubeadm/app/cmd/certs.go @@ -26,6 +26,7 @@ import ( "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/util/duration" + "k8s.io/klog/v2" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme" @@ -335,6 +336,14 @@ func getInternalCfg(cfgPath string, kubeconfigPath string, cfg kubeadmapiv1.Clus internalcfg, err := configutil.FetchInitConfigurationFromCluster(client, nil, logPrefix, false, false) if err == nil { fmt.Println() // add empty line to separate the FetchInitConfigurationFromCluster output from the command output + // certificate renewal or expiration checking doesn't depend on a running cluster, which means the CertificatesDir + // could be set to a value other than the default value or the value fetched from the cluster. + // cfg.CertificatesDir could be empty if the default value is set to empty (not true today). + if len(cfg.CertificatesDir) != 0 { + klog.V(1).Infof("Overriding the cluster certificate directory with the value from command line flag --%s: %s", options.CertificatesDir, cfg.CertificatesDir) + internalcfg.ClusterConfiguration.CertificatesDir = cfg.CertificatesDir + } + return internalcfg, nil } fmt.Printf("[%s] Error reading configuration from the Cluster. Falling back to default configuration\n\n", logPrefix)