From 4e4ab691c808acec59ac637060ad3c10ff00a314 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Tue, 10 May 2022 16:10:02 +0000 Subject: [PATCH] Error when deleting a pool with runners --- runner/pools.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runner/pools.go b/runner/pools.go index 81656ddf..a2e186f0 100644 --- a/runner/pools.go +++ b/runner/pools.go @@ -52,6 +52,18 @@ func (r *Runner) DeletePoolByID(ctx context.Context, poolID string) error { return runnerErrors.ErrUnauthorized } + pool, err := r.store.GetPoolByID(ctx, poolID) + if err != nil { + if !errors.Is(err, runnerErrors.ErrNotFound) { + return errors.Wrap(err, "fetching pool") + } + return nil + } + + if len(pool.Instances) > 0 { + return runnerErrors.NewBadRequestError("pool has runners") + } + if err := r.store.DeletePoolByID(ctx, poolID); err != nil { return errors.Wrap(err, "fetching pool") }