@@ -17,6 +17,8 @@ import {
1717import { PodCleaner } from "./podCleaner" ;
1818import { TaskMonitor } from "./taskMonitor" ;
1919import { UptimeHeartbeat } from "./uptimeHeartbeat" ;
20+ import { assertExhaustive } from "@trigger.dev/core" ;
21+ import { CustomLabelHelper } from "./labelHelper" ;
2022
2123const RUNTIME_ENV = process . env . KUBERNETES_PORT ? "kubernetes" : "local" ;
2224const NODE_NAME = process . env . NODE_NAME || "local" ;
@@ -37,7 +39,14 @@ const UPTIME_MAX_PENDING_ERRORS = Number(process.env.UPTIME_MAX_PENDING_ERRORS |
3739const POD_EPHEMERAL_STORAGE_SIZE_LIMIT = process . env . POD_EPHEMERAL_STORAGE_SIZE_LIMIT || "10Gi" ;
3840const POD_EPHEMERAL_STORAGE_SIZE_REQUEST = process . env . POD_EPHEMERAL_STORAGE_SIZE_REQUEST || "2Gi" ;
3941
42+ // Image config
4043const PRE_PULL_DISABLED = process . env . PRE_PULL_DISABLED === "true" ;
44+ const ADDITIONAL_PULL_SECRETS = process . env . ADDITIONAL_PULL_SECRETS ;
45+ const PAUSE_IMAGE = process . env . PAUSE_IMAGE || "registry.k8s.io/pause:3.9" ;
46+ const BUSYBOX_IMAGE = process . env . BUSYBOX_IMAGE || "registry.digitalocean.com/trigger/busybox" ;
47+ const DEPLOYMENT_IMAGE_PREFIX = process . env . DEPLOYMENT_IMAGE_PREFIX ;
48+ const RESTORE_IMAGE_PREFIX = process . env . RESTORE_IMAGE_PREFIX ;
49+ const UTILITY_IMAGE_PREFIX = process . env . UTILITY_IMAGE_PREFIX ;
4150
4251const logger = new SimpleLogger ( `[${ NODE_NAME } ]` ) ;
4352logger . log ( `running in ${ RUNTIME_ENV } mode` ) ;
@@ -65,6 +74,8 @@ class KubernetesTaskOperations implements TaskOperations {
6574 apps : k8s . AppsV1Api ;
6675 } ;
6776
77+ #labelHelper = new CustomLabelHelper ( ) ;
78+
6879 constructor ( opts : { namespace ?: string } = { } ) {
6980 if ( opts . namespace ) {
7081 this . #namespace. metadata . name = opts . namespace ;
@@ -103,7 +114,7 @@ class KubernetesTaskOperations implements TaskOperations {
103114 containers : [
104115 {
105116 name : this . #getIndexContainerName( opts . shortCode ) ,
106- image : opts . imageRef ,
117+ image : getImageRef ( "deployment" , opts . imageRef ) ,
107118 ports : [
108119 {
109120 containerPort : 8000 ,
@@ -157,6 +168,7 @@ class KubernetesTaskOperations implements TaskOperations {
157168 name : containerName ,
158169 namespace : this . #namespace. metadata . name ,
159170 labels : {
171+ ...this . #labelHelper. getAdditionalLabels ( "create" ) ,
160172 ...this . #getSharedLabels( opts ) ,
161173 app : "task-run" ,
162174 "app.kubernetes.io/part-of" : "trigger-worker" ,
@@ -170,7 +182,7 @@ class KubernetesTaskOperations implements TaskOperations {
170182 containers : [
171183 {
172184 name : containerName ,
173- image : opts . image ,
185+ image : getImageRef ( "deployment" , opts . image ) ,
174186 ports : [
175187 {
176188 containerPort : 8000 ,
@@ -218,6 +230,7 @@ class KubernetesTaskOperations implements TaskOperations {
218230 name : `${ this . #getRunContainerName( opts . runId ) } -${ opts . checkpointId . slice ( - 8 ) } ` ,
219231 namespace : this . #namespace. metadata . name ,
220232 labels : {
233+ ...this . #labelHelper. getAdditionalLabels ( "restore" ) ,
221234 ...this . #getSharedLabels( opts ) ,
222235 app : "task-run" ,
223236 "app.kubernetes.io/part-of" : "trigger-worker" ,
@@ -231,12 +244,12 @@ class KubernetesTaskOperations implements TaskOperations {
231244 initContainers : [
232245 {
233246 name : "pull-base-image" ,
234- image : opts . imageRef ,
247+ image : getImageRef ( "deployment" , opts . imageRef ) ,
235248 command : [ "sleep" , "0" ] ,
236249 } ,
237250 {
238251 name : "populate-taskinfo" ,
239- image : "registry.digitalocean.com/trigger/busybox" ,
252+ image : getImageRef ( "utility" , BUSYBOX_IMAGE ) ,
240253 imagePullPolicy : "IfNotPresent" ,
241254 command : [ "/bin/sh" , "-c" ] ,
242255 args : [ "printenv COORDINATOR_HOST | tee /etc/taskinfo/coordinator-host" ] ,
@@ -252,7 +265,7 @@ class KubernetesTaskOperations implements TaskOperations {
252265 containers : [
253266 {
254267 name : this . #getRunContainerName( opts . runId ) ,
255- image : opts . checkpointRef ,
268+ image : getImageRef ( "restore" , opts . checkpointRef ) ,
256269 ports : [
257270 {
258271 containerPort : 8000 ,
@@ -358,7 +371,7 @@ class KubernetesTaskOperations implements TaskOperations {
358371 initContainers : [
359372 {
360373 name : "prepull" ,
361- image : opts . imageRef ,
374+ image : getImageRef ( "deployment" , opts . imageRef ) ,
362375 command : [ "/usr/bin/true" ] ,
363376 resources : {
364377 limits : {
@@ -372,7 +385,7 @@ class KubernetesTaskOperations implements TaskOperations {
372385 containers : [
373386 {
374387 name : "pause" ,
375- image : "registry.k8s.io/pause:3.9" ,
388+ image : getImageRef ( "utility" , PAUSE_IMAGE ) ,
376389 resources : {
377390 limits : {
378391 cpu : "1m" ,
@@ -403,17 +416,20 @@ class KubernetesTaskOperations implements TaskOperations {
403416 }
404417
405418 get #defaultPodSpec( ) : Omit < k8s . V1PodSpec , "containers" > {
419+ const pullSecrets = [ "registry-trigger" , "registry-trigger-failover" ] ;
420+
421+ if ( ADDITIONAL_PULL_SECRETS ) {
422+ pullSecrets . push ( ...ADDITIONAL_PULL_SECRETS . split ( "," ) ) ;
423+ }
424+
425+ const imagePullSecrets = pullSecrets . map (
426+ ( name ) => ( { name } ) satisfies k8s . V1LocalObjectReference
427+ ) ;
428+
406429 return {
407430 restartPolicy : "Never" ,
408431 automountServiceAccountToken : false ,
409- imagePullSecrets : [
410- {
411- name : "registry-trigger" ,
412- } ,
413- {
414- name : "registry-trigger-failover" ,
415- } ,
416- ] ,
432+ imagePullSecrets,
417433 nodeSelector : {
418434 nodetype : "worker" ,
419435 } ,
@@ -673,6 +689,26 @@ class KubernetesTaskOperations implements TaskOperations {
673689 }
674690}
675691
692+ type ImageType = "deployment" | "restore" | "utility" ;
693+
694+ function getImagePrefix ( type : ImageType ) {
695+ switch ( type ) {
696+ case "deployment" :
697+ return DEPLOYMENT_IMAGE_PREFIX ;
698+ case "restore" :
699+ return RESTORE_IMAGE_PREFIX ;
700+ case "utility" :
701+ return UTILITY_IMAGE_PREFIX ;
702+ default :
703+ assertExhaustive ( type ) ;
704+ }
705+ }
706+
707+ function getImageRef ( type : ImageType , ref : string ) {
708+ const prefix = getImagePrefix ( type ) ;
709+ return prefix ? `${ prefix } /${ ref } ` : ref ;
710+ }
711+
676712const provider = new ProviderShell ( {
677713 tasks : new KubernetesTaskOperations ( {
678714 namespace : KUBERNETES_NAMESPACE ,
0 commit comments