-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
ceph_helm_installer.go
298 lines (265 loc) · 10.7 KB
/
ceph_helm_installer.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
Copyright 2021 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package installer
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
kerrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
OperatorChartName = "rook-ceph"
CephClusterChartName = "rook-ceph-cluster"
)
// The Ceph Storage CustomResource and StorageClass names used in testing
const (
BlockPoolName = "ceph-block-test"
BlockPoolSCName = "ceph-block-test-sc"
FilesystemName = "ceph-filesystem-test"
FilesystemSCName = "ceph-filesystem-test-sc"
ObjectStoreName = "ceph-objectstore-test"
ObjectStoreSCName = "ceph-bucket-test-sc"
)
// CreateRookOperatorViaHelm creates rook operator via Helm chart named local/rook present in local repo
func (h *CephInstaller) CreateRookOperatorViaHelm() error {
return h.configureRookOperatorViaHelm(false)
}
func (h *CephInstaller) UpgradeRookOperatorViaHelm() error {
return h.configureRookOperatorViaHelm(true)
}
func (h *CephInstaller) configureRookOperatorViaHelm(upgrade bool) error {
values := map[string]interface{}{
"enableDiscoveryDaemon": h.settings.EnableDiscovery,
"image": map[string]interface{}{"tag": h.settings.RookVersion},
}
// create the operator namespace before the admission controller is created
if err := h.k8shelper.CreateNamespace(h.settings.OperatorNamespace); err != nil {
return errors.Errorf("failed to create namespace %s. %v", h.settings.Namespace, err)
}
if err := h.startAdmissionController(); err != nil {
return errors.Errorf("failed to start admission controllers. %v", err)
}
if h.settings.RookVersion == LocalBuildTag {
if err := h.helmHelper.InstallLocalHelmChart(upgrade, h.settings.OperatorNamespace, OperatorChartName, values); err != nil {
return errors.Errorf("failed to install rook operator via helm, err : %v", err)
}
} else {
// Install a specific version of the chart, from which the test will upgrade later
if err := h.helmHelper.InstallVersionedChart(h.settings.OperatorNamespace, OperatorChartName, h.settings.RookVersion, values); err != nil {
return errors.Errorf("failed to install rook operator via helm, err : %v", err)
}
}
return nil
}
// CreateRookCephClusterViaHelm creates rook cluster via Helm
func (h *CephInstaller) CreateRookCephClusterViaHelm() error {
return h.configureRookCephClusterViaHelm(false)
}
func (h *CephInstaller) UpgradeRookCephClusterViaHelm() error {
return h.configureRookCephClusterViaHelm(true)
}
func (h *CephInstaller) configureRookCephClusterViaHelm(upgrade bool) error {
values := map[string]interface{}{
"image": "rook/ceph:" + h.settings.RookVersion,
}
// Set the host path the first time, but use the same path for an upgrade
if h.settings.DataDirHostPath == "" {
var err error
h.settings.DataDirHostPath, err = h.initTestDir(h.settings.Namespace)
if err != nil {
return err
}
}
var clusterCRD map[string]interface{}
if err := yaml.Unmarshal([]byte(h.Manifests.GetCephCluster()), &clusterCRD); err != nil {
return err
}
values["cephClusterSpec"] = clusterCRD["spec"]
values["operatorNamespace"] = h.settings.OperatorNamespace
values["configOverride"] = clusterCustomSettings
values["toolbox"] = map[string]interface{}{
"enabled": true,
"image": "rook/ceph:" + h.settings.RookVersion,
}
values["ingress"] = map[string]interface{}{
"dashboard": map[string]interface{}{
"annotations": map[string]interface{}{
"kubernetes.io/ingress-class": "nginx",
"nginx.ingress.kubernetes.io/rewrite-target": "/ceph-dashboard/$2",
},
"host": map[string]interface{}{
"name": "localhost",
"path": "/ceph-dashboard(/|$)(.*)",
},
},
}
if err := h.CreateBlockPoolConfiguration(values, BlockPoolName, BlockPoolSCName); err != nil {
return err
}
if err := h.CreateFileSystemConfiguration(values, FilesystemName, FilesystemSCName); err != nil {
return err
}
if err := h.CreateObjectStoreConfiguration(values, ObjectStoreName, ObjectStoreSCName); err != nil {
return err
}
logger.Infof("Creating ceph cluster using Helm with values: %+v", values)
if h.settings.RookVersion == LocalBuildTag {
if err := h.helmHelper.InstallLocalHelmChart(upgrade, h.settings.Namespace, CephClusterChartName, values); err != nil {
return err
}
} else {
// Install official version of the chart
if err := h.helmHelper.InstallVersionedChart(h.settings.Namespace, CephClusterChartName, h.settings.RookVersion, values); err != nil {
return err
}
}
return nil
}
// removeCephClusterHelmResources tidies up the helm created CRs and Storage Classes, as they interfere with other tests.
func (h *CephInstaller) removeCephClusterHelmResources() {
if err := h.k8shelper.Clientset.StorageV1().StorageClasses().Delete(context.TODO(), BlockPoolSCName, v1.DeleteOptions{}); err != nil {
assert.True(h.T(), kerrors.IsNotFound(err))
}
if err := h.k8shelper.Clientset.StorageV1().StorageClasses().Delete(context.TODO(), FilesystemSCName, v1.DeleteOptions{}); err != nil {
assert.True(h.T(), kerrors.IsNotFound(err))
}
if err := h.k8shelper.Clientset.StorageV1().StorageClasses().Delete(context.TODO(), ObjectStoreSCName, v1.DeleteOptions{}); err != nil {
assert.True(h.T(), kerrors.IsNotFound(err))
}
if err := h.k8shelper.RookClientset.CephV1().CephBlockPools(h.settings.Namespace).Delete(context.TODO(), BlockPoolName, v1.DeleteOptions{}); err != nil {
assert.True(h.T(), kerrors.IsNotFound(err))
}
if err := h.k8shelper.RookClientset.CephV1().CephFilesystems(h.settings.Namespace).Delete(context.TODO(), FilesystemName, v1.DeleteOptions{}); err != nil {
assert.True(h.T(), kerrors.IsNotFound(err))
}
if err := h.k8shelper.RookClientset.CephV1().CephObjectStores(h.settings.Namespace).Delete(context.TODO(), ObjectStoreName, v1.DeleteOptions{}); err != nil {
assert.True(h.T(), kerrors.IsNotFound(err))
}
if !h.k8shelper.WaitUntilPodWithLabelDeleted(fmt.Sprintf("rook_object_store=%s", ObjectStoreName), h.settings.Namespace) {
assert.Fail(h.T(), "rgw did not stop via helm uninstall")
}
}
// ConfirmHelmClusterInstalledCorrectly runs some validation to check whether the helm chart installed correctly.
func (h *CephInstaller) ConfirmHelmClusterInstalledCorrectly() error {
storageClassList, err := h.k8shelper.Clientset.StorageV1().StorageClasses().List(context.TODO(), v1.ListOptions{})
if err != nil {
return err
}
foundStorageClasses := 0
for _, storageClass := range storageClassList.Items {
if storageClass.Name == BlockPoolSCName {
foundStorageClasses++
} else if storageClass.Name == FilesystemSCName {
foundStorageClasses++
} else if storageClass.Name == ObjectStoreSCName {
foundStorageClasses++
}
}
if foundStorageClasses != 3 {
return fmt.Errorf("did not find the three storage classes which should have been deployed")
}
// check that ObjectStore is created
logger.Infof("Check that RGW pods are Running")
for i := 0; i < 24 && !h.k8shelper.CheckPodCountAndState("rook-ceph-rgw", h.settings.Namespace, 2, "Running"); i++ {
logger.Infof("(%d) RGW pod check sleeping for 5 seconds ...", i)
time.Sleep(5 * time.Second)
}
if !h.k8shelper.CheckPodCountAndState("rook-ceph-rgw", h.settings.Namespace, 2, "Running") {
return fmt.Errorf("did not find the rados gateway pod, which should have been deployed")
}
return nil
}
// CreateBlockPoolConfiguration creates a block store configuration
func (h *CephInstaller) CreateBlockPoolConfiguration(values map[string]interface{}, name, scName string) error {
testBlockPoolBytes := []byte(h.Manifests.GetBlockPool("testPool", "1"))
var testBlockPoolCRD map[string]interface{}
if err := yaml.Unmarshal(testBlockPoolBytes, &testBlockPoolCRD); err != nil {
return err
}
storageClassBytes := []byte(h.Manifests.GetBlockStorageClass(name, scName, "Delete"))
var testBlockSC map[string]interface{}
if err := yaml.Unmarshal(storageClassBytes, &testBlockSC); err != nil {
return err
}
values["cephBlockPools"] = []map[string]interface{}{
{
"name": name,
"spec": testBlockPoolCRD["spec"],
"storageClass": map[string]interface{}{
"enabled": true,
"isDefault": true,
"name": scName,
"parameters": testBlockSC["parameters"],
"reclaimPolicy": "Delete",
"allowVolumeExpansion": true,
},
},
}
return nil
}
// CreateFileSystemConfiguration creates a filesystem configuration
func (h *CephInstaller) CreateFileSystemConfiguration(values map[string]interface{}, name, scName string) error {
testFilesystemBytes := []byte(h.Manifests.GetFilesystem("testFilesystem", 1))
var testFilesystemCRD map[string]interface{}
if err := yaml.Unmarshal(testFilesystemBytes, &testFilesystemCRD); err != nil {
return err
}
storageClassBytes := []byte(h.Manifests.GetFileStorageClass(name, scName))
var testFileSystemSC map[string]interface{}
if err := yaml.Unmarshal(storageClassBytes, &testFileSystemSC); err != nil {
return err
}
values["cephFileSystems"] = []map[string]interface{}{
{
"name": name,
"spec": testFilesystemCRD["spec"],
"storageClass": map[string]interface{}{
"enabled": true,
"name": scName,
"parameters": testFileSystemSC["parameters"],
"reclaimPolicy": "Delete",
},
},
}
return nil
}
// CreateObjectStoreConfiguration creates an object store configuration
func (h *CephInstaller) CreateObjectStoreConfiguration(values map[string]interface{}, name, scName string) error {
testObjectStoreBytes := []byte(h.Manifests.GetObjectStore(name, 2, 8080, false))
var testObjectStoreCRD map[string]interface{}
if err := yaml.Unmarshal(testObjectStoreBytes, &testObjectStoreCRD); err != nil {
return err
}
storageClassBytes := []byte(h.Manifests.GetBucketStorageClass(name, scName, "Delete", name))
var testObjectStoreSC map[string]interface{}
if err := yaml.Unmarshal(storageClassBytes, &testObjectStoreSC); err != nil {
return err
}
values["cephObjectStores"] = []map[string]interface{}{
{
"name": name,
"spec": testObjectStoreCRD["spec"],
"storageClass": map[string]interface{}{
"enabled": true,
"name": scName,
"parameters": testObjectStoreSC["parameters"],
"reclaimPolicy": "Delete",
},
},
}
return nil
}