From 3fa6662875b869442f54dc6f4bf5e72ae61a08b1 Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Sun, 9 Oct 2022 17:08:35 +0800 Subject: [PATCH] kubeadm: print out the solution if CA files do not exist phase `kubeadm init phase kubeconfig/*` must run after the phase `kubeadm init phase certs/ca` to get the client cert and key singed by the CA. print out the way to generate the CA file is more useful than just say the file cannot be loaded. Signed-off-by: Dave Chen --- cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go index dcb0b64923c..eeac15bb958 100644 --- a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go +++ b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go @@ -140,6 +140,9 @@ func createKubeConfigFiles(outDir string, cfg *kubeadmapi.InitConfiguration, kub // NB. this method holds the information about how kubeadm creates kubeconfig files. func getKubeConfigSpecs(cfg *kubeadmapi.InitConfiguration) (map[string]*kubeConfigSpec, error) { caCert, caKey, err := pkiutil.TryLoadCertAndKeyFromDisk(cfg.CertificatesDir, kubeadmconstants.CACertAndKeyBaseName) + if os.IsNotExist(errors.Cause(err)) { + return nil, errors.Wrap(err, "the CA files do not exist, please run `kubeadm init phase certs ca` to generate it") + } if err != nil { return nil, errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded") }