-
Notifications
You must be signed in to change notification settings - Fork 175
/
scyllacluster_scaling.go
214 lines (179 loc) · 8.38 KB
/
scyllacluster_scaling.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
// Copyright (C) 2021 ScyllaDB
package scyllacluster
import (
"context"
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
"github.com/scylladb/scylla-operator/pkg/controller/scyllacluster"
"github.com/scylladb/scylla-operator/pkg/controllerhelpers"
"github.com/scylladb/scylla-operator/pkg/helpers"
"github.com/scylladb/scylla-operator/pkg/naming"
scyllafixture "github.com/scylladb/scylla-operator/test/e2e/fixture/scylla"
"github.com/scylladb/scylla-operator/test/e2e/framework"
"github.com/scylladb/scylla-operator/test/e2e/utils"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
var _ = g.Describe("ScyllaCluster", func() {
defer g.GinkgoRecover()
f := framework.NewFramework("scyllacluster")
g.It("should support scaling", func() {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
sc := scyllafixture.BasicScyllaCluster.ReadOrFail()
sc.Spec.Datacenter.Racks[0].Members = 1
framework.By("Creating a ScyllaCluster with 1 member")
sc, err := f.ScyllaClient().ScyllaV1().ScyllaClusters(f.Namespace()).Create(ctx, sc, metav1.CreateOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
framework.By("Waiting for the ScyllaCluster to rollout (RV=%s)", sc.ResourceVersion)
waitCtx1, waitCtx1Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx1Cancel()
sc, err = utils.WaitForScyllaClusterState(waitCtx1, f.ScyllaClient().ScyllaV1(), sc.Namespace, sc.Name, utils.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
hosts := getScyllaHostsAndWaitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(hosts).To(o.HaveLen(1))
diRF1 := insertAndVerifyCQLData(ctx, hosts)
defer diRF1.Close()
framework.By("Scaling the ScyllaCluster to 3 replicas")
sc, err = f.ScyllaClient().ScyllaV1().ScyllaClusters(f.Namespace()).Patch(
ctx,
sc.Name,
types.JSONPatchType,
[]byte(`[{"op": "replace", "path": "/spec/datacenter/racks/0/members", "value": 3}]`),
metav1.PatchOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(sc.Spec.Datacenter.Racks).To(o.HaveLen(1))
o.Expect(sc.Spec.Datacenter.Racks[0].Members).To(o.BeEquivalentTo(3))
framework.By("Waiting for the ScyllaCluster to rollout (RV=%s)", sc.ResourceVersion)
waitCtx2, waitCtx2Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx2Cancel()
sc, err = utils.WaitForScyllaClusterState(waitCtx2, f.ScyllaClient().ScyllaV1(), sc.Namespace, sc.Name, utils.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
oldHosts := hosts
hosts = getScyllaHostsAndWaitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(oldHosts).To(o.HaveLen(1))
o.Expect(hosts).To(o.HaveLen(3))
o.Expect(hosts).To(o.ContainElements(oldHosts))
verifyCQLData(ctx, diRF1)
// Statistically, some data should land on the 3rd node that will give us a chance to ensure
// it was stream correctly when downscaling.
diRF2 := insertAndVerifyCQLData(ctx, hosts[0:2])
defer diRF2.Close()
diRF3 := insertAndVerifyCQLData(ctx, hosts)
defer diRF3.Close()
framework.By("Scaling the ScyllaCluster down to 2 replicas")
sc, err = f.ScyllaClient().ScyllaV1().ScyllaClusters(sc.Namespace).Patch(
ctx,
sc.Name,
types.JSONPatchType,
[]byte(`[{"op": "replace", "path": "/spec/datacenter/racks/0/members", "value": 2}]`),
metav1.PatchOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(sc.Spec.Datacenter.Racks[0].Members).To(o.BeEquivalentTo(2))
framework.By("Waiting for the ScyllaCluster to rollout (RV=%s)", sc.ResourceVersion)
waitCtx3, waitCtx3Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx3Cancel()
sc, err = utils.WaitForScyllaClusterState(waitCtx3, f.ScyllaClient().ScyllaV1(), sc.Namespace, sc.Name, utils.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
oldHosts = hosts
hosts = getScyllaHostsAndWaitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(oldHosts).To(o.HaveLen(3))
o.Expect(hosts).To(o.HaveLen(2))
o.Expect(oldHosts).To(o.ContainElements(hosts))
verifyCQLData(ctx, diRF1)
// The 2 nodes out of 3 we used earlier may not be the ones that got left. Although discovery will still
// make sure the missing one is picked up, let's avoid having a down node in the pool and refresh it.
err = diRF2.SetClientEndpoints(hosts)
o.Expect(err).NotTo(o.HaveOccurred())
verifyCQLData(ctx, diRF2)
podName := naming.StatefulSetNameForRack(sc.Spec.Datacenter.Racks[0], sc) + "-1"
svcName := podName
framework.By("Marking ScyllaCluster node #2 (%s) for maintenance", podName)
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
naming.NodeMaintenanceLabel: "",
},
},
}
patch, err := helpers.CreateTwoWayMergePatch(&corev1.Service{}, svc)
o.Expect(err).NotTo(o.HaveOccurred())
svc, err = f.KubeClient().CoreV1().Services(sc.Namespace).Patch(
ctx,
svcName,
types.StrategicMergePatchType,
patch,
metav1.PatchOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())
framework.By("Manually draining ScyllaCluster node #2 (%s)", podName)
ec := &corev1.EphemeralContainer{
TargetContainerName: naming.ScyllaContainerName,
EphemeralContainerCommon: corev1.EphemeralContainerCommon{
Name: "e2e-drain-scylla",
Image: scyllacluster.ImageForCluster(sc),
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"/usr/bin/nodetool", "drain"},
Args: []string{},
},
}
pod, err := utils.RunEphemeralContainerAndWaitForCompletion(ctx, f.KubeClient().CoreV1().Pods(sc.Namespace), podName, ec)
o.Expect(err).NotTo(o.HaveOccurred())
ephemeralContainerState := controllerhelpers.FindContainerStatus(pod, ec.Name)
o.Expect(ephemeralContainerState).NotTo(o.BeNil())
o.Expect(ephemeralContainerState.State.Terminated).NotTo(o.BeNil())
o.Expect(ephemeralContainerState.State.Terminated.ExitCode).To(o.BeEquivalentTo(0))
framework.By("Scaling the ScyllaCluster down to 1 replicas")
sc, err = f.ScyllaClient().ScyllaV1().ScyllaClusters(f.Namespace()).Patch(
ctx,
sc.Name,
types.JSONPatchType,
[]byte(`[{"op": "replace", "path": "/spec/datacenter/racks/0/members", "value": 1}]`),
metav1.PatchOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(sc.Spec.Datacenter.Racks[0].Members).To(o.BeEquivalentTo(1))
framework.By("Waiting for the ScyllaCluster to rollout (RV=%s)", sc.ResourceVersion)
waitCtx5, waitCtx5Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx5Cancel()
sc, err = utils.WaitForScyllaClusterState(waitCtx5, f.ScyllaClient().ScyllaV1(), sc.Namespace, sc.Name, utils.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
oldHosts = hosts
hosts = getScyllaHostsAndWaitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(oldHosts).To(o.HaveLen(2))
o.Expect(hosts).To(o.HaveLen(1))
o.Expect(oldHosts).To(o.ContainElements(hosts))
verifyCQLData(ctx, diRF1)
framework.By("Scaling the ScyllaCluster back to 3 replicas to make sure there isn't an old (decommissioned) storage in place")
sc, err = f.ScyllaClient().ScyllaV1().ScyllaClusters(f.Namespace()).Patch(
ctx,
sc.Name,
types.JSONPatchType,
[]byte(`[{"op": "replace", "path": "/spec/datacenter/racks/0/members", "value": 3}]`),
metav1.PatchOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(sc.Spec.Datacenter.Racks[0].Members).To(o.BeEquivalentTo(3))
framework.By("Waiting for the ScyllaCluster to rollout (RV=%s)", sc.ResourceVersion)
waitCtx6, waitCtx6Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx6Cancel()
sc, err = utils.WaitForScyllaClusterState(waitCtx6, f.ScyllaClient().ScyllaV1(), sc.Namespace, sc.Name, utils.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
oldHosts = hosts
hosts = getScyllaHostsAndWaitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(oldHosts).To(o.HaveLen(1))
o.Expect(hosts).To(o.HaveLen(3))
o.Expect(hosts).To(o.ContainElements(oldHosts))
verifyCQLData(ctx, diRF1)
verifyCQLData(ctx, diRF2)
verifyCQLData(ctx, diRF3)
})
})