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 59
/
task_exec_context.go
66 lines (55 loc) · 2.24 KB
/
task_exec_context.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
package k8s
import (
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
pluginsCore "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/utils"
"github.com/flyteorg/flytepropeller/pkg/utils/secrets"
)
// TaskExecutionContext provides a layer on top of core TaskExecutionContext with a custom TaskExecutionMetadata.
type TaskExecutionContext struct {
pluginsCore.TaskExecutionContext
metadataOverride pluginsCore.TaskExecutionMetadata
}
func (t TaskExecutionContext) TaskExecutionMetadata() pluginsCore.TaskExecutionMetadata {
return t.metadataOverride
}
func newTaskExecutionContext(tCtx pluginsCore.TaskExecutionContext, metadataOverride pluginsCore.TaskExecutionMetadata) TaskExecutionContext {
return TaskExecutionContext{
TaskExecutionContext: tCtx,
metadataOverride: metadataOverride,
}
}
// TaskExecutionMetadata provides a layer on top of the core TaskExecutionMetadata with customized annotations and labels
// for k8s plugins.
type TaskExecutionMetadata struct {
pluginsCore.TaskExecutionMetadata
annotations map[string]string
labels map[string]string
}
func (t TaskExecutionMetadata) GetLabels() map[string]string {
return t.labels
}
func (t TaskExecutionMetadata) GetAnnotations() map[string]string {
return t.annotations
}
// newTaskExecutionMetadata creates a TaskExecutionMetadata with secrets serialized as annotations and a label added
// to trigger the flyte pod webhook
func newTaskExecutionMetadata(tCtx pluginsCore.TaskExecutionMetadata, taskTmpl *core.TaskTemplate) (TaskExecutionMetadata, error) {
var err error
secretsMap := make(map[string]string)
injectSecretsLabel := make(map[string]string)
if taskTmpl.SecurityContext != nil && len(taskTmpl.SecurityContext.Secrets) > 0 {
secretsMap, err = secrets.MarshalSecretsToMapStrings(taskTmpl.SecurityContext.Secrets)
if err != nil {
return TaskExecutionMetadata{}, err
}
injectSecretsLabel = map[string]string{
secrets.PodLabel: secrets.PodLabelValue,
}
}
return TaskExecutionMetadata{
TaskExecutionMetadata: tCtx,
annotations: utils.UnionMaps(tCtx.GetAnnotations(), secretsMap),
labels: utils.UnionMaps(tCtx.GetLabels(), injectSecretsLabel),
}, nil
}