/
context.go
57 lines (49 loc) · 1.03 KB
/
context.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 framework
import (
"flag"
"os"
"path/filepath"
"k8s.io/klog/v2"
)
var context = &E2EContext{}
type E2EContext struct {
HubKubeConfig string
TestCluster string
IsOCMInstalled bool
}
func ParseFlags() {
registerFlags()
flag.Parse()
defaultFlags()
validateFlags()
}
func registerFlags() {
flag.StringVar(&context.HubKubeConfig,
"hub-kubeconfig",
os.Getenv("KUBECONFIG"),
"Path to kubeconfig of the hub cluster.")
flag.StringVar(&context.TestCluster,
"test-cluster",
"",
"The target cluster to run the e2e suite.")
flag.BoolVar(&context.IsOCMInstalled,
"ocm-installed",
false,
"Is the test running inside OCM environment")
}
func defaultFlags() {
if len(context.HubKubeConfig) == 0 {
home := os.Getenv("HOME")
if len(home) > 0 {
context.HubKubeConfig = filepath.Join(home, ".kube", "config")
}
}
}
func validateFlags() {
if len(context.HubKubeConfig) == 0 {
klog.Fatalf("--hub-kubeconfig is required")
}
if len(context.TestCluster) == 0 {
klog.Fatalf("--test-cluster is required")
}
}