This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
launcher.go
91 lines (70 loc) · 2.38 KB
/
launcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package k8s
import (
"context"
"fmt"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/utils"
"github.com/flyteorg/flyteplugins/go/tasks/plugins/array/errorcollector"
arrayCore "github.com/flyteorg/flyteplugins/go/tasks/plugins/array/core"
errors2 "github.com/flyteorg/flytestdlib/errors"
corev1 "k8s.io/api/core/v1"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
)
const (
ErrBuildPodTemplate errors2.ErrorCode = "POD_TEMPLATE_FAILED"
ErrReplaceCmdTemplate errors2.ErrorCode = "CMD_TEMPLATE_FAILED"
ErrSubmitJob errors2.ErrorCode = "SUBMIT_JOB_FAILED"
ErrGetTaskTypeVersion errors2.ErrorCode = "GET_TASK_TYPE_VERSION_FAILED"
JobIndexVarName string = "BATCH_JOB_ARRAY_INDEX_VAR_NAME"
FlyteK8sArrayIndexVarName string = "FLYTE_K8S_ARRAY_INDEX"
)
var arrayJobEnvVars = []corev1.EnvVar{
{
Name: JobIndexVarName,
Value: FlyteK8sArrayIndexVarName,
},
}
func formatSubTaskName(_ context.Context, parentName, suffix string) (subTaskName string) {
return utils.ConvertToDNS1123SubdomainCompatibleString(fmt.Sprintf("%v-%v", parentName, suffix))
}
func ApplyPodPolicies(_ context.Context, cfg *Config, pod *corev1.Pod) *corev1.Pod {
if len(cfg.DefaultScheduler) > 0 {
pod.Spec.SchedulerName = cfg.DefaultScheduler
}
return pod
}
func applyNodeSelectorLabels(_ context.Context, cfg *Config, pod *corev1.Pod) *corev1.Pod {
if len(cfg.NodeSelector) != 0 {
pod.Spec.NodeSelector = cfg.NodeSelector
}
return pod
}
func applyPodTolerations(_ context.Context, cfg *Config, pod *corev1.Pod) *corev1.Pod {
if len(cfg.Tolerations) != 0 {
pod.Spec.Tolerations = cfg.Tolerations
}
return pod
}
func TerminateSubTasks(ctx context.Context, tCtx core.TaskExecutionContext, kubeClient core.KubeClient, config *Config,
currentState *arrayCore.State) error {
size := currentState.GetExecutionArraySize()
errs := errorcollector.NewErrorMessageCollector()
for childIdx := 0; childIdx < size; childIdx++ {
task := Task{
ChildIdx: childIdx,
Config: config,
State: currentState,
}
err := task.Abort(ctx, tCtx, kubeClient)
if err != nil {
errs.Collect(childIdx, err.Error())
}
err = task.Finalize(ctx, tCtx, kubeClient)
if err != nil {
errs.Collect(childIdx, err.Error())
}
}
if errs.Length() > 0 {
return fmt.Errorf(errs.Summary(config.MaxErrorStringLength))
}
return nil
}