-
Notifications
You must be signed in to change notification settings - Fork 66
/
config_secret_suite_test.go
110 lines (88 loc) · 4.11 KB
/
config_secret_suite_test.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
package config_secret
import (
"fmt"
"testing"
api "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
"github.com/k8ssandra/cass-operator/tests/kustomize"
corev1 "k8s.io/api/core/v1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
ginkgo_util "github.com/k8ssandra/cass-operator/tests/util/ginkgo"
"github.com/k8ssandra/cass-operator/tests/util/kubectl"
)
var (
testName = "Config change rollout with config secret"
namespace = "test-config-change-rollout-secret"
dcName = "dc1"
dcYaml = "../testdata/cluster-with-config-secret.yaml"
dcResource = fmt.Sprintf("CassandraDatacenter/%s", dcName)
secretYaml = "../testdata/test-config-secret.yaml"
updatedSecretYaml = "../testdata/updated-test-config-secret.yaml"
ns = ginkgo_util.NewWrapper(testName, namespace)
)
func TestLifecycle(t *testing.T) {
AfterSuite(func() {
logPath := fmt.Sprintf("%s/aftersuite", ns.LogDir)
err := kubectl.DumpAllLogs(logPath).ExecV()
if err != nil {
t.Logf("Failed to dump all the logs: %v", err)
}
fmt.Printf("\n\tPost-run logs dumped at: %s\n\n", logPath)
ns.Terminate()
err = kustomize.Undeploy(namespace)
if err != nil {
t.Logf("Failed to undeploy cass-operator: %v", err)
}
})
RegisterFailHandler(Fail)
RunSpecs(t, testName)
}
var _ = Describe(testName, func() {
Context("when in a new cluster", func() {
Specify("cassandra configuration can be applied with a secret", func() {
By("deploy cass-operator with kustomize")
err := kustomize.Deploy(namespace)
Expect(err).ToNot(HaveOccurred())
ns.WaitForOperatorReady()
step := "creating config secret"
testSecretFile, err := ginkgo_util.CreateTestSecretsConfig(secretYaml)
Expect(err).ToNot(HaveOccurred())
k := kubectl.ApplyFiles(testSecretFile)
ns.ExecAndLog(step, k)
step = "creating datacenter"
testFile, err := ginkgo_util.CreateTestFile(dcYaml)
Expect(err).ToNot(HaveOccurred())
k = kubectl.ApplyFiles(testFile)
ns.ExecAndLog(step, k)
ns.WaitForDatacenterReadyWithTimeouts(dcName, 420, 30)
step = "update config secret"
testUpdatedSecretFile, err := ginkgo_util.CreateTestSecretsConfig(updatedSecretYaml)
Expect(err).ToNot(HaveOccurred())
k = kubectl.ApplyFiles(testUpdatedSecretFile)
ns.ExecAndLog(step, k)
ns.WaitForDatacenterOperatorProgress(dcName, "Updating", 60)
ns.WaitForDatacenterConditionWithTimeout(dcName, string(api.DatacenterReady), string(corev1.ConditionTrue), 1200)
step = "checking cassandra.yaml"
k = kubectl.ExecOnPod("cluster1-dc1-r1-sts-0", "-c", "cassandra", "--", "cat", ginkgo_util.GetCassandraConfigYamlLocation())
ns.WaitForOutputContainsAndLog(step, k, "read_request_timeout: 10000ms", 60)
step = "stop using config secret"
json := ginkgo_util.CreateTestJson(`[{"op": "remove", "path": "/spec/configSecret"}, {"op": "add", "path": "/spec/config", "value": {"cassandra-yaml": {"read_request_timeout": "25000ms"}, "jvm-server-options": {"initial_heap_size": "512M", "max_heap_size": "512M"}}}]`)
k = kubectl.PatchJson(dcResource, json)
ns.ExecAndLog(step, k)
ns.WaitForDatacenterOperatorProgress(dcName, "Updating", 120)
ns.WaitForDatacenterConditionWithTimeout(dcName, string(api.DatacenterReady), string(corev1.ConditionTrue), 1200)
step = "checking cassandra.yaml"
k = kubectl.ExecOnPod("cluster1-dc1-r1-sts-0", "-c", "cassandra", "--", "cat", ginkgo_util.GetCassandraConfigYamlLocation())
ns.WaitForOutputContainsAndLog(step, k, "read_request_timeout: 25000ms", 120)
step = "use config secret again"
json = `{"spec": {"config": null, "configSecret": "test-config"}}`
k = kubectl.PatchMerge(dcResource, json)
ns.ExecAndLog(step, k)
ns.WaitForDatacenterOperatorProgress(dcName, "Updating", 120)
ns.WaitForDatacenterConditionWithTimeout(dcName, string(api.DatacenterReady), string(corev1.ConditionTrue), 1200)
step = "checking cassandra.yaml"
k = kubectl.ExecOnPod("cluster1-dc1-r1-sts-0", "-c", "cassandra", "--", "cat", ginkgo_util.GetCassandraConfigYamlLocation())
ns.WaitForOutputContainsAndLog(step, k, "read_request_timeout: 10000ms", 120)
})
})
})