Skip to content

Commit 9f0858f

Browse files
committed
allow config of connection timeout and error limit
1 parent d6e5c40 commit 9f0858f

File tree

9 files changed

+62
-19
lines changed

9 files changed

+62
-19
lines changed

common/config/environment.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const (
3434
DDInfraExtraResourcesTags = "extraResourcesTags"
3535
DDInfraSSHUser = "sshUser"
3636
DDInfraInitOnly = "initOnly"
37+
DDInfraDialErrorLimit = "dialErrorLimit"
38+
DDInfraPerDialTimeoutSeconds = "perDialTimeoutSeconds"
3739

3840
// Agent Namespace
3941
DDAgentDeployParamName = "deploy"
@@ -244,6 +246,14 @@ func (e *CommonEnvironment) InfraSSHUser() string {
244246
return e.GetStringWithDefault(e.InfraConfig, DDInfraSSHUser, "")
245247
}
246248

249+
func (e *CommonEnvironment) InfraDialErrorLimit() int {
250+
return e.GetIntWithDefault(e.InfraConfig, DDInfraDialErrorLimit, 0)
251+
}
252+
253+
func (e *CommonEnvironment) InfraPerDialTimeoutSeconds() int {
254+
return e.GetIntWithDefault(e.InfraConfig, DDInfraPerDialTimeoutSeconds, 0)
255+
}
256+
247257
func EnvVariableResourceTags() map[string]string {
248258
tags := map[string]string{}
249259
lookupVars := []string{"TEAM", "PIPELINE_ID", "CI_PIPELINE_ID"}

components/remote/connection.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import (
77
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
88
)
99

10-
const (
11-
// We retry every 5s maximum 100 times (~8 minutes)
12-
dialTimeoutSeconds int = 5
13-
dialErrorLimit int = 100
14-
)
15-
1610
// NewConnection creates a remote connection to a host.
1711
// Host and user are mandatory.
1812
func NewConnection(host pulumi.StringInput, user string, options ...ConnectionOption) (*remote.ConnectionArgs, error) {
@@ -24,8 +18,8 @@ func NewConnection(host pulumi.StringInput, user string, options ...ConnectionOp
2418
conn := &remote.ConnectionArgs{
2519
Host: args.host,
2620
User: pulumi.String(args.user),
27-
PerDialTimeout: pulumi.IntPtr(dialTimeoutSeconds),
28-
DialErrorLimit: pulumi.IntPtr(dialErrorLimit),
21+
PerDialTimeout: pulumi.IntPtr(args.perDialTimeoutSeconds),
22+
DialErrorLimit: pulumi.IntPtr(args.dialErrorLimit),
2923
Port: pulumi.Float64Ptr(float64(args.port)),
3024
}
3125

components/remote/connectionargs.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
package remote
22

33
import (
4-
"github.com/DataDog/test-infra-definitions/common"
54
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
5+
6+
"github.com/DataDog/test-infra-definitions/common"
67
)
78

89
type connectionArgs struct {
910
host pulumi.StringInput
1011
user string
1112

1213
// ==== Optional ====
13-
privateKeyPath string
14-
privateKeyPassword string
15-
sshAgentPath string
16-
port int
14+
privateKeyPath string
15+
privateKeyPassword string
16+
sshAgentPath string
17+
port int
18+
dialErrorLimit int
19+
perDialTimeoutSeconds int
1720
}
1821

1922
type ConnectionOption = func(*connectionArgs) error
2023

2124
func buildConnectionArgs(host pulumi.StringInput, user string, options ...ConnectionOption) (*connectionArgs, error) {
2225
args := &connectionArgs{
23-
host: host,
24-
user: user,
25-
port: 22,
26+
host: host,
27+
user: user,
28+
port: 22,
29+
dialErrorLimit: 100,
30+
perDialTimeoutSeconds: 5,
2631
}
2732
return common.ApplyOption(args, options)
2833
}
@@ -58,3 +63,23 @@ func WithPort(port int) ConnectionOption {
5863
return nil
5964
}
6065
}
66+
67+
// WithDialErrorLimit [optional] sets the maximum dial attempts for the connection. Defaults to 100.
68+
func WithDialErrorLimit(limit int) ConnectionOption {
69+
return func(args *connectionArgs) error {
70+
if limit > 0 {
71+
args.dialErrorLimit = limit
72+
}
73+
return nil
74+
}
75+
}
76+
77+
// WithPerDialTimeoutSeconds [optional] sets the per dial timeout in seconds for the connection. Defaults to 5.
78+
func WithPerDialTimeoutSeconds(seconds int) ConnectionOption {
79+
return func(args *connectionArgs) error {
80+
if seconds > 0 {
81+
args.perDialTimeoutSeconds = seconds
82+
}
83+
return nil
84+
}
85+
}

resources/hyperv/vm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func NewVM(e Environment, args VMArgs, opts ...pulumi.ResourceOption) (*remote.H
3737
"<SSH_USER_NAME>",
3838
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
3939
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
40+
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
41+
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
4042
)
4143
if err != nil {
4244
return err

scenarios/aws/ec2/vm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func NewVM(e aws.Environment, name string, params ...VMOption) (*remote.Host, er
8080
sshUser,
8181
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
8282
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
83+
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
84+
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
8385
)
8486
if err != nil {
8587
return err

scenarios/aws/microVMs/microvms/provision.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
1010
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
1111

12+
commonConfig "github.com/DataDog/test-infra-definitions/common/config"
1213
"github.com/DataDog/test-infra-definitions/common/namer"
1314
"github.com/DataDog/test-infra-definitions/components/command"
1415
remoteComp "github.com/DataDog/test-infra-definitions/components/remote"
@@ -232,6 +233,8 @@ func provisionRemoteMicroVMs(vmCollections []*VMCollection, instanceEnv *Instanc
232233
"ubuntu",
233234
remoteComp.WithPrivateKeyPath(instanceEnv.DefaultPrivateKeyPath()),
234235
remoteComp.WithPrivateKeyPassword(instanceEnv.DefaultPrivateKeyPassword()),
236+
remoteComp.WithDialErrorLimit(instanceEnv.InfraDialErrorLimit()),
237+
remoteComp.WithPerDialTimeoutSeconds(instanceEnv.InfraPerDialTimeoutSeconds()),
235238
)
236239
if err != nil {
237240
return nil, err
@@ -276,7 +279,7 @@ func provisionRemoteMicroVMs(vmCollections []*VMCollection, instanceEnv *Instanc
276279
return waitFor, nil
277280
}
278281

279-
func provisionLocalMicroVMs(vmCollections []*VMCollection) ([]pulumi.Resource, error) {
282+
func provisionLocalMicroVMs(vmCollections []*VMCollection, e commonConfig.CommonEnvironment) ([]pulumi.Resource, error) {
280283
var waitFor []pulumi.Resource
281284
for _, collection := range vmCollections {
282285
if collection.instance.Arch != LocalVMSet {
@@ -294,6 +297,8 @@ func provisionLocalMicroVMs(vmCollections []*VMCollection) ([]pulumi.Resource, e
294297
domain.ip,
295298
"root",
296299
remoteComp.WithPrivateKeyPath(filepath.Join(GetWorkingDirectory(domain.vmset.Arch), "ddvm_rsa")),
300+
remoteComp.WithDialErrorLimit(e.InfraDialErrorLimit()),
301+
remoteComp.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
297302
)
298303
if err != nil {
299304
return nil, err

scenarios/aws/microVMs/microvms/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func run(e commonConfig.CommonEnvironment) (*ScenarioDone, error) {
365365
return nil, err
366366
}
367367

368-
if _, err := provisionLocalMicroVMs(vmCollections); err != nil {
368+
if _, err := provisionLocalMicroVMs(vmCollections, e); err != nil {
369369
return nil, err
370370
}
371371
}

scenarios/azure/compute/vm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func NewVM(e azure.Environment, name string, params ...VMOption) (*remote.Host,
6363
compute.AdminUsername,
6464
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
6565
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
66+
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
67+
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
6668
)
6769
if err != nil {
6870
return err

scenarios/gcp/compute/vm.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package compute
33
import (
44
"fmt"
55

6+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
7+
68
"github.com/DataDog/test-infra-definitions/components"
79
"github.com/DataDog/test-infra-definitions/components/command"
810
"github.com/DataDog/test-infra-definitions/components/os"
911
"github.com/DataDog/test-infra-definitions/components/remote"
1012
"github.com/DataDog/test-infra-definitions/resources/gcp/compute"
11-
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
1213

1314
"github.com/DataDog/test-infra-definitions/resources/gcp"
1415
)
@@ -40,6 +41,8 @@ func NewVM(e gcp.Environment, name string, option ...VMOption) (*remote.Host, er
4041
"gce",
4142
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
4243
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
44+
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
45+
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
4346
)
4447
if err != nil {
4548
return err

0 commit comments

Comments
 (0)