-
Notifications
You must be signed in to change notification settings - Fork 14
/
cluster_setup.go
89 lines (72 loc) · 2.42 KB
/
cluster_setup.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
package infra
import (
"fmt"
"io"
"os"
"strings"
"github.com/maistra/istio-workspace/test/shell"
)
var RunsOnOpenshift = func() bool {
cmdGetDefaultServices := shell.Execute("kubectl get services -o=custom-columns='SERVICES:metadata.name' --no-headers -n default")
<-cmdGetDefaultServices.Done()
defaultServices := strings.Join(cmdGetDefaultServices.Status().Stdout, "")
return strings.Contains(defaultServices, "openshift")
}()
// UpdateSecurityConstraintsFor applies anyuid and privileged constraints to a given namespace.
func UpdateSecurityConstraintsFor(namespace string) {
shell.WaitForSuccess(
shell.Execute("oc adm policy add-scc-to-user anyuid -z default -n "+namespace),
shell.Execute("oc adm policy add-scc-to-user privileged -z default -n "+namespace),
)
}
func EnablePullingImages(namespace string) {
<-shell.Execute("oc policy add-role-to-user system:image-puller system:serviceaccount:" + namespace + ":default -n " + GetRepositoryName()).Done()
<-shell.Execute("oc policy add-role-to-user system:image-puller system:serviceaccount:" + namespace + ":istio-workspace -n " + GetRepositoryName()).Done()
}
var (
user = "admin"
pwd = "admin"
)
func LoginAsTestPowerUser() {
if ikeUser, found := os.LookupEnv("IKE_CLUSTER_USER"); found {
user = ikeUser
}
if ikePwd, found := os.LookupEnv("IKE_CLUSTER_PWD"); found {
pwd = ikePwd
}
srv := ""
if server, found := os.LookupEnv("IKE_CLUSTER_ADDRESS"); found {
srv = server
}
<-shell.ExecuteInDir(".", "oc", "login", srv, "-u", user, "-p", pwd, "--insecure-skip-tls-verify=true").Done()
}
// GetEvents returns all events which occurred for a given namespace.
func GetEvents(ns string) {
state := shell.Execute("kubectl get events -n " + ns)
<-state.Done()
}
// DumpTelepresenceLog dumps telepresence log if exists.
func DumpTelepresenceLog(dir string) {
fh, err := os.Open(dir + string(os.PathSeparator) + "telepresence.log")
if err != nil {
fmt.Println(err)
return
}
_, err = io.Copy(os.Stdout, fh)
if err != nil {
fmt.Println(err)
}
}
// UsePrebuiltImages returns true if test suite should use images that are built outside of the test execution flow.
func UsePrebuiltImages() bool {
return os.Getenv("PRE_BUILT_IMAGES") != ""
}
// PrepareEnv sets up a environmental specific things.
func PrepareEnv(namespace string) {
if RunsOnOpenshift {
UpdateSecurityConstraintsFor(namespace)
if !UsePrebuiltImages() {
EnablePullingImages(namespace)
}
}
}