From d9ef9bec342df59cf0b1640f1112952cd0c7d2e2 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Thu, 30 Jun 2022 16:45:21 +0100 Subject: [PATCH] kubernetes: add error when no pods available This prevents the fall-through to the panic from division by zero in the modulus below, and presents a neater error to the user. Signed-off-by: Justin Chadwell --- driver/kubernetes/podchooser/podchooser.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/driver/kubernetes/podchooser/podchooser.go b/driver/kubernetes/podchooser/podchooser.go index 66984e06..059d0aec 100644 --- a/driver/kubernetes/podchooser/podchooser.go +++ b/driver/kubernetes/podchooser/podchooser.go @@ -6,6 +6,7 @@ import ( "sort" "time" + "github.com/pkg/errors" "github.com/serialx/hashring" "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" @@ -29,6 +30,9 @@ func (pc *RandomPodChooser) ChoosePod(ctx context.Context) (*corev1.Pod, error) if err != nil { return nil, err } + if len(pods) == 0 { + return nil, errors.New("no running buildkit pods found") + } randSource := pc.RandSource if randSource == nil { randSource = rand.NewSource(time.Now().Unix())