Merge pull request #62 from mercedes-benz/fix-shortid

fix: shortid generates correctly now
This commit is contained in:
Gabriel 2023-01-19 15:30:43 +02:00 committed by GitHub
commit 4f2808eb23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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,