fix: shortid generates correctly now

This commit is contained in:
Michael Kuhnt 2023-01-19 14:05:00 +01:00
parent c92dfb5d20
commit 49762d7f9e
No known key found for this signature in database
GPG key ID: 088DC1E2EDC5A631

View file

@ -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,