-
Notifications
You must be signed in to change notification settings - Fork 458
/
controller.go
64 lines (51 loc) · 1.72 KB
/
controller.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package runtime
import (
"context"
"log"
"github.com/cosi-project/runtime/pkg/controller"
)
// TaskSetupFunc defines the function that a task will execute for a specific runtime
// mode.
type TaskSetupFunc func(seq Sequence, data any) (TaskExecutionFunc, string)
// TaskExecutionFunc defines the function that a task will execute for a specific runtime
// mode.
type TaskExecutionFunc func(context.Context, *log.Logger, Runtime) error
// Phase represents a collection of tasks to be performed concurrently.
type Phase struct {
Name string
Tasks []TaskSetupFunc
CheckFunc func() bool
}
// LockOptions represents the options for a controller.
type LockOptions struct {
Takeover bool
}
// LockOption represents an option setter.
type LockOption func(o *LockOptions) error
// WithTakeover sets the take option to true.
func WithTakeover() LockOption {
return func(o *LockOptions) error {
o.Takeover = true
return nil
}
}
// DefaultControllerOptions returns the default controller options.
func DefaultControllerOptions() LockOptions {
return LockOptions{}
}
// Controller represents the controller responsible for managing the execution
// of sequences.
type Controller interface {
Runtime() Runtime
Sequencer() Sequencer
Run(context.Context, Sequence, interface{}, ...LockOption) error
V1Alpha2() V1Alpha2Controller
}
// V1Alpha2Controller provides glue into v2alpha1 controller runtime.
type V1Alpha2Controller interface {
Run(context.Context, *Drainer) error
DependencyGraph() (*controller.DependencyGraph, error)
}