Skip to content

Commit 1cbb524

Browse files
committed
feat(deisctl): add -ssh-timeout command-line option
1 parent 658d944 commit 1cbb524

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

deisctl/backend/fleet/registry.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/coreos/fleet/client"
1111
"github.com/coreos/fleet/etcd"
1212
"github.com/coreos/fleet/machine"
13+
"github.com/coreos/fleet/pkg"
1314
"github.com/coreos/fleet/registry"
1415
"github.com/coreos/fleet/ssh"
1516
)
@@ -28,6 +29,7 @@ var Flags = struct {
2829
StrictHostKeyChecking bool
2930
Tunnel string
3031
RequestTimeout float64
32+
SSHTimeout float64
3133
}{}
3234

3335
const (
@@ -68,9 +70,10 @@ func getFakeClient() (*registry.FakeRegistry, error) {
6870

6971
func getRegistryClient() (client.API, error) {
7072
var dial func(string, string) (net.Conn, error)
73+
sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
7174
tun := getTunnelFlag()
7275
if tun != "" {
73-
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
76+
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false, sshTimeout)
7477
if err != nil {
7578
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
7679
}
@@ -84,27 +87,27 @@ func getRegistryClient() (client.API, error) {
8487
}
8588
}
8689

87-
tlsConfig, err := etcd.ReadTLSConfigFiles(Flags.EtcdCAFile, Flags.EtcdCertFile, Flags.EtcdKeyFile)
90+
tlsConfig, err := pkg.ReadTLSConfigFiles(Flags.EtcdCAFile, Flags.EtcdCertFile, Flags.EtcdKeyFile)
8891
if err != nil {
8992
return nil, err
9093
}
9194

92-
trans := http.Transport{
95+
trans := &http.Transport{
9396
Dial: dial,
9497
TLSClientConfig: tlsConfig,
9598
}
9699

97100
timeout := time.Duration(Flags.RequestTimeout*1000) * time.Millisecond
98101
machines := []string{Flags.Endpoint}
99-
eClient, err := etcd.NewClient(machines, &trans, timeout)
102+
eClient, err := etcd.NewClient(machines, trans, timeout)
100103
if err != nil {
101104
return nil, err
102105
}
103106

104107
reg := registry.NewEtcdRegistry(eClient, Flags.EtcdKeyPrefix)
105108

106109
// if msg, ok := checkVersion(reg); !ok {
107-
// fmt.Fprint(os.Stderr, msg)
110+
// stderr(msg)
108111
// }
109112

110113
return &client.RegistryClient{Registry: reg}, nil

deisctl/backend/fleet/ssh.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77
"strings"
88
"syscall"
9+
"time"
910

1011
"github.com/coreos/fleet/machine"
1112
"github.com/coreos/fleet/ssh"
@@ -25,7 +26,8 @@ func runCommand(cmd string, machID string) (retcode int) {
2526
if err != nil || ms == nil {
2627
fmt.Printf("Error getting machine IP: %v\n", err)
2728
} else {
28-
err, retcode = runRemoteCommand(cmd, ms.PublicIP)
29+
sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
30+
err, retcode = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
2931
if err != nil {
3032
fmt.Printf("Error running remote command: %v\n", err)
3133
}
@@ -57,12 +59,12 @@ func runLocalCommand(cmd string) (error, int) {
5759

5860
// runRemoteCommand runs the given command over SSH on the given IP, and returns
5961
// any error encountered and the exit status of the command
60-
func runRemoteCommand(cmd string, addr string) (err error, exit int) {
62+
func runRemoteCommand(cmd string, addr string, timeout time.Duration) (err error, exit int) {
6163
var sshClient *ssh.SSHForwardingClient
6264
if tun := getTunnelFlag(); tun != "" {
63-
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false)
65+
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
6466
} else {
65-
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false)
67+
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
6668
}
6769
if err != nil {
6870
return err, -1

deisctl/config/etcd.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"time"
99

10-
fleetEtcd "github.com/coreos/fleet/etcd"
10+
"github.com/coreos/fleet/pkg"
1111
"github.com/coreos/fleet/ssh"
1212
"github.com/coreos/go-etcd/etcd"
1313
"github.com/deis/deis/deisctl/backend/fleet"
@@ -52,9 +52,10 @@ func (c *etcdClient) Set(key string, value string) (string, error) {
5252

5353
func getEtcdClient() (*etcdClient, error) {
5454
var dial func(string, string) (net.Conn, error)
55+
sshTimeout := time.Duration(fleet.Flags.SSHTimeout*1000) * time.Millisecond
5556
tun := getTunnelFlag()
5657
if tun != "" {
57-
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
58+
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false, sshTimeout)
5859
if err != nil {
5960
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
6061
}
@@ -68,7 +69,7 @@ func getEtcdClient() (*etcdClient, error) {
6869
}
6970
}
7071

71-
tlsConfig, err := fleetEtcd.ReadTLSConfigFiles(fleet.Flags.EtcdCAFile,
72+
tlsConfig, err := pkg.ReadTLSConfigFiles(fleet.Flags.EtcdCAFile,
7273
fleet.Flags.EtcdCertFile, fleet.Flags.EtcdKeyFile)
7374
if err != nil {
7475
return nil, err

deisctl/deisctl.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Options:
5252
--etcd-keyfile=<path> etcd key file authentication [default: ]
5353
--known-hosts-file=<path> where to store remote fingerprints [default: ~/.ssh/known_hosts]
5454
--request-timeout=<secs> seconds before a request is considered failed [default: 10.0]
55+
--ssh-timeout=<secs> seconds before SSH connection is considered failed [default: 10.0]
5556
--strict-host-key-checking verify SSH host keys [default: true]
5657
--tunnel=<host> SSH tunnel for communication with fleet and etcd [default: ]
5758
--version print the version of deisctl
@@ -134,9 +135,10 @@ func isGlobalArg(arg string) bool {
134135
"--etcd-cafile=",
135136
// "--experimental-api=",
136137
"--known-hosts-file=",
137-
"--strict-host-key-checking=",
138138
"--request-timeout=",
139-
"--tunnel",
139+
"--ssh-timeout=",
140+
"--strict-host-key-checking=",
141+
"--tunnel=",
140142
}
141143
for _, p := range prefixes {
142144
if strings.HasPrefix(arg, p) {
@@ -202,6 +204,8 @@ func setGlobalFlags(args map[string]interface{}, setTunnel bool) {
202204
fleet.Flags.StrictHostKeyChecking = args["--strict-host-key-checking"].(bool)
203205
timeout, _ := strconv.ParseFloat(args["--request-timeout"].(string), 64)
204206
fleet.Flags.RequestTimeout = timeout
207+
sshTimeout, _ := strconv.ParseFloat(args["--ssh-timeout"].(string), 64)
208+
fleet.Flags.SSHTimeout = sshTimeout
205209
if setTunnel == true {
206210
tunnel := args["--tunnel"].(string)
207211
if tunnel != "" {

0 commit comments

Comments
 (0)