forked from flyteorg/flyteplugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformer.go
80 lines (64 loc) · 2.45 KB
/
transformer.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
package k8s
import (
"context"
core2 "github.com/lyft/flyteplugins/go/tasks/plugins/array/core"
"github.com/lyft/flytestdlib/storage"
"github.com/lyft/flyteplugins/go/tasks/pluginmachinery/io"
idlPlugins "github.com/lyft/flyteidl/gen/pb-go/flyteidl/plugins"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/lyft/flyteplugins/go/tasks/errors"
"github.com/lyft/flyteplugins/go/tasks/pluginmachinery/core"
"github.com/lyft/flyteplugins/go/tasks/pluginmachinery/flytek8s"
v1 "k8s.io/api/core/v1"
)
const PodKind = "pod"
// A proxy inputreader that overrides the inputpath to be the inputpathprefix for array jobs
type arrayJobInputReader struct {
io.InputReader
}
// We override the inputpath to return the prefix path for array jobs
func (i arrayJobInputReader) GetInputPath() storage.DataReference {
return i.GetInputPrefixPath()
}
// Note that Name is not set on the result object.
// It's up to the caller to set the Name before creating the object in K8s.
func FlyteArrayJobToK8sPodTemplate(ctx context.Context, tCtx core.TaskExecutionContext) (
podTemplate v1.Pod, job *idlPlugins.ArrayJob, err error) {
// Check that the taskTemplate is valid
taskTemplate, err := tCtx.TaskReader().Read(ctx)
if err != nil {
return v1.Pod{}, nil, err
} else if taskTemplate == nil {
return v1.Pod{}, nil, errors.Errorf(errors.BadTaskSpecification, "Required value not set, taskTemplate is nil")
}
if taskTemplate.GetContainer() == nil {
return v1.Pod{}, nil, errors.Errorf(errors.BadTaskSpecification,
"Required value not set, taskTemplate Container")
}
var arrayJob *idlPlugins.ArrayJob
if taskTemplate.GetCustom() != nil {
arrayJob, err = core2.ToArrayJob(taskTemplate.GetCustom())
if err != nil {
return v1.Pod{}, nil, err
}
}
podSpec, err := flytek8s.ToK8sPodSpec(ctx, tCtx.TaskExecutionMetadata(), tCtx.TaskReader(), arrayJobInputReader{tCtx.InputReader()},
tCtx.OutputWriter())
if err != nil {
return v1.Pod{}, nil, err
}
return v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: PodKind,
APIVersion: v1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
// Note that name is missing here
Namespace: tCtx.TaskExecutionMetadata().GetNamespace(),
Labels: tCtx.TaskExecutionMetadata().GetLabels(),
Annotations: tCtx.TaskExecutionMetadata().GetAnnotations(),
OwnerReferences: []metav1.OwnerReference{tCtx.TaskExecutionMetadata().GetOwnerReference()},
},
Spec: *podSpec,
}, arrayJob, nil
}