@@ -4,7 +4,12 @@ import {
44 type WorkloadManagerCreateOptions ,
55 type WorkloadManagerOptions ,
66} from "./types.js" ;
7- import type { EnvironmentType , MachinePreset , PlacementTag } from "@trigger.dev/core/v3" ;
7+ import type {
8+ EnvironmentType ,
9+ MachinePreset ,
10+ MachinePresetName ,
11+ PlacementTag ,
12+ } from "@trigger.dev/core/v3" ;
813import { PlacementTagProcessor } from "@trigger.dev/core/v3/serverOnly" ;
914import { env } from "../env.js" ;
1015import { type K8sApi , createK8sApi , type k8s } from "../clients/kubernetes.js" ;
@@ -14,6 +19,26 @@ type ResourceQuantities = {
1419 [ K in "cpu" | "memory" | "ephemeral-storage" ] ?: string ;
1520} ;
1621
22+ const cpuRequestRatioByMachinePreset : Record < MachinePresetName , number | undefined > = {
23+ micro : env . KUBERNETES_CPU_REQUEST_RATIO_MICRO ,
24+ "small-1x" : env . KUBERNETES_CPU_REQUEST_RATIO_SMALL_1X ,
25+ "small-2x" : env . KUBERNETES_CPU_REQUEST_RATIO_SMALL_2X ,
26+ "medium-1x" : env . KUBERNETES_CPU_REQUEST_RATIO_MEDIUM_1X ,
27+ "medium-2x" : env . KUBERNETES_CPU_REQUEST_RATIO_MEDIUM_2X ,
28+ "large-1x" : env . KUBERNETES_CPU_REQUEST_RATIO_LARGE_1X ,
29+ "large-2x" : env . KUBERNETES_CPU_REQUEST_RATIO_LARGE_2X ,
30+ } ;
31+
32+ const memoryRequestRatioByMachinePreset : Record < MachinePresetName , number | undefined > = {
33+ micro : env . KUBERNETES_MEMORY_REQUEST_RATIO_MICRO ,
34+ "small-1x" : env . KUBERNETES_MEMORY_REQUEST_RATIO_SMALL_1X ,
35+ "small-2x" : env . KUBERNETES_MEMORY_REQUEST_RATIO_SMALL_2X ,
36+ "medium-1x" : env . KUBERNETES_MEMORY_REQUEST_RATIO_MEDIUM_1X ,
37+ "medium-2x" : env . KUBERNETES_MEMORY_REQUEST_RATIO_MEDIUM_2X ,
38+ "large-1x" : env . KUBERNETES_MEMORY_REQUEST_RATIO_LARGE_1X ,
39+ "large-2x" : env . KUBERNETES_MEMORY_REQUEST_RATIO_LARGE_2X ,
40+ } ;
41+
1742export class KubernetesWorkloadManager implements WorkloadManager {
1843 private readonly logger = new SimpleStructuredLogger ( "kubernetes-workload-provider" ) ;
1944 private k8s : K8sApi ;
@@ -321,8 +346,11 @@ export class KubernetesWorkloadManager implements WorkloadManager {
321346 }
322347
323348 #getResourceRequestsForMachine( preset : MachinePreset ) : ResourceQuantities {
324- const cpuRequest = preset . cpu * this . cpuRequestRatio ;
325- const memoryRequest = preset . memory * this . memoryRequestRatio ;
349+ const cpuRatio = cpuRequestRatioByMachinePreset [ preset . name ] ?? this . cpuRequestRatio ;
350+ const memoryRatio = memoryRequestRatioByMachinePreset [ preset . name ] ?? this . memoryRequestRatio ;
351+
352+ const cpuRequest = preset . cpu * cpuRatio ;
353+ const memoryRequest = preset . memory * memoryRatio ;
326354
327355 // Clamp between min and max
328356 const clampedCpu = this . clamp ( cpuRequest , this . cpuRequestMinCores , preset . cpu ) ;
0 commit comments