@@ -6,14 +6,14 @@ import (
6
6
"io"
7
7
"os"
8
8
"path/filepath"
9
- "strings"
10
9
"sync/atomic"
11
10
"time"
12
11
13
12
"github.com/ovh/cds/engine/api/observability"
14
13
"github.com/ovh/cds/sdk"
15
14
"github.com/ovh/cds/sdk/log"
16
15
"github.com/ovh/cds/sdk/namesgenerator"
16
+ "github.com/ovh/cds/sdk/slug"
17
17
)
18
18
19
19
type workerStarterRequest struct {
@@ -226,39 +226,38 @@ func spawnWorkerForJob(ctx context.Context, h Interface, j workerStarterRequest)
226
226
return true // ok for this job
227
227
}
228
228
229
- // a worker name must be 60 char max, without '.' and '_' -> replaced by '-'
230
- func generateWorkerName (hatcheryName string , isRegister bool , model string ) string {
229
+ // a worker name must be 60 char max, without '.' and '_', "/" -> replaced by '-'
230
+ func generateWorkerName (hatcheryName string , isRegister bool , modelName string ) string {
231
231
prefix := ""
232
232
if isRegister {
233
233
prefix = "register-"
234
234
}
235
235
236
236
maxLength := 63
237
- hName := strings .Replace (strings .ToLower (hatcheryName ), "/" , "-" , - 1 ) + "-"
238
- modelName := strings .Replace (strings .ToLower (model ), "/" , "-" , - 1 )
239
- random := strings .Replace (namesgenerator .GetRandomNameCDS (0 ), "_" , "-" , - 1 )
240
- workerName := strings .Replace (fmt .Sprintf ("%s%s-%s-%s" , prefix , hatcheryName , modelName , random ), "." , "-" , - 1 )
237
+ hName := hatcheryName + "-"
238
+ random := namesgenerator .GetRandomNameCDS (0 )
239
+ workerName := fmt .Sprintf ("%s%s-%s-%s" , prefix , hatcheryName , modelName , random )
241
240
242
241
if len (workerName ) <= maxLength {
243
- return workerName
242
+ return slug . Convert ( workerName )
244
243
}
245
244
if len (hName ) > 10 {
246
245
hName = ""
247
246
}
248
247
workerName = fmt .Sprintf ("%s%s%s-%s" , prefix , hName , modelName , random )
249
248
if len (workerName ) <= maxLength {
250
- return workerName
249
+ return slug . Convert ( workerName )
251
250
}
252
251
if len (modelName ) > 15 {
253
252
modelName = modelName [:15 ]
254
253
}
255
254
workerName = fmt .Sprintf ("%s%s%s-%s" , prefix , hName , modelName , random )
256
255
if len (workerName ) <= maxLength {
257
- return workerName
256
+ return slug . Convert ( workerName )
258
257
}
259
258
260
259
if len (workerName ) > maxLength {
261
- return workerName [:maxLength ]
260
+ return slug . Convert ( workerName [:maxLength ])
262
261
}
263
- return workerName
262
+ return slug . Convert ( workerName )
264
263
}
0 commit comments