forked from rh-messaging/shipshape
/
skupperoperator.go
128 lines (102 loc) · 2.74 KB
/
skupperoperator.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package operators
import (
"context"
"os"
"os/exec"
)
// SkupperOperatorBuilder helps building a skupper operator that uses
// the CLI skupper. Once the API is available
// we can create a second skupper operator to
// test both api and cli.
type SkupperOperatorBuilder struct {
BaseOperatorBuilder
skupper SkupperOperator
}
func (b *SkupperOperatorBuilder) SkupperId(id string) {
b.skupper.Id = id
}
func (b *SkupperOperatorBuilder) ClusterLocal(local bool) {
b.skupper.ClusterLocal = local
}
func (b *SkupperOperatorBuilder) WithSkupperPath(path string) {
b.skupper.SkupperPath = path
}
func (s *SkupperOperatorBuilder) OperatorType() OperatorType {
return OperatorTypeSkupper
}
//
// Future use
//
func (b *SkupperOperatorBuilder) WithQdrouterdImage(image string) {
b.skupper.QdrouterdImage = image
}
func (b *SkupperOperatorBuilder) WithControllerImage(image string) {
b.skupper.ControllerImage = image
}
func (b *SkupperOperatorBuilder) WithProxyImage(image string) {
b.skupper.ProxyImage = image
}
//
// END OF - Future use
//
func (b *SkupperOperatorBuilder) Build() (OperatorSetup, error) {
if err := b.skupper.InitFromBaseOperatorBuilder(&b.BaseOperatorBuilder); err != nil {
return &b.skupper, err
}
b.skupper.restConfig = b.restConfig
b.skupper.rawConfig = b.rawConfig
// This is set when running shipshape cluster test
if os.Getenv("OPERATOR_TESTING") != "" {
b.ClusterLocal(true)
}
return &b.skupper, nil
}
type SkupperOperator struct {
BaseOperator
ClusterLocal bool
Id string
QdrouterdImage string
ControllerImage string
ProxyImage string
SkupperPath string
}
func (s *SkupperOperator) SkupperBin() string {
return s.SkupperPath + "skupper"
}
func (s *SkupperOperator) Name() string {
return s.operatorName
}
func (s *SkupperOperator) Setup() error {
// run skupper init with provided flags from builder
cmdCtx := context.TODO()
// Building args list
args := []string{
"init",
}
if s.ClusterLocal {
args = append(args, "--cluster-local")
}
// Using provided context
args = append(args, "--namespace", s.namespace)
args = append(args, "--context", s.rawConfig.CurrentContext)
cmd := exec.CommandContext(cmdCtx, s.SkupperBin(), args...)
err := cmd.Start()
return err
}
func (s *SkupperOperator) TeardownEach() error {
return nil
}
func (s *SkupperOperator) TeardownSuite() error {
// run skupper delete
cmdCtx := context.TODO()
// Building args list
args := []string{
"delete",
}
// Using provided context
args = append(args, "--namespace", s.namespace)
args = append(args, "--context", s.rawConfig.CurrentContext)
cmd := exec.CommandContext(cmdCtx, s.SkupperBin(), args...)
err := cmd.Start()
return err
}