@@ -67,7 +67,7 @@ func (w *worker) Create(ctx context.Context, job *api.CommandJob) error {
6767 logger := w .logger .With (zap .String ("uuid" , job .Uuid ))
6868 logger .Info ("creating job" )
6969 jobWrapper := NewJobWrapper (w .logger , job , w .cfg ).ParsePlugins ()
70- kjob , err := jobWrapper .Build ()
70+ kjob , err := jobWrapper .Build (false )
7171 if err != nil {
7272 kjob , err = jobWrapper .BuildFailureJob (err )
7373 if err != nil {
@@ -146,7 +146,7 @@ func (w *jobWrapper) ParsePlugins() *jobWrapper {
146146 return w
147147}
148148
149- func (w * jobWrapper ) Build () (* batchv1.Job , error ) {
149+ func (w * jobWrapper ) Build (skipCheckout bool ) (* batchv1.Job , error ) {
150150 // if previous steps have failed, error immediately
151151 if w .err != nil {
152152 return nil , w .err
@@ -231,7 +231,11 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
231231 volumeMounts := []corev1.VolumeMount {{Name : "workspace" , MountPath : "/workspace" }}
232232 volumeMounts = append (volumeMounts , w .k8sPlugin .ExtraVolumeMounts ... )
233233
234- const systemContainers = 1
234+ systemContainerCount := 0
235+ if ! skipCheckout {
236+ systemContainerCount = 1
237+ }
238+
235239 ttl := int32 (w .cfg .JobTTL .Seconds ())
236240 kjob .Spec .TTLSecondsAfterFinished = & ttl
237241
@@ -261,7 +265,7 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
261265 },
262266 corev1.EnvVar {
263267 Name : "BUILDKITE_CONTAINER_ID" ,
264- Value : strconv .Itoa (i + systemContainers ),
268+ Value : strconv .Itoa (i + systemContainerCount ),
265269 },
266270 corev1.EnvVar {
267271 Name : "BUILDKITE_PLUGINS_PATH" ,
@@ -294,7 +298,7 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
294298 podSpec .Containers [i ] = c
295299 }
296300
297- containerCount := len (podSpec .Containers ) + systemContainers
301+ containerCount := len (podSpec .Containers ) + systemContainerCount
298302
299303 for i , c := range w .k8sPlugin .Sidecars {
300304 if c .Name == "" {
@@ -366,10 +370,12 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
366370 },
367371 }
368372 agentContainer .Env = append (agentContainer .Env , env ... )
373+ podSpec .Containers = append (podSpec .Containers , agentContainer )
369374
370- checkoutContainer := w .createCheckoutContainer (kjob , env , volumeMounts )
375+ if ! skipCheckout {
376+ podSpec .Containers = append (podSpec .Containers , w .createCheckoutContainer (kjob , env , volumeMounts ))
377+ }
371378
372- podSpec .Containers = append (podSpec .Containers , agentContainer , checkoutContainer )
373379 podSpec .InitContainers = append (podSpec .InitContainers , corev1.Container {
374380 Name : "copy-agent" ,
375381 Image : w .cfg .Image ,
@@ -495,14 +501,24 @@ func (w *jobWrapper) BuildFailureJob(err error) (*batchv1.Job, error) {
495501 PodSpec : & corev1.PodSpec {
496502 Containers : []corev1.Container {
497503 {
498- Image : w .cfg .Image ,
504+ // the configured agent image may be private. If there is an error in specifying the
505+ // secrets for this image, we should still be able to run the failure job. So, we
506+ // bypass the potentially private image and use a public one. We could use a
507+ // thinner public image like `alpine:latest`, but it's generally unwise to depend
508+ // on an image that's not published by us.
509+ //
510+ // TODO: pin the version of the agent image and use that here.
511+ // Currently, DefaultAgentImage has a latest tag. That's not ideal as
512+ // a given version of agent stack-k8s may use different versions of the agent image over
513+ // time. We should consider using a specific version of the agent image here.
514+ Image : config .DefaultAgentImage ,
499515 Command : []string {fmt .Sprintf ("echo %q && exit 1" , err .Error ())},
500516 },
501517 },
502518 },
503519 }
504520 w .otherPlugins = nil
505- return w .Build ()
521+ return w .Build (true )
506522}
507523
508524func (w * jobWrapper ) labelWithAgentTags () {
0 commit comments