-
Notifications
You must be signed in to change notification settings - Fork 157
/
scyllacluster_upgrades.go
146 lines (126 loc) · 4.87 KB
/
scyllacluster_upgrades.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
// Copyright (C) 2021 ScyllaDB
package scyllacluster
import (
"context"
"fmt"
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
scyllav1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1"
"github.com/scylladb/scylla-operator/pkg/controllerhelpers"
"github.com/scylladb/scylla-operator/test/e2e/framework"
"github.com/scylladb/scylla-operator/test/e2e/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
var _ = g.Describe("ScyllaCluster upgrades", func() {
defer g.GinkgoRecover()
f := framework.NewFramework("scyllacluster")
type entry struct {
rackSize int32
rackCount int32
initialVersion string
updatedVersion string
}
describeEntry := func(e *entry) string {
return fmt.Sprintf("with %d member(s) and %d rack(s) from %s to %s", e.rackSize, e.rackCount, e.initialVersion, e.updatedVersion)
}
g.DescribeTable("should deploy and update",
func(e *entry) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
sc := f.GetDefaultScyllaCluster()
sc.Spec.Version = e.initialVersion
o.Expect(sc.Spec.Datacenter.Racks).To(o.HaveLen(1))
rack := &sc.Spec.Datacenter.Racks[0]
sc.Spec.Datacenter.Racks = make([]scyllav1.RackSpec, 0, e.rackCount)
for i := int32(0); i < e.rackCount; i++ {
r := rack.DeepCopy()
r.Name = fmt.Sprintf("rack-%d", i)
r.Members = e.rackSize
sc.Spec.Datacenter.Racks = append(sc.Spec.Datacenter.Racks, *r)
}
framework.By("Creating a ScyllaCluster")
sc, err := f.ScyllaClient().ScyllaV1().ScyllaClusters(f.Namespace()).Create(ctx, sc, metav1.CreateOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(sc.Spec.Version).To(o.Equal(e.initialVersion))
framework.By("Waiting for the ScyllaCluster to rollout (RV=%s)", sc.ResourceVersion)
waitCtx1, waitCtx1Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx1Cancel()
sc, err = controllerhelpers.WaitForScyllaClusterState(waitCtx1, f.ScyllaClient().ScyllaV1().ScyllaClusters(sc.Namespace), sc.Name, controllerhelpers.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
waitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
hosts, hostIDs, err := utils.GetBroadcastRPCAddressesAndUUIDs(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(err).NotTo(o.HaveOccurred())
numNodes := int(e.rackCount * e.rackSize)
o.Expect(hosts).To(o.HaveLen(numNodes))
o.Expect(hostIDs).To(o.HaveLen(numNodes))
di := insertAndVerifyCQLData(ctx, hosts)
defer di.Close()
framework.By("triggering and update")
sc, err = f.ScyllaClient().ScyllaV1().ScyllaClusters(f.Namespace()).Patch(
ctx,
sc.Name,
types.MergePatchType,
[]byte(fmt.Sprintf(
`{"metadata":{"uid":"%s"},"spec":{"version":"%s"}}`,
sc.UID,
e.updatedVersion,
)),
metav1.PatchOptions{},
)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(sc.Spec.Version).To(o.Equal(e.updatedVersion))
framework.By("Waiting for the ScyllaCluster to re-deploy")
waitCtx2, waitCtx2Cancel := utils.ContextForRollout(ctx, sc)
defer waitCtx2Cancel()
sc, err = controllerhelpers.WaitForScyllaClusterState(waitCtx2, f.ScyllaClient().ScyllaV1().ScyllaClusters(sc.Namespace), sc.Name, controllerhelpers.WaitForStateOptions{}, utils.IsScyllaClusterRolledOut)
o.Expect(err).NotTo(o.HaveOccurred())
verifyScyllaCluster(ctx, f.KubeClient(), sc)
waitForFullQuorum(ctx, f.KubeClient().CoreV1(), sc)
oldHosts := hosts
oldHostIDs := hostIDs
hosts, hostIDs, err = utils.GetBroadcastRPCAddressesAndUUIDs(ctx, f.KubeClient().CoreV1(), sc)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(hosts).To(o.HaveLen(len(oldHosts)))
o.Expect(hostIDs).To(o.ConsistOf(oldHostIDs))
// Reset hosts if there's only one node as the client won't be able to discover it.
if numNodes == 1 {
err = di.SetClientEndpoints(hosts)
o.Expect(err).NotTo(o.HaveOccurred())
}
verifyCQLData(ctx, di)
},
// Test 1 and 3 member rack to cover e.g. handling PDBs correctly.
g.Entry(describeEntry, &entry{
rackCount: 1,
rackSize: 1,
initialVersion: updateFromScyllaVersion,
updatedVersion: updateToScyllaVersion,
}),
g.Entry(describeEntry, &entry{
rackCount: 1,
rackSize: 3,
initialVersion: updateFromScyllaVersion,
updatedVersion: updateToScyllaVersion,
}),
g.Entry(describeEntry, &entry{
rackCount: 1,
rackSize: 1,
initialVersion: upgradeFromScyllaVersion,
updatedVersion: upgradeToScyllaVersion,
}),
g.Entry(describeEntry, &entry{
rackCount: 1,
rackSize: 3,
initialVersion: upgradeFromScyllaVersion,
updatedVersion: upgradeToScyllaVersion,
}),
g.Entry(describeEntry, &entry{
rackCount: 2,
rackSize: 3,
initialVersion: upgradeFromScyllaVersion,
updatedVersion: upgradeToScyllaVersion,
}),
)
})