@@ -8,9 +8,10 @@ import (
8
8
"strings"
9
9
"time"
10
10
11
+ "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s"
12
+
11
13
"github.com/flyteorg/flyteplugins/go/tasks/errors"
12
14
pluginsCore "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
13
- "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s"
14
15
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s/config"
15
16
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/k8s"
16
17
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/tasklog"
@@ -159,6 +160,20 @@ func clearFinalizers(ctx context.Context, o client.Object, kubeClient pluginsCor
159
160
return nil
160
161
}
161
162
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
+
162
177
// launchSubtask creates a k8s pod defined by the SubTaskExecutionContext and Config.
163
178
func launchSubtask (ctx context.Context , stCtx SubTaskExecutionContext , cfg * Config , kubeClient pluginsCore.KubeClient ) (pluginsCore.PhaseInfo , error ) {
164
179
o , err := podPlugin .DefaultPodPlugin .BuildResource (ctx , stCtx )
@@ -187,6 +202,7 @@ func launchSubtask(ctx context.Context, stCtx SubTaskExecutionContext, cfg *Conf
187
202
})
188
203
189
204
pod .Spec .Containers [containerIndex ].Env = append (pod .Spec .Containers [containerIndex ].Env , arrayJobEnvVars ... )
205
+ updateCopilotArgs (pod , stCtx )
190
206
191
207
logger .Infof (ctx , "Creating Object: Type:[%v], Object:[%v/%v]" , pod .GetObjectKind ().GroupVersionKind (), pod .GetNamespace (), pod .GetName ())
192
208
err = kubeClient .GetClient ().Create (ctx , pod )
@@ -330,6 +346,10 @@ func getTaskContainerIndex(pod *v1.Pod) (int, error) {
330
346
if len (pod .Spec .Containers ) == 1 {
331
347
return 0 , nil
332
348
}
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
+ }
333
353
// For tasks with a K8sPod task target, they may produce multiple containers but at least one must be the designated primary.
334
354
return - 1 , stdErrors .Errorf (ErrBuildPodTemplate , "Expected a specified primary container key when building an array job with a K8sPod spec target" )
335
355
0 commit comments