Skip to content

Commit

Permalink
Only Cancel() the k8s job when Await returned an error
Browse files Browse the repository at this point in the history
  • Loading branch information
CerealBoy committed Aug 19, 2024
1 parent 08f161e commit 4d5d84c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,13 +1268,17 @@ func (e *Executor) kubernetesSetup(ctx context.Context, k8sAgentSocket *kubernet
go func() {
// If the k8s client is interrupted because the "server" agent is
// stopped or unreachable, we should stop running the job.
// If the k8s client is interrupted because our own ctx was cancelled,
// then the job is already stopping, so there's no point logging an
// error.
if err := k8sAgentSocket.Await(ctx, kubernetes.RunStateInterrupt); err != nil && !errors.Is(err, context.Canceled) {
e.shell.Errorf("Error waiting for client interrupt: %v", err)
err := k8sAgentSocket.Await(ctx, kubernetes.RunStateInterrupt)
if err != nil {
// If the k8s client is interrupted because our own ctx was cancelled,
// then the job is already stopping, so there's no point logging an
// error.
if !errors.Is(err, context.Canceled) {
e.shell.Errorf("Error waiting for client interrupt: %v", err)
}
// If there's an error from Await, we should Cancel the job.
e.Cancel()
}
e.Cancel()
}()
return nil
}

0 comments on commit 4d5d84c

Please sign in to comment.