From af2ae9bab86af57a51d184f5b944ed37e7ecdc44 Mon Sep 17 00:00:00 2001 From: Tejas Sharma Date: Fri, 18 Oct 2024 13:41:55 -0700 Subject: [PATCH] mark more errors as gitlab transient errors as they should cause runner system failures --- internal/command/prepare.go | 4 ++-- internal/command/run.go | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/command/prepare.go b/internal/command/prepare.go index 09abfdc..5e52fbc 100644 --- a/internal/command/prepare.go +++ b/internal/command/prepare.go @@ -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) @@ -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) diff --git a/internal/command/run.go b/internal/command/run.go index f62ce28..db14871 100644 --- a/internal/command/run.go +++ b/internal/command/run.go @@ -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 { @@ -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]) @@ -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) @@ -114,7 +114,7 @@ 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() @@ -122,7 +122,7 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro 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") @@ -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")