@@ -8,9 +8,10 @@ import (
88 "strings"
99 "time"
1010
11+ "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s"
12+
1113 "github.com/flyteorg/flyteplugins/go/tasks/errors"
1214 pluginsCore "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
13- "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s"
1415 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s/config"
1516 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/k8s"
1617 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/tasklog"
@@ -159,6 +160,20 @@ func clearFinalizers(ctx context.Context, o client.Object, kubeClient pluginsCor
159160 return nil
160161}
161162
163+ // updateCopilotArgs append array index to the end of the output prefix
164+ func updateCopilotArgs (pod * v1.Pod , stCtx SubTaskExecutionContext ) {
165+ for sidecarIndex , container := range pod .Spec .Containers {
166+ if container .Name == config .GetK8sPluginConfig ().CoPilot .NamePrefix + flytek8s .Sidecar {
167+ for i , arg := range pod .Spec .Containers [sidecarIndex ].Args {
168+ if arg == "--to-output-prefix" {
169+ pod .Spec .Containers [sidecarIndex ].Args [i + 1 ] = fmt .Sprintf ("%s/%s" , pod .Spec .Containers [sidecarIndex ].Args [i + 1 ], strconv .Itoa (stCtx .originalIndex ))
170+ }
171+ }
172+ break
173+ }
174+ }
175+ }
176+
162177// launchSubtask creates a k8s pod defined by the SubTaskExecutionContext and Config.
163178func launchSubtask (ctx context.Context , stCtx SubTaskExecutionContext , cfg * Config , kubeClient pluginsCore.KubeClient ) (pluginsCore.PhaseInfo , error ) {
164179 o , err := podPlugin .DefaultPodPlugin .BuildResource (ctx , stCtx )
@@ -187,6 +202,7 @@ func launchSubtask(ctx context.Context, stCtx SubTaskExecutionContext, cfg *Conf
187202 })
188203
189204 pod .Spec .Containers [containerIndex ].Env = append (pod .Spec .Containers [containerIndex ].Env , arrayJobEnvVars ... )
205+ updateCopilotArgs (pod , stCtx )
190206
191207 logger .Infof (ctx , "Creating Object: Type:[%v], Object:[%v/%v]" , pod .GetObjectKind ().GroupVersionKind (), pod .GetNamespace (), pod .GetName ())
192208 err = kubeClient .GetClient ().Create (ctx , pod )
@@ -330,6 +346,10 @@ func getTaskContainerIndex(pod *v1.Pod) (int, error) {
330346 if len (pod .Spec .Containers ) == 1 {
331347 return 0 , nil
332348 }
349+ // Copilot is always the second container if it is enabled.
350+ if len (pod .Spec .Containers ) == 2 && pod .Spec .Containers [1 ].Name == config .GetK8sPluginConfig ().CoPilot .NamePrefix + flytek8s .Sidecar {
351+ return 0 , nil
352+ }
333353 // For tasks with a K8sPod task target, they may produce multiple containers but at least one must be the designated primary.
334354 return - 1 , stdErrors .Errorf (ErrBuildPodTemplate , "Expected a specified primary container key when building an array job with a K8sPod spec target" )
335355
0 commit comments