@@ -20,6 +20,12 @@ export class KubernetesWorkloadManager implements WorkloadManager {
2020 private namespace = env . KUBERNETES_NAMESPACE ;
2121 private placementTagProcessor : PlacementTagProcessor ;
2222
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+
2329 constructor ( private opts : WorkloadManagerOptions ) {
2430 this . k8s = createK8sApi ( ) ;
2531 this . placementTagProcessor = new PlacementTagProcessor ( {
@@ -63,6 +69,10 @@ export class KubernetesWorkloadManager implements WorkloadManager {
6369 return imageRef . substring ( 0 , atIndex ) ;
6470 }
6571
72+ private clamp ( value : number , min : number , max : number ) : number {
73+ return Math . min ( Math . max ( value , min ) , max ) ;
74+ }
75+
6676 async create ( opts : WorkloadManagerCreateOptions ) {
6777 this . logger . log ( "[KubernetesWorkloadManager] Creating container" , { opts } ) ;
6878
@@ -295,9 +305,16 @@ export class KubernetesWorkloadManager implements WorkloadManager {
295305 }
296306
297307 #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+
298315 return {
299- cpu : `${ preset . cpu * 0.75 } ` ,
300- memory : `${ preset . memory } G` ,
316+ cpu : `${ clampedCpu } ` ,
317+ memory : `${ clampedMemory } G` ,
301318 } ;
302319 }
303320
0 commit comments