From 49762d7f9e72ee205d96493ebd79680be074a6ae Mon Sep 17 00:00:00 2001 From: Michael Kuhnt Date: Thu, 19 Jan 2023 14:05:00 +0100 Subject: [PATCH] fix: shortid generates correctly now --- runner/pool/pool.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 82f58f64..c943e55a 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -32,6 +32,7 @@ import ( providerCommon "garm/runner/providers/common" "github.com/google/go-github/v48/github" + "github.com/google/uuid" "github.com/pkg/errors" "github.com/teris-io/shortid" ) @@ -388,9 +389,6 @@ func (r *basePoolManager) acquireNewInstance(job params.WorkflowJob) error { return nil } -// use own alphabet to avoid '-' and '_' in the shortid -const shortidABC = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - func (r *basePoolManager) AddRunner(ctx context.Context, poolID string) error { pool, err := r.helper.GetPoolByID(poolID) if err != nil { @@ -401,7 +399,11 @@ func (r *basePoolManager) AddRunner(ctx context.Context, poolID string) error { if prefix == "" { prefix = params.DefaultRunnerPrefix } - name := fmt.Sprintf("%s-%s", prefix, shortid.MustNew(0, shortidABC, 42).String()) + suffix, err := shortid.Generate() + if err != nil { + suffix = uuid.New().String() + } + name := fmt.Sprintf("%s-%s", prefix, suffix) createParams := params.CreateInstanceParams{ Name: name,