@@ -20,6 +20,12 @@ export class KubernetesWorkloadManager implements WorkloadManager {
20
20
private namespace = env . KUBERNETES_NAMESPACE ;
21
21
private placementTagProcessor : PlacementTagProcessor ;
22
22
23
+ // Resource settings
24
+ private readonly cpuRequestMinCores = env . KUBERNETES_CPU_REQUEST_MIN_CORES ;
25
+ private readonly cpuRequestRatio = env . KUBERNETES_CPU_REQUEST_RATIO ;
26
+ private readonly memoryRequestMinGb = env . KUBERNETES_MEMORY_REQUEST_MIN_GB ;
27
+ private readonly memoryRequestRatio = env . KUBERNETES_MEMORY_REQUEST_RATIO ;
28
+
23
29
constructor ( private opts : WorkloadManagerOptions ) {
24
30
this . k8s = createK8sApi ( ) ;
25
31
this . placementTagProcessor = new PlacementTagProcessor ( {
@@ -63,6 +69,10 @@ export class KubernetesWorkloadManager implements WorkloadManager {
63
69
return imageRef . substring ( 0 , atIndex ) ;
64
70
}
65
71
72
+ private clamp ( value : number , min : number , max : number ) : number {
73
+ return Math . min ( Math . max ( value , min ) , max ) ;
74
+ }
75
+
66
76
async create ( opts : WorkloadManagerCreateOptions ) {
67
77
this . logger . log ( "[KubernetesWorkloadManager] Creating container" , { opts } ) ;
68
78
@@ -295,9 +305,16 @@ export class KubernetesWorkloadManager implements WorkloadManager {
295
305
}
296
306
297
307
#getResourceRequestsForMachine( preset : MachinePreset ) : ResourceQuantities {
308
+ const cpuRequest = preset . cpu * this . cpuRequestRatio ;
309
+ const memoryRequest = preset . memory * this . memoryRequestRatio ;
310
+
311
+ // Clamp between min and max
312
+ const clampedCpu = this . clamp ( cpuRequest , this . cpuRequestMinCores , preset . cpu ) ;
313
+ const clampedMemory = this . clamp ( memoryRequest , this . memoryRequestMinGb , preset . memory ) ;
314
+
298
315
return {
299
- cpu : `${ preset . cpu * 0.75 } ` ,
300
- memory : `${ preset . memory } G` ,
316
+ cpu : `${ clampedCpu } ` ,
317
+ memory : `${ clampedMemory } G` ,
301
318
} ;
302
319
}
303
320
0 commit comments