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
/
handler_factory.go
72 lines (57 loc) · 2.26 KB
/
handler_factory.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
package nodes
import (
"context"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/catalog"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/dynamic"
"github.com/flyteorg/flytestdlib/promutils"
"github.com/pkg/errors"
"github.com/flyteorg/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
"github.com/flyteorg/flytepropeller/pkg/controller/executors"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/branch"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/end"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/handler"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/start"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/subworkflow"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/subworkflow/launchplan"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/task"
)
//go:generate mockery -name HandlerFactory -case=underscore
type HandlerFactory interface {
GetHandler(kind v1alpha1.NodeKind) (handler.Node, error)
Setup(ctx context.Context, setup handler.SetupContext) error
}
type handlerFactory struct {
handlers map[v1alpha1.NodeKind]handler.Node
}
func (f handlerFactory) GetHandler(kind v1alpha1.NodeKind) (handler.Node, error) {
h, ok := f.handlers[kind]
if !ok {
return nil, errors.Errorf("Handler not registered for NodeKind [%v]", kind)
}
return h, nil
}
func (f handlerFactory) Setup(ctx context.Context, setup handler.SetupContext) error {
for _, v := range f.handlers {
if err := v.Setup(ctx, setup); err != nil {
return err
}
}
return nil
}
func NewHandlerFactory(ctx context.Context, executor executors.Node, workflowLauncher launchplan.Executor,
launchPlanReader launchplan.Reader, kubeClient executors.Client, client catalog.Client, scope promutils.Scope) (HandlerFactory, error) {
t, err := task.New(ctx, kubeClient, client, scope)
if err != nil {
return nil, err
}
f := &handlerFactory{
handlers: map[v1alpha1.NodeKind]handler.Node{
v1alpha1.NodeKindBranch: branch.New(executor, scope),
v1alpha1.NodeKindTask: dynamic.New(t, executor, launchPlanReader, scope),
v1alpha1.NodeKindWorkflow: subworkflow.New(executor, workflowLauncher, scope),
v1alpha1.NodeKindStart: start.New(),
v1alpha1.NodeKindEnd: end.New(),
},
}
return f, nil
}