This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
executor.go
77 lines (64 loc) · 1.4 KB
/
executor.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
package main
/*
type ExecutionContext interface {
Nodes() NodeManager
Pods() PodManager
}
type Executor struct {
}
func CreateAction(desc ActionDescription) (Action, error) {
return nil, nil
}
func (e *Executor) Run(ctx context.Context, script ActionDescriptionList) error {
for _, desc := range script {
action, err := CreateAction(desc)
if err != nil {
return err
}
log.Printf("Starting action %s", desc.Type)
if err := action.Start(); err != nil {
return err
}
if desc.WaitForCompletion {
log.Printf("Waiting for action completion")
waitForCompletionLoop:
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(desc.Delay):
progress, err := action.CheckProgress()
if err != nil {
return err
}
if progress.IsCompleted() {
break waitForCompletionLoop
}
if progress.IsFailed() {
return errors.New("Action failed")
}
}
}
} else {
time.Sleep(desc.Delay)
}
if desc.WaitForHealth {
log.Printf("Waiting for cluster health")
timeout, cancel := context.WithTimeout(ctx, 2*time.Minute)
waitForHealthLoop:
for {
select {
case <-timeout.Done():
cancel()
return errors.Wrap(ctx.Err(), "waiting for cluster health failed")
case <-time.After(20 * time.Second):
// check cluster health
cancel()
break waitForHealthLoop
}
}
}
}
return nil
}
*/