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

enable ssh debug and Error msg debug #264

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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