Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark more errors as runner system failures #32

Merged
merged 1 commit into from
Oct 21, 2024
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
4 changes: 2 additions & 2 deletions internal/command/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func executePrepare(ctx context.Context, env gitlab.Environment) error {
apiClientConfig := getAPIClientConfig(env)
apiClient, err := ankacloud.NewAPIClient(apiClientConfig)
if err != nil {
return fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err)
return gitlab.TransientError(fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err))
}
controller := ankacloud.NewController(apiClient)

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

instance, err := controller.WaitForInstanceToBeScheduled(ctx, instanceId)
Expand Down
18 changes: 9 additions & 9 deletions internal/command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
apiClientConfig := getAPIClientConfig(env)
apiClient, err := ankacloud.NewAPIClient(apiClientConfig)
if err != nil {
return fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err)
return gitlab.TransientError(fmt.Errorf("failed to initialize API client with config +%v: %w", apiClientConfig, err))
}

controller := ankacloud.NewController(apiClient)

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

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

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

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

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

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

log.Debugln("ssh connection established")

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

err = session.Shell()
if err != nil {
return fmt.Errorf("failed to start Shell on SSH session: %w", err)
return gitlab.TransientError(fmt.Errorf("failed to start Shell on SSH session: %w", err))
}

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