-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait.go
57 lines (51 loc) · 1.34 KB
/
wait.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
package main
import (
"context"
"sync"
"k8s.io/client-go/kubernetes"
)
func wait(ctx context.Context, clientset kubernetes.Interface, descriptions []StateDescription) {
for _, description := range descriptions {
validator, ok := getValidator(clientset, description)
if !ok {
panic("could not find validator for resource type " + description.Type)
}
if err := validator.Validate(ctx, description); err != nil {
panic("description not valid: " + err.Error())
}
}
var wg sync.WaitGroup
for _, description := range descriptions {
matcher, ok := getMatcher(clientset, description)
if !ok {
panic("could not find matcher for resource type " + description.Type)
}
wg.Add(1)
go func() {
defer wg.Done()
err := matcher.Start(ctx)
if err != nil {
panic(err)
}
}()
}
wg.Wait()
}
func getValidator(clientset kubernetes.Interface, description StateDescription) (Validator, bool) {
switch description.Type {
case PodResource:
return NewPodValidator(), true
case JobResource:
return NewJobValidator(), true
}
return nil, false
}
func getMatcher(clientset kubernetes.Interface, description StateDescription) (Matcher, bool) {
switch description.Type {
case PodResource:
return NewPodMatcher(clientset, description), true
case JobResource:
return NewJobMatcher(clientset, description), true
}
return nil, false
}