@@ -17,6 +17,8 @@ import {
17
17
import { PodCleaner } from "./podCleaner" ;
18
18
import { TaskMonitor } from "./taskMonitor" ;
19
19
import { UptimeHeartbeat } from "./uptimeHeartbeat" ;
20
+ import { assertExhaustive } from "@trigger.dev/core" ;
21
+ import { CustomLabelHelper } from "./labelHelper" ;
20
22
21
23
const RUNTIME_ENV = process . env . KUBERNETES_PORT ? "kubernetes" : "local" ;
22
24
const NODE_NAME = process . env . NODE_NAME || "local" ;
@@ -37,7 +39,14 @@ const UPTIME_MAX_PENDING_ERRORS = Number(process.env.UPTIME_MAX_PENDING_ERRORS |
37
39
const POD_EPHEMERAL_STORAGE_SIZE_LIMIT = process . env . POD_EPHEMERAL_STORAGE_SIZE_LIMIT || "10Gi" ;
38
40
const POD_EPHEMERAL_STORAGE_SIZE_REQUEST = process . env . POD_EPHEMERAL_STORAGE_SIZE_REQUEST || "2Gi" ;
39
41
42
+ // Image config
40
43
const 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 ;
41
50
42
51
const logger = new SimpleLogger ( `[${ NODE_NAME } ]` ) ;
43
52
logger . log ( `running in ${ RUNTIME_ENV } mode` ) ;
@@ -65,6 +74,8 @@ class KubernetesTaskOperations implements TaskOperations {
65
74
apps : k8s . AppsV1Api ;
66
75
} ;
67
76
77
+ #labelHelper = new CustomLabelHelper ( ) ;
78
+
68
79
constructor ( opts : { namespace ?: string } = { } ) {
69
80
if ( opts . namespace ) {
70
81
this . #namespace. metadata . name = opts . namespace ;
@@ -103,7 +114,7 @@ class KubernetesTaskOperations implements TaskOperations {
103
114
containers : [
104
115
{
105
116
name : this . #getIndexContainerName( opts . shortCode ) ,
106
- image : opts . imageRef ,
117
+ image : getImageRef ( "deployment" , opts . imageRef ) ,
107
118
ports : [
108
119
{
109
120
containerPort : 8000 ,
@@ -157,6 +168,7 @@ class KubernetesTaskOperations implements TaskOperations {
157
168
name : containerName ,
158
169
namespace : this . #namespace. metadata . name ,
159
170
labels : {
171
+ ...this . #labelHelper. getAdditionalLabels ( "create" ) ,
160
172
...this . #getSharedLabels( opts ) ,
161
173
app : "task-run" ,
162
174
"app.kubernetes.io/part-of" : "trigger-worker" ,
@@ -170,7 +182,7 @@ class KubernetesTaskOperations implements TaskOperations {
170
182
containers : [
171
183
{
172
184
name : containerName ,
173
- image : opts . image ,
185
+ image : getImageRef ( "deployment" , opts . image ) ,
174
186
ports : [
175
187
{
176
188
containerPort : 8000 ,
@@ -218,6 +230,7 @@ class KubernetesTaskOperations implements TaskOperations {
218
230
name : `${ this . #getRunContainerName( opts . runId ) } -${ opts . checkpointId . slice ( - 8 ) } ` ,
219
231
namespace : this . #namespace. metadata . name ,
220
232
labels : {
233
+ ...this . #labelHelper. getAdditionalLabels ( "restore" ) ,
221
234
...this . #getSharedLabels( opts ) ,
222
235
app : "task-run" ,
223
236
"app.kubernetes.io/part-of" : "trigger-worker" ,
@@ -231,12 +244,12 @@ class KubernetesTaskOperations implements TaskOperations {
231
244
initContainers : [
232
245
{
233
246
name : "pull-base-image" ,
234
- image : opts . imageRef ,
247
+ image : getImageRef ( "deployment" , opts . imageRef ) ,
235
248
command : [ "sleep" , "0" ] ,
236
249
} ,
237
250
{
238
251
name : "populate-taskinfo" ,
239
- image : "registry.digitalocean.com/trigger/busybox" ,
252
+ image : getImageRef ( "utility" , BUSYBOX_IMAGE ) ,
240
253
imagePullPolicy : "IfNotPresent" ,
241
254
command : [ "/bin/sh" , "-c" ] ,
242
255
args : [ "printenv COORDINATOR_HOST | tee /etc/taskinfo/coordinator-host" ] ,
@@ -252,7 +265,7 @@ class KubernetesTaskOperations implements TaskOperations {
252
265
containers : [
253
266
{
254
267
name : this . #getRunContainerName( opts . runId ) ,
255
- image : opts . checkpointRef ,
268
+ image : getImageRef ( "restore" , opts . checkpointRef ) ,
256
269
ports : [
257
270
{
258
271
containerPort : 8000 ,
@@ -358,7 +371,7 @@ class KubernetesTaskOperations implements TaskOperations {
358
371
initContainers : [
359
372
{
360
373
name : "prepull" ,
361
- image : opts . imageRef ,
374
+ image : getImageRef ( "deployment" , opts . imageRef ) ,
362
375
command : [ "/usr/bin/true" ] ,
363
376
resources : {
364
377
limits : {
@@ -372,7 +385,7 @@ class KubernetesTaskOperations implements TaskOperations {
372
385
containers : [
373
386
{
374
387
name : "pause" ,
375
- image : "registry.k8s.io/pause:3.9" ,
388
+ image : getImageRef ( "utility" , PAUSE_IMAGE ) ,
376
389
resources : {
377
390
limits : {
378
391
cpu : "1m" ,
@@ -403,17 +416,20 @@ class KubernetesTaskOperations implements TaskOperations {
403
416
}
404
417
405
418
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
+
406
429
return {
407
430
restartPolicy : "Never" ,
408
431
automountServiceAccountToken : false ,
409
- imagePullSecrets : [
410
- {
411
- name : "registry-trigger" ,
412
- } ,
413
- {
414
- name : "registry-trigger-failover" ,
415
- } ,
416
- ] ,
432
+ imagePullSecrets,
417
433
nodeSelector : {
418
434
nodetype : "worker" ,
419
435
} ,
@@ -673,6 +689,26 @@ class KubernetesTaskOperations implements TaskOperations {
673
689
}
674
690
}
675
691
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
+
676
712
const provider = new ProviderShell ( {
677
713
tasks : new KubernetesTaskOperations ( {
678
714
namespace : KUBERNETES_NAMESPACE ,
0 commit comments