Skip to content

Commit aeba20d

Browse files
mark more errors as gitlab transient errors as they should cause runner system failures (#32)
1 parent e3efc34 commit aeba20d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

internal/command/prepare.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func executePrepare(ctx context.Context, env gitlab.Environment) error {
3131
apiClientConfig := getAPIClientConfig(env)
3232
apiClient, err := ankacloud.NewAPIClient(apiClientConfig)
3333
if err != nil {
34-
return fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err)
34+
return gitlab.TransientError(fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err))
3535
}
3636
controller := ankacloud.NewController(apiClient)
3737

@@ -77,7 +77,7 @@ func executePrepare(ctx context.Context, env gitlab.Environment) error {
7777
log.Debugf("payload %+v\n", req)
7878
instanceId, err := controller.CreateInstance(ctx, req)
7979
if err != nil {
80-
return fmt.Errorf("failed to create instance: %w", err)
80+
return gitlab.TransientError(fmt.Errorf("failed to create instance: %w", err))
8181
}
8282

8383
instance, err := controller.WaitForInstanceToBeScheduled(ctx, instanceId)

internal/command/run.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
3838
apiClientConfig := getAPIClientConfig(env)
3939
apiClient, err := ankacloud.NewAPIClient(apiClientConfig)
4040
if err != nil {
41-
return fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err)
41+
return gitlab.TransientError(fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err))
4242
}
4343

4444
controller := ankacloud.NewController(apiClient)
4545

4646
instance, err := controller.GetInstanceByExternalId(ctx, env.GitlabJobUrl)
4747
if err != nil {
48-
return fmt.Errorf("failed to get instance by external id %q: %w", env.GitlabJobUrl, err)
48+
return gitlab.TransientError(fmt.Errorf("failed to get instance by external id %q: %w", env.GitlabJobUrl, err))
4949
}
5050

5151
var nodeSshPort string
5252
if instance.VMInfo == nil {
53-
return fmt.Errorf("instance has no VM: %+v", instance)
53+
return gitlab.TransientError(fmt.Errorf("instance has no VM: %+v", instance))
5454
}
5555

5656
for _, rule := range instance.VMInfo.PortForwardingRules {
@@ -59,13 +59,13 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
5959
}
6060
}
6161
if nodeSshPort == "" {
62-
return fmt.Errorf("could not find ssh port forwarded for vm")
62+
return gitlab.TransientError(fmt.Errorf("could not find ssh port forwarded for vm"))
6363
}
6464
log.Debugf("node SSH port to VM: %s\n", nodeSshPort)
6565

6666
gitlabScriptFile, err := os.Open(args[0])
6767
if err != nil {
68-
return fmt.Errorf("failed to open script file at %q: %w", args[0], err)
68+
return gitlab.TransientError(fmt.Errorf("failed to open script file at %q: %w", args[0], err))
6969
}
7070
defer gitlabScriptFile.Close()
7171
log.Debugf("gitlab script path: %s", args[0])
@@ -90,7 +90,7 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
9090

9191
node, err := controller.GetNode(ctx, ankacloud.GetNodeRequest{Id: instance.NodeId})
9292
if err != nil {
93-
return fmt.Errorf("failed to get node %s: %w", instance.NodeId, err)
93+
return gitlab.TransientError(fmt.Errorf("failed to get node %s: %w", instance.NodeId, err))
9494
}
9595

9696
addr := fmt.Sprintf("%s:%s", node.IP, nodeSshPort)
@@ -114,15 +114,15 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
114114
time.Sleep(time.Duration(sshConnectionAttemptDelay) * time.Second)
115115
}
116116
if err != nil {
117-
return fmt.Errorf("failed to create new ssh client connection to %q: %w", addr, err)
117+
return gitlab.TransientError(fmt.Errorf("failed to create new ssh client connection to %q: %w", addr, err))
118118
}
119119
defer sshClient.Close()
120120

121121
log.Debugln("ssh connection established")
122122

123123
session, err := sshClient.NewSession()
124124
if err != nil {
125-
return fmt.Errorf("failed to start new ssh session: %w", err)
125+
return gitlab.TransientError(fmt.Errorf("failed to start new ssh session: %w", err))
126126
}
127127
defer session.Close()
128128
log.Debugln("ssh session opened")
@@ -133,7 +133,7 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
133133

134134
err = session.Shell()
135135
if err != nil {
136-
return fmt.Errorf("failed to start Shell on SSH session: %w", err)
136+
return gitlab.TransientError(fmt.Errorf("failed to start Shell on SSH session: %w", err))
137137
}
138138

139139
log.Debugln("waiting for remote execution to finish")

0 commit comments

Comments
 (0)