@@ -183,7 +183,15 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery
183
183
logJob = fmt .Sprintf ("for workflow job %d," , spawnArgs .JobID )
184
184
}
185
185
186
+ cpu := h .Config .DefaultCPU
187
+ if cpu == "" {
188
+ cpu = "500m"
189
+ }
190
+
186
191
memory := int64 (h .Config .DefaultMemory )
192
+ if memory == 0 {
193
+ memory = 1024
194
+ }
187
195
for _ , r := range spawnArgs .Requirements {
188
196
if r .Type == sdk .MemoryRequirement {
189
197
var err error
@@ -192,9 +200,15 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery
192
200
log .Warn (ctx , "spawnKubernetesDockerWorker> %s unable to parse memory requirement %d: %v" , logJob , memory , err )
193
201
return err
194
202
}
203
+ break
195
204
}
196
205
}
197
206
207
+ ephemeralStorage := h .Config .DefaultEphemeralStorage
208
+ if ephemeralStorage == "" {
209
+ ephemeralStorage = "1Gi"
210
+ }
211
+
198
212
workerConfig := h .GenerateWorkerConfig (ctx , h , spawnArgs )
199
213
udataParam := struct {
200
214
API string
@@ -283,7 +297,14 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery
283
297
Args : []string {cmd },
284
298
Resources : apiv1.ResourceRequirements {
285
299
Requests : apiv1.ResourceList {
286
- apiv1 .ResourceMemory : resource .MustParse (fmt .Sprintf ("%d" , memory )),
300
+ apiv1 .ResourceCPU : resource .MustParse (cpu ),
301
+ apiv1 .ResourceMemory : * resource .NewScaledQuantity (memory , resource .Mega ),
302
+ apiv1 .ResourceEphemeralStorage : resource .MustParse (ephemeralStorage ),
303
+ },
304
+ Limits : apiv1.ResourceList {
305
+ apiv1 .ResourceCPU : resource .MustParse (cpu ),
306
+ apiv1 .ResourceMemory : * resource .NewScaledQuantity (memory , resource .Mega ),
307
+ apiv1 .ResourceEphemeralStorage : resource .MustParse (ephemeralStorage ),
287
308
},
288
309
},
289
310
},
@@ -313,28 +334,51 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery
313
334
podSchema .Spec .HostAliases [0 ].Hostnames [0 ] = "worker"
314
335
}
315
336
337
+ serviceCPU := h .Config .DefaultServiceCPU
338
+ if serviceCPU == "" {
339
+ serviceCPU = "256m"
340
+ }
341
+
342
+ serviceMemory := int64 (h .Config .DefaultServiceMemory )
343
+ if serviceMemory == 0 {
344
+ serviceMemory = 512
345
+ }
346
+
347
+ serviceEphemeralStorage := h .Config .DefaultServiceEphemeralStorage
348
+ if serviceEphemeralStorage == "" {
349
+ serviceEphemeralStorage = "512Mi"
350
+ }
351
+
316
352
for i , serv := range services {
317
353
//name= <alias> => the name of the host put in /etc/hosts of the worker
318
354
//value= "postgres:latest env_1=blabla env_2=blabla"" => we can add env variables in requirement name
319
355
img , envm := hatchery .ParseRequirementModel (serv .Value )
320
356
321
- servContainer := apiv1.Container {
322
- Name : fmt .Sprintf ("service-%d-%s" , serv .ID , strings .ToLower (serv .Name )),
323
- Image : img ,
324
- }
325
-
326
357
if sm , ok := envm ["CDS_SERVICE_MEMORY" ]; ok {
327
- mq , err := resource .ParseQuantity (sm )
358
+ var err error
359
+ serviceMemory , err = strconv .ParseInt (sm , 10 , 64 )
328
360
if err != nil {
329
361
log .Warn (ctx , "hatchery> kubernetes> SpawnWorker> Unable to parse CDS_SERVICE_MEMORY value '%s': %s" , sm , err )
330
362
continue
331
363
}
332
- servContainer .Resources = apiv1.ResourceRequirements {
364
+ delete (envm , "CDS_SERVICE_MEMORY" )
365
+ }
366
+
367
+ servContainer := apiv1.Container {
368
+ Name : fmt .Sprintf ("service-%d-%s" , serv .ID , strings .ToLower (serv .Name )),
369
+ Image : img ,
370
+ Resources : apiv1.ResourceRequirements {
333
371
Requests : apiv1.ResourceList {
334
- apiv1 .ResourceMemory : mq ,
372
+ apiv1 .ResourceCPU : resource .MustParse (serviceCPU ),
373
+ apiv1 .ResourceMemory : * resource .NewScaledQuantity (serviceMemory , resource .Mega ),
374
+ apiv1 .ResourceEphemeralStorage : resource .MustParse (serviceEphemeralStorage ),
335
375
},
336
- }
337
- delete (envm , "CDS_SERVICE_MEMORY" )
376
+ Limits : apiv1.ResourceList {
377
+ apiv1 .ResourceCPU : resource .MustParse (serviceCPU ),
378
+ apiv1 .ResourceMemory : * resource .NewScaledQuantity (serviceMemory , resource .Mega ),
379
+ apiv1 .ResourceEphemeralStorage : resource .MustParse (serviceEphemeralStorage ),
380
+ },
381
+ },
338
382
}
339
383
340
384
if sa , ok := envm ["CDS_SERVICE_ARGS" ]; ok {
0 commit comments