Skip to content

File tree

3 files changed

+59
-45
lines changed

3 files changed

+59
-45
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Accepted values for booleans are: "1", "t", "T", "true", "TRUE", "True", "0", "f
6161
| ANKA_CLOUD_BUILDS_DIR | ❌ | String | Absolute path to a directory where builds are stored in the VM. If not supplied, "/tmp/builds" is used. |
6262
| ANKA_CLOUD_CACHE_DIR | ❌ | String | Absolute path to a directory where build caches are stored in the VM. If not supplied, "/tmp/cache" is used. |
6363
| ANKA_SSH_CONNECTION_ATTEMPTS | ❌ | Number | The attempts to make when sshing to the VM. Useful when VMs take a long time to start under stressful situations or slow disks (like EBS). Defaults to `4` -- Minimum value of 1 |
64+
| ANKA_SSH_CONNECTION_ATTEMPT_DELAY | ❌ | Number | The delay between ssh connection attempts in seconds. Defaults to `5` |
6465
| ANKA_CLOUD_SSH_USER_NAME | ❌ | String | SSH user name to use inside VM. Defaults to "anka". This can also be set via a command line flags to prevent this value from being exposed to the job. See example below. |
6566
| ANKA_CLOUD_SSH_PASSWORD | ❌ | String | SSH password to use inside VM. Defaults to "admin". This can also be set via a command line flags to prevent this value from being exposed to the job. See example below. |
6667

internal/command/run.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
106106
if maxAttempts < 1 {
107107
maxAttempts = 4
108108
}
109+
sshConnectionAttemptDelay := env.SSHConnectionAttemptDelay
110+
if sshConnectionAttemptDelay < 1 {
111+
sshConnectionAttemptDelay = 5
112+
}
109113
for i := 0; i < maxAttempts; i++ {
110114
log.Printf("attempt #%d to establish ssh connection to %q\n", i+1, addr)
111115
sshClient, err = ssh.Dial("tcp", addr, sshClientConfig)
112116
if err == nil {
113117
break
114118
}
115-
time.Sleep(5 * time.Second)
119+
time.Sleep(time.Duration(sshConnectionAttemptDelay) * time.Second)
116120
}
117121
if err != nil {
118122
return fmt.Errorf("failed to create new ssh client connection to %q: %w", addr, err)

internal/gitlab/vars.go

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,59 @@ const (
1818

1919
var (
2020
// Custom Executor vars
21-
varDebug = ankaVar("DEBUG")
22-
varControllerURL = ankaVar("CONTROLLER_URL")
23-
varTemplateId = ankaVar("TEMPLATE_ID")
24-
varTemplateTag = ankaVar("TEMPLATE_TAG")
25-
varNodeId = ankaVar("NODE_ID")
26-
varPriority = ankaVar("PRIORITY")
27-
varNodeGroupId = ankaVar("NODE_GROUP_ID")
28-
varCaCertPath = ankaVar("CA_CERT_PATH")
29-
varSkipTLSVerify = ankaVar("SKIP_TLS_VERIFY")
30-
varClientCertPath = ankaVar("CLIENT_CERT_PATH")
31-
varClientCertKeyPath = ankaVar("CLIENT_CERT_KEY_PATH")
32-
varSshUserName = ankaVar("SSH_USER_NAME")
33-
varSshPassword = ankaVar("SSH_PASSWORD")
34-
varSshAttempts = ankaVar("SSH_CONNECTION_ATTEMPTS")
35-
varCustomHTTPHeaders = ankaVar("CUSTOM_HTTP_HEADERS")
36-
varKeepAliveOnError = ankaVar("KEEP_ALIVE_ON_ERROR")
37-
varTemplateName = ankaVar("TEMPLATE_NAME")
38-
varBuildsDir = ankaVar("BUILDS_DIR")
39-
varCacheDir = ankaVar("CACHE_DIR")
40-
varVmVramMb = ankaVar("VM_VRAM_MB")
41-
varVmVcpu = ankaVar("VM_VCPU")
21+
varDebug = ankaVar("DEBUG")
22+
varControllerURL = ankaVar("CONTROLLER_URL")
23+
varTemplateId = ankaVar("TEMPLATE_ID")
24+
varTemplateTag = ankaVar("TEMPLATE_TAG")
25+
varNodeId = ankaVar("NODE_ID")
26+
varPriority = ankaVar("PRIORITY")
27+
varNodeGroupId = ankaVar("NODE_GROUP_ID")
28+
varCaCertPath = ankaVar("CA_CERT_PATH")
29+
varSkipTLSVerify = ankaVar("SKIP_TLS_VERIFY")
30+
varClientCertPath = ankaVar("CLIENT_CERT_PATH")
31+
varClientCertKeyPath = ankaVar("CLIENT_CERT_KEY_PATH")
32+
varSshUserName = ankaVar("SSH_USER_NAME")
33+
varSshPassword = ankaVar("SSH_PASSWORD")
34+
varSshAttempts = ankaVar("SSH_CONNECTION_ATTEMPTS")
35+
varSshConnectionAttemptDelay = ankaVar("SSH_CONNECTION_ATTEMPT_DELAY")
36+
varCustomHTTPHeaders = ankaVar("CUSTOM_HTTP_HEADERS")
37+
varKeepAliveOnError = ankaVar("KEEP_ALIVE_ON_ERROR")
38+
varTemplateName = ankaVar("TEMPLATE_NAME")
39+
varBuildsDir = ankaVar("BUILDS_DIR")
40+
varCacheDir = ankaVar("CACHE_DIR")
41+
varVmVramMb = ankaVar("VM_VRAM_MB")
42+
varVmVcpu = ankaVar("VM_VCPU")
4243

4344
// Gitlab vars
4445
varGitlabJobId = gitlabVar("CI_JOB_ID")
4546
varGitlabJobStatus = gitlabVar("CI_JOB_STATUS")
4647
)
4748

4849
type Environment struct {
49-
ControllerURL string
50-
Debug bool
51-
TemplateId string
52-
TemplateTag string
53-
NodeId string
54-
Priority int
55-
NodeGroupId string
56-
CaCertPath string
57-
SkipTLSVerify bool
58-
ClientCertPath string
59-
ClientCertKeyPath string
60-
SSHUserName string
61-
SSHPassword string
62-
SSHAttempts int
63-
GitlabJobId string
64-
CustomHttpHeaders map[string]string
65-
KeepAliveOnError bool
66-
GitlabJobStatus jobStatus
67-
TemplateName string
68-
BuildsDir string
69-
CacheDir string
70-
VmVramMb int
71-
VmVcpu int
50+
ControllerURL string
51+
Debug bool
52+
TemplateId string
53+
TemplateTag string
54+
NodeId string
55+
Priority int
56+
NodeGroupId string
57+
CaCertPath string
58+
SkipTLSVerify bool
59+
ClientCertPath string
60+
ClientCertKeyPath string
61+
SSHUserName string
62+
SSHPassword string
63+
SSHAttempts int
64+
SSHConnectionAttemptDelay int
65+
GitlabJobId string
66+
CustomHttpHeaders map[string]string
67+
KeepAliveOnError bool
68+
GitlabJobStatus jobStatus
69+
TemplateName string
70+
BuildsDir string
71+
CacheDir string
72+
VmVramMb int
73+
VmVcpu int
7274
}
7375

7476
type jobStatus string
@@ -118,6 +120,13 @@ func InitEnv() (Environment, error) {
118120
}
119121
e.SSHAttempts = sshAttempts
120122
}
123+
if sshConnectionAttemptDelay, ok, err := GetIntEnvVar(varSshConnectionAttemptDelay); ok {
124+
if err != nil {
125+
return e, fmt.Errorf("%w %q: %w", ErrInvalidVar, varSshConnectionAttemptDelay, err)
126+
}
127+
e.SSHConnectionAttemptDelay = sshConnectionAttemptDelay
128+
}
129+
121130
e.TemplateId = os.Getenv(varTemplateId)
122131
e.TemplateName = os.Getenv(varTemplateName)
123132
e.TemplateTag = os.Getenv(varTemplateTag)

0 commit comments

Comments
 (0)