From fd60b9c492f7c3480805522a78cf23dacb1692fb Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Wed, 28 Dec 2022 14:23:35 +0800 Subject: [PATCH] kubeadm: return the output from stdout and stderr It was just saying the copy of file failed with `exit status 1`, no much details for what's going wrong. Combine the stderr and stdout and show those info will be easier for us to fix the problem. Signed-off-by: Dave Chen --- cmd/kubeadm/app/phases/upgrade/staticpods.go | 10 ++++++---- cmd/kubeadm/app/util/copy_unix.go | 5 ++--- cmd/kubeadm/app/util/copy_windows.go | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/kubeadm/app/phases/upgrade/staticpods.go b/cmd/kubeadm/app/phases/upgrade/staticpods.go index 524a624c34f..b62b3e15476 100644 --- a/cmd/kubeadm/app/phases/upgrade/staticpods.go +++ b/cmd/kubeadm/app/phases/upgrade/staticpods.go @@ -280,8 +280,9 @@ func performEtcdStaticPodUpgrade(certsRenewMgr *renewal.Manager, client clientse // Backing up etcd data store backupEtcdDir := pathMgr.BackupEtcdDir() runningEtcdDir := cfg.Etcd.Local.DataDir - if err := kubeadmutil.CopyDir(runningEtcdDir, backupEtcdDir); err != nil { - return true, errors.Wrap(err, "failed to back up etcd data") + output, err := kubeadmutil.CopyDir(runningEtcdDir, backupEtcdDir) + if err != nil { + return true, errors.Wrapf(err, "failed to back up etcd data, output: %q", output) } // Get the desired etcd version. That's either the one specified by the user in cfg.Etcd.Local.ImageTag @@ -531,9 +532,10 @@ func rollbackEtcdData(cfg *kubeadmapi.InitConfiguration, pathMgr StaticPodPathMa backupEtcdDir := pathMgr.BackupEtcdDir() runningEtcdDir := cfg.Etcd.Local.DataDir - if err := kubeadmutil.CopyDir(backupEtcdDir, runningEtcdDir); err != nil { + output, err := kubeadmutil.CopyDir(backupEtcdDir, runningEtcdDir) + if err != nil { // Let the user know there we're problems, but we tried to reçover - return errors.Wrapf(err, "couldn't recover etcd database with error, the location of etcd backup: %s ", backupEtcdDir) + return errors.Wrapf(err, "couldn't recover etcd database with error, the location of etcd backup: %s, output: %q", backupEtcdDir, output) } return nil diff --git a/cmd/kubeadm/app/util/copy_unix.go b/cmd/kubeadm/app/util/copy_unix.go index e2601bc94e8..0d75b09dd0e 100644 --- a/cmd/kubeadm/app/util/copy_unix.go +++ b/cmd/kubeadm/app/util/copy_unix.go @@ -24,7 +24,6 @@ import ( ) // CopyDir copies the content of a folder -func CopyDir(src string, dst string) error { - cmd := exec.Command("cp", "-r", src, dst) - return cmd.Run() +func CopyDir(src string, dst string) ([]byte, error) { + return exec.Command("cp", "-r", src, dst).CombinedOutput() } diff --git a/cmd/kubeadm/app/util/copy_windows.go b/cmd/kubeadm/app/util/copy_windows.go index e689e200432..e20f4f7b936 100644 --- a/cmd/kubeadm/app/util/copy_windows.go +++ b/cmd/kubeadm/app/util/copy_windows.go @@ -24,9 +24,8 @@ import ( ) // CopyDir copies the content of a folder -func CopyDir(src string, dst string) error { +func CopyDir(src string, dst string) ([]byte, error) { // /E Copies directories and subdirectories, including empty ones. // /H Copies hidden and system files also. - cmd := exec.Command("xcopy", "/E", "/H", src, dst) - return cmd.Run() + return exec.Command("xcopy", "/E", "/H", src, dst).CombinedOutput() }