From a6e3c5c326d6b33db027bf8b4c06c5055f8adb6e Mon Sep 17 00:00:00 2001 From: tedteng Date: Thu, 20 Aug 2020 08:58:43 +0800 Subject: [PATCH] enable ssh debug and Error msg debug --- pkg/cmd/root.go | 2 +- pkg/cmd/ssh_aws.go | 7 ++++++- pkg/cmd/utils.go | 12 ++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index a231e8337..ce8393f9b 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -130,7 +130,7 @@ func init() { RootCmd.PersistentFlags().BoolVarP(&cachevar, "no-cache", "c", false, "no caching") RootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "yaml", "output format yaml or json") - RootCmd.PersistentFlags().BoolVarP(&debugSwitch, "debug", "d", false, "enable debug level output") + RootCmd.PersistentFlags().BoolVarP(&debugSwitch, "verbose", "d", false, "enable verbose output") cobra.EnableCommandSorting = false cobra.EnablePrefixMatching = prefixMatching diff --git a/pkg/cmd/ssh_aws.go b/pkg/cmd/ssh_aws.go index f245fba35..9ef2d1c3e 100644 --- a/pkg/cmd/ssh_aws.go +++ b/pkg/cmd/ssh_aws.go @@ -80,7 +80,12 @@ func sshToAWSNode(nodeName, path, user, pathSSKeypair string, sshPublicKey []byt fmt.Print("SSH " + bastionNode + " => " + node) key := filepath.Join(pathSSKeypair, "key") - sshCmd := fmt.Sprintf("ssh -i " + key + " -o ConnectionAttempts=2 -o \"ProxyCommand ssh -W %%h:%%p -i " + key + " -o IdentitiesOnly=yes -o ConnectionAttempts=2 -o StrictHostKeyChecking=no " + bastionNode + "\" " + node + " -o IdentitiesOnly=yes -o StrictHostKeyChecking=no") + var sshCmd string + if debugSwitch { + sshCmd = fmt.Sprintf("ssh -v -i " + key + " -o ConnectionAttempts=2 -o \"ProxyCommand ssh -W %%h:%%p -i " + key + " -o IdentitiesOnly=yes -o ConnectionAttempts=2 -o StrictHostKeyChecking=no " + bastionNode + "\" " + node + " -o IdentitiesOnly=yes -o StrictHostKeyChecking=no") + } else { + sshCmd = fmt.Sprintf("ssh -i " + key + " -o ConnectionAttempts=2 -o \"ProxyCommand ssh -W %%h:%%p -i " + key + " -o IdentitiesOnly=yes -o ConnectionAttempts=2 -o StrictHostKeyChecking=no " + bastionNode + "\" " + node + " -o IdentitiesOnly=yes -o StrictHostKeyChecking=no") + } cmd := exec.Command("bash", "-c", sshCmd) cmd.Stdout = os.Stdout cmd.Stdin = os.Stdin diff --git a/pkg/cmd/utils.go b/pkg/cmd/utils.go index 0d40df7ae..07db31d1f 100644 --- a/pkg/cmd/utils.go +++ b/pkg/cmd/utils.go @@ -17,9 +17,11 @@ package cmd import ( "fmt" "io/ioutil" + "log" "os" "os/exec" "path/filepath" + "runtime" "strings" gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1" @@ -34,8 +36,14 @@ import ( // checkError checks if an error during execution occurred func checkError(err error) { if err != nil { - fmt.Println(err.Error()) - os.Exit(2) + if debugSwitch { + _, fn, line, _ := runtime.Caller(1) + log.Printf("[error] %s:%d \n %v", fn, line, err) + os.Exit(2) + } else { + fmt.Println(err.Error()) + os.Exit(2) + } } }