@@ -13,13 +13,22 @@ type ResourceQuantities = {
1313 [ K in "cpu" | "memory" | "ephemeral-storage" ] ?: string ;
1414} ;
1515
16+ interface TierConfig {
17+ enabled : boolean ;
18+ labelKey : string ;
19+ freeValue : string ;
20+ paidValue : string ;
21+ }
22+
1623export class KubernetesWorkloadManager implements WorkloadManager {
1724 private readonly logger = new SimpleStructuredLogger ( "kubernetes-workload-provider" ) ;
1825 private k8s : K8sApi ;
1926 private namespace = env . KUBERNETES_NAMESPACE ;
27+ private tierConfig : TierConfig ;
2028
2129 constructor ( private opts : WorkloadManagerOptions ) {
2230 this . k8s = createK8sApi ( ) ;
31+ this . tierConfig = this . tierSchedulingConfig ;
2332
2433 if ( opts . workloadApiDomain ) {
2534 this . logger . warn ( "[KubernetesWorkloadManager] ⚠️ Custom workload API domain" , {
@@ -28,6 +37,34 @@ export class KubernetesWorkloadManager implements WorkloadManager {
2837 }
2938 }
3039
40+ private get tierSchedulingConfig ( ) : TierConfig {
41+ return {
42+ enabled : env . ENABLE_TIER_SCHEDULING ,
43+ labelKey : env . TIER_LABEL_KEY ,
44+ freeValue : env . TIER_LABEL_VALUE_FREE ,
45+ paidValue : env . TIER_LABEL_VALUE_PAID ,
46+ } ;
47+ }
48+
49+ private addTierScheduling (
50+ podSpec : Omit < k8s . V1PodSpec , "containers" > ,
51+ isPaidTier : boolean
52+ ) : Omit < k8s . V1PodSpec , "containers" > {
53+ if ( ! this . tierConfig . enabled ) {
54+ return podSpec ;
55+ }
56+
57+ const labelValue = isPaidTier ? this . tierConfig . paidValue : this . tierConfig . freeValue ;
58+
59+ return {
60+ ...podSpec ,
61+ nodeSelector : {
62+ ...podSpec . nodeSelector ,
63+ [ this . tierConfig . labelKey ] : labelValue ,
64+ } ,
65+ } ;
66+ }
67+
3168 async create ( opts : WorkloadManagerCreateOptions ) {
3269 this . logger . log ( "[KubernetesWorkloadManager] Creating container" , { opts } ) ;
3370
@@ -48,7 +85,7 @@ export class KubernetesWorkloadManager implements WorkloadManager {
4885 } ,
4986 } ,
5087 spec : {
51- ...this . #defaultPodSpec,
88+ ...this . addTierScheduling ( this . #defaultPodSpec, opts . isPaidTier ?? false ) ,
5289 terminationGracePeriodSeconds : 60 * 60 ,
5390 containers : [
5491 {
0 commit comments