Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #264 from tedteng/debug
Browse files Browse the repository at this point in the history
enable ssh debug and Error msg debug
  • Loading branch information
neo-liang-sap authored Sep 9, 2020
2 parents 0efeaa8 + a6e3c5c commit f4c54d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/ssh_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ func sshToAWSNode(nodeName, path, user, pathSSKeypair string, sshPublicKey []byt
fmt.Print("SSH " + bastionNode + " => " + node + "\n")
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
Expand Down
12 changes: 10 additions & 2 deletions pkg/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit f4c54d9

Please sign in to comment.