Skip to content
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
10 changes: 10 additions & 0 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
DDInfraExtraResourcesTags = "extraResourcesTags"
DDInfraSSHUser = "sshUser"
DDInfraInitOnly = "initOnly"
DDInfraDialErrorLimit = "dialErrorLimit"
DDInfraPerDialTimeoutSeconds = "perDialTimeoutSeconds"

// Agent Namespace
DDAgentDeployParamName = "deploy"
Expand Down Expand Up @@ -244,6 +246,14 @@ func (e *CommonEnvironment) InfraSSHUser() string {
return e.GetStringWithDefault(e.InfraConfig, DDInfraSSHUser, "")
}

func (e *CommonEnvironment) InfraDialErrorLimit() int {
return e.GetIntWithDefault(e.InfraConfig, DDInfraDialErrorLimit, 0)
}

func (e *CommonEnvironment) InfraPerDialTimeoutSeconds() int {
return e.GetIntWithDefault(e.InfraConfig, DDInfraPerDialTimeoutSeconds, 0)
}

func EnvVariableResourceTags() map[string]string {
tags := map[string]string{}
lookupVars := []string{"TEAM", "PIPELINE_ID", "CI_PIPELINE_ID"}
Expand Down
10 changes: 2 additions & 8 deletions components/remote/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

const (
// We retry every 5s maximum 100 times (~8 minutes)
dialTimeoutSeconds int = 5
dialErrorLimit int = 100
)

// NewConnection creates a remote connection to a host.
// Host and user are mandatory.
func NewConnection(host pulumi.StringInput, user string, options ...ConnectionOption) (*remote.ConnectionArgs, error) {
Expand All @@ -24,8 +18,8 @@ func NewConnection(host pulumi.StringInput, user string, options ...ConnectionOp
conn := &remote.ConnectionArgs{
Host: args.host,
User: pulumi.String(args.user),
PerDialTimeout: pulumi.IntPtr(dialTimeoutSeconds),
DialErrorLimit: pulumi.IntPtr(dialErrorLimit),
PerDialTimeout: pulumi.IntPtr(args.perDialTimeoutSeconds),
DialErrorLimit: pulumi.IntPtr(args.dialErrorLimit),
Port: pulumi.Float64Ptr(float64(args.port)),
}

Expand Down
41 changes: 33 additions & 8 deletions components/remote/connectionargs.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package remote

import (
"github.com/DataDog/test-infra-definitions/common"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/DataDog/test-infra-definitions/common"
)

type connectionArgs struct {
host pulumi.StringInput
user string

// ==== Optional ====
privateKeyPath string
privateKeyPassword string
sshAgentPath string
port int
privateKeyPath string
privateKeyPassword string
sshAgentPath string
port int
dialErrorLimit int
perDialTimeoutSeconds int
}

type ConnectionOption = func(*connectionArgs) error

func buildConnectionArgs(host pulumi.StringInput, user string, options ...ConnectionOption) (*connectionArgs, error) {
args := &connectionArgs{
host: host,
user: user,
port: 22,
host: host,
user: user,
port: 22,
dialErrorLimit: 100,
perDialTimeoutSeconds: 5,
}
return common.ApplyOption(args, options)
}
Expand Down Expand Up @@ -58,3 +63,23 @@ func WithPort(port int) ConnectionOption {
return nil
}
}

// WithDialErrorLimit [optional] sets the maximum dial attempts for the connection. Defaults to 100.
func WithDialErrorLimit(limit int) ConnectionOption {
return func(args *connectionArgs) error {
if limit > 0 {
args.dialErrorLimit = limit
}
return nil
}
}

// WithPerDialTimeoutSeconds [optional] sets the per dial timeout in seconds for the connection. Defaults to 5.
func WithPerDialTimeoutSeconds(seconds int) ConnectionOption {
return func(args *connectionArgs) error {
if seconds > 0 {
args.perDialTimeoutSeconds = seconds
}
return nil
}
}
2 changes: 2 additions & 0 deletions resources/hyperv/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func NewVM(e Environment, args VMArgs, opts ...pulumi.ResourceOption) (*remote.H
"<SSH_USER_NAME>",
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions scenarios/aws/ec2/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func NewVM(e aws.Environment, name string, params ...VMOption) (*remote.Host, er
sshUser,
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
)
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion scenarios/aws/microVMs/microvms/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"

commonConfig "github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/common/namer"
"github.com/DataDog/test-infra-definitions/components/command"
remoteComp "github.com/DataDog/test-infra-definitions/components/remote"
Expand Down Expand Up @@ -232,6 +233,8 @@ func provisionRemoteMicroVMs(vmCollections []*VMCollection, instanceEnv *Instanc
"ubuntu",
remoteComp.WithPrivateKeyPath(instanceEnv.DefaultPrivateKeyPath()),
remoteComp.WithPrivateKeyPassword(instanceEnv.DefaultPrivateKeyPassword()),
remoteComp.WithDialErrorLimit(instanceEnv.InfraDialErrorLimit()),
remoteComp.WithPerDialTimeoutSeconds(instanceEnv.InfraPerDialTimeoutSeconds()),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -276,7 +279,7 @@ func provisionRemoteMicroVMs(vmCollections []*VMCollection, instanceEnv *Instanc
return waitFor, nil
}

func provisionLocalMicroVMs(vmCollections []*VMCollection) ([]pulumi.Resource, error) {
func provisionLocalMicroVMs(vmCollections []*VMCollection, e commonConfig.CommonEnvironment) ([]pulumi.Resource, error) {
var waitFor []pulumi.Resource
for _, collection := range vmCollections {
if collection.instance.Arch != LocalVMSet {
Expand All @@ -294,6 +297,8 @@ func provisionLocalMicroVMs(vmCollections []*VMCollection) ([]pulumi.Resource, e
domain.ip,
"root",
remoteComp.WithPrivateKeyPath(filepath.Join(GetWorkingDirectory(domain.vmset.Arch), "ddvm_rsa")),
remoteComp.WithDialErrorLimit(e.InfraDialErrorLimit()),
remoteComp.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion scenarios/aws/microVMs/microvms/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func run(e commonConfig.CommonEnvironment) (*ScenarioDone, error) {
return nil, err
}

if _, err := provisionLocalMicroVMs(vmCollections); err != nil {
if _, err := provisionLocalMicroVMs(vmCollections, e); err != nil {
return nil, err
}
}
Expand Down
2 changes: 2 additions & 0 deletions scenarios/azure/compute/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func NewVM(e azure.Environment, name string, params ...VMOption) (*remote.Host,
compute.AdminUsername,
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
)
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion scenarios/gcp/compute/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package compute
import (
"fmt"

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/DataDog/test-infra-definitions/components"
"github.com/DataDog/test-infra-definitions/components/command"
"github.com/DataDog/test-infra-definitions/components/os"
"github.com/DataDog/test-infra-definitions/components/remote"
"github.com/DataDog/test-infra-definitions/resources/gcp/compute"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/DataDog/test-infra-definitions/resources/gcp"
)
Expand Down Expand Up @@ -40,6 +41,8 @@ func NewVM(e gcp.Environment, name string, option ...VMOption) (*remote.Host, er
"gce",
remote.WithPrivateKeyPath(e.DefaultPrivateKeyPath()),
remote.WithPrivateKeyPassword(e.DefaultPrivateKeyPassword()),
remote.WithDialErrorLimit(e.InfraDialErrorLimit()),
remote.WithPerDialTimeoutSeconds(e.InfraPerDialTimeoutSeconds()),
)
if err != nil {
return err
Expand Down