/
deploy-rook.go
150 lines (128 loc) · 4.21 KB
/
deploy-rook.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package e2e
import (
"fmt"
"strings"
"time"
. "github.com/onsi/gomega" // nolint
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
)
var (
rookURL = "https://raw.githubusercontent.com/rook/rook/$version/cluster/examples/kubernetes/ceph"
)
var rookNS = "rook-ceph"
func formRookURL(version string) {
rookURL = strings.Replace(rookURL, "$version", version, 1)
}
func getK8sClient() kubernetes.Interface {
e2elog.Logf("Creating a kubernetes client")
client, err := framework.LoadClientset()
Expect(err).Should(BeNil())
return client
}
func deployCommon() {
commonPath := fmt.Sprintf("%s/%s", rookURL, "common.yaml")
framework.RunKubectlOrDie("create", "-f", commonPath)
}
func createFileSystem(c kubernetes.Interface) {
commonPath := fmt.Sprintf("%s/%s", rookURL, "filesystem-test.yaml")
framework.RunKubectlOrDie("create", "-f", commonPath)
opt := &metav1.ListOptions{
LabelSelector: "app=rook-ceph-mds",
}
err := checkCephPods(rookNS, c, 1, deployTimeout, opt)
Expect(err).Should(BeNil())
}
func createRBDPool() {
commonPath := fmt.Sprintf("%s/%s", rookURL, "pool-test.yaml")
framework.RunKubectlOrDie("create", "-f", commonPath)
}
func deleteFileSystem() {
commonPath := fmt.Sprintf("%s/%s", rookURL, "filesystem-test.yaml")
_, err := framework.RunKubectl("delete", "-f", commonPath)
if err != nil {
e2elog.Logf("failed to delete file-system %v", err)
}
}
func deleteRBDPool() {
commonPath := fmt.Sprintf("%s/%s", rookURL, "pool-test.yaml")
_, err := framework.RunKubectl("delete", "-f", commonPath)
if err != nil {
e2elog.Logf("failed to delete pool %v", err)
}
}
func deployOperator(c kubernetes.Interface) {
opPath := fmt.Sprintf("%s/%s", rookURL, "operator.yaml")
_, err := framework.RunKubectl("create", "-f", opPath)
Expect(err).Should(BeNil())
err = waitForDaemonSets("rook-discover", rookNS, c, deployTimeout)
Expect(err).Should(BeNil())
err = waitForDeploymentComplete("rook-ceph-operator", rookNS, c, deployTimeout)
Expect(err).Should(BeNil())
}
func deployCluster(c kubernetes.Interface) {
opPath := fmt.Sprintf("%s/%s", rookURL, "cluster-test.yaml")
framework.RunKubectlOrDie("create", "-f", opPath)
err := waitForDaemonSets("rook-ceph-agent", rookNS, c, deployTimeout)
Expect(err).Should(BeNil())
opt := &metav1.ListOptions{
LabelSelector: "app=rook-ceph-mon",
}
err = checkCephPods(rookNS, c, 1, deployTimeout, opt)
Expect(err).Should(BeNil())
}
func deployToolBox(c kubernetes.Interface) {
opPath := fmt.Sprintf("%s/%s", rookURL, "toolbox.yaml")
framework.RunKubectlOrDie("create", "-f", opPath)
opt := &metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools",
}
name := getPodName(rookNS, c, opt)
err := waitForPodInRunningState(name, rookNS, c, deployTimeout)
Expect(err).Should(BeNil())
waitforToolBoX(name)
}
// this is a workaround, as we are hitting "unable to get monitor info from DNS SRV with service name: ceph-mon"
func waitforToolBoX(name string) {
cmd := []string{"logs", "-nrook-ceph", name}
for i := 0; i < 20; i++ {
resp, err := framework.RunKubectl(cmd...)
if err != nil {
e2elog.Logf("failed to get logs %v", err)
continue
}
if !strings.Contains(resp, "=") {
e2elog.Logf("malformed monitor configuration %+v", resp)
time.Sleep(10 * time.Second)
continue
}
if strings.TrimRight(resp[strings.LastIndex(resp, "=")+1:], "\n") != "" {
break
}
e2elog.Logf("monitor list is empty in ceph.conf %v", resp)
time.Sleep(10 * time.Second)
}
}
func deployRook() {
c := getK8sClient()
deployCommon()
deployOperator(c)
deployCluster(c)
deployToolBox(c)
}
func tearDownRook() {
opPath := fmt.Sprintf("%s/%s", rookURL, "cluster-test.yaml")
framework.Cleanup(opPath, rookNS, "app=rook-ceph-mon")
opPath = fmt.Sprintf("%s/%s", rookURL, "toolbox.yaml")
framework.Cleanup(opPath, rookNS, "app=rook-ceph-tools")
opPath = fmt.Sprintf("%s/%s", rookURL, "operator.yaml")
// TODO need to add selector for cleanup validation
framework.Cleanup(opPath, rookNS)
commonPath := fmt.Sprintf("%s/%s", rookURL, "common.yaml")
_, err := framework.RunKubectl("delete", "-f", commonPath)
if err != nil {
e2elog.Logf("failed to delete rook common %v", err)
}
}