From dede5cc46597ad24015e74b69a845d10b244f50c Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Sat, 16 Jul 2022 13:41:26 +0000 Subject: [PATCH] Allow deletion of a runner in error state Signed-off-by: Gabriel Adrian Samfira --- runner/pool/pool.go | 9 ++++++--- runner/runner.go | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 54e735e3..bd0af614 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -845,14 +845,17 @@ func (r *basePool) ForceDeleteRunner(runner params.Instance) error { if resp != nil { switch resp.StatusCode { case http.StatusUnprocessableEntity: - return errors.Wrapf(runnerErrors.ErrUnprocessable, "removing runner: %q", err) + return errors.Wrapf(runnerErrors.ErrBadRequest, "removing runner: %q", err) case http.StatusNotFound: - return errors.Wrapf(runnerErrors.ErrNotFound, "removing runner: %q", err) + // Runner may have been deleted by a finished job, or manually by the user. + log.Printf("runner with agent id %d was not found in github", runner.AgentID) default: return errors.Wrap(err, "removing runner") } + } else { + // We got a nil response. Assume we are in error. + return errors.Wrap(err, "removing runner") } - return errors.Wrap(err, "removing runner") } } diff --git a/runner/runner.go b/runner/runner.go index 804ffaf1..48c3309e 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -520,8 +520,10 @@ func (r *Runner) ForceDeleteRunner(ctx context.Context, instanceName string) err return errors.Wrap(err, "fetching instance") } - if instance.Status != providerCommon.InstanceRunning { - return runnerErrors.NewBadRequestError("runner must be in %q state", providerCommon.InstanceRunning) + switch instance.Status { + case providerCommon.InstanceRunning, providerCommon.InstanceError: + default: + return runnerErrors.NewBadRequestError("runner must be in %q or %q state", providerCommon.InstanceRunning, providerCommon.InstanceError) } pool, err := r.store.GetPoolByID(ctx, instance.PoolID)