|
1 | 1 | package controllers_test |
2 | 2 |
|
3 | 3 | import ( |
4 | | - rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1" |
5 | 4 | "time" |
6 | 5 |
|
| 6 | + rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1" |
| 7 | + |
7 | 8 | . "github.com/onsi/ginkgo" |
8 | 9 | . "github.com/onsi/ginkgo/extensions/table" |
9 | 10 | . "github.com/onsi/gomega" |
10 | 11 |
|
11 | 12 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 13 | + "k8s.io/utils/pointer" |
12 | 14 | ) |
13 | 15 |
|
14 | 16 | var _ = Describe("Reconcile rabbitmq Configurations", func() { |
15 | 17 | var ( |
16 | 18 | cluster *rabbitmqv1beta1.RabbitmqCluster |
17 | 19 | defaultNamespace = "default" |
18 | 20 | ) |
19 | | - DescribeTable("Server configurations updates", |
20 | | - func(testCase string) { |
21 | | - // create rabbitmqcluster |
| 21 | + |
| 22 | + AfterEach(func() { |
| 23 | + Expect(client.Delete(ctx, cluster)).To(Succeed()) |
| 24 | + waitForClusterDeletion(ctx, cluster, client) |
| 25 | + }) |
| 26 | + |
| 27 | + DescribeTable("Server configurations updates", func(testCase string) { |
| 28 | + cluster = &rabbitmqv1beta1.RabbitmqCluster{ |
| 29 | + ObjectMeta: metav1.ObjectMeta{ |
| 30 | + Namespace: defaultNamespace, |
| 31 | + Name: "rabbitmq-" + testCase, |
| 32 | + }, |
| 33 | + } |
| 34 | + Expect(client.Create(ctx, cluster)).To(Succeed()) |
| 35 | + waitForClusterCreation(ctx, cluster, client) |
| 36 | + |
| 37 | + // ensure that cfm and statefulSet does not have annotations set when cluster just got created |
| 38 | + cfm := configMap(ctx, cluster, "server-conf") |
| 39 | + Expect(cfm.Annotations).ShouldNot(HaveKey("rabbitmq.com/serverConfUpdatedAt")) |
| 40 | + sts := statefulSet(ctx, cluster) |
| 41 | + Expect(sts.Annotations).ShouldNot(HaveKey("rabbitmq.com/lastRestartAt")) |
| 42 | + |
| 43 | + // update rabbitmq server configurations |
| 44 | + Expect(updateWithRetry(cluster, func(r *rabbitmqv1beta1.RabbitmqCluster) { |
| 45 | + if testCase == "additional-config" { |
| 46 | + r.Spec.Rabbitmq.AdditionalConfig = "test_config=0" |
| 47 | + } |
| 48 | + if testCase == "advanced-config" { |
| 49 | + r.Spec.Rabbitmq.AdvancedConfig = "sample-advanced-config." |
| 50 | + } |
| 51 | + if testCase == "env-config" { |
| 52 | + r.Spec.Rabbitmq.EnvConfig = "some-env-variable" |
| 53 | + } |
| 54 | + })).To(Succeed()) |
| 55 | + |
| 56 | + By("annotating the server-conf ConfigMap") |
| 57 | + // ensure annotations from the server-conf ConfigMap |
| 58 | + var annotations map[string]string |
| 59 | + Eventually(func() map[string]string { |
| 60 | + cfm := configMap(ctx, cluster, "server-conf") |
| 61 | + annotations = cfm.Annotations |
| 62 | + return annotations |
| 63 | + }, 5).Should(HaveKey("rabbitmq.com/serverConfUpdatedAt")) |
| 64 | + _, err := time.Parse(time.RFC3339, annotations["rabbitmq.com/serverConfUpdatedAt"]) |
| 65 | + Expect(err).NotTo(HaveOccurred(), "Annotation rabbitmq.com/serverConfUpdatedAt was not a valid RFC3339 timestamp") |
| 66 | + |
| 67 | + By("annotating the sts podTemplate") |
| 68 | + // ensure statefulSet annotations |
| 69 | + Eventually(func() map[string]string { |
| 70 | + sts := statefulSet(ctx, cluster) |
| 71 | + annotations = sts.Spec.Template.Annotations |
| 72 | + return annotations |
| 73 | + }, 5).Should(HaveKey("rabbitmq.com/lastRestartAt")) |
| 74 | + _, err = time.Parse(time.RFC3339, annotations["rabbitmq.com/lastRestartAt"]) |
| 75 | + Expect(err).NotTo(HaveOccurred(), "Annotation rabbitmq.com/lastRestartAt was not a valid RFC3339 timestamp") |
| 76 | + }, |
| 77 | + |
| 78 | + Entry("spec.rabbitmq.additionalConfig is updated", "additional-config"), |
| 79 | + Entry("spec.rabbitmq.advancedConfig is updated", "advanced-config"), |
| 80 | + Entry("spec.rabbitmq.envConfig is updated", "env-config"), |
| 81 | + ) |
| 82 | + |
| 83 | + Context("scale out", func() { |
| 84 | + It("does not restart StatefulSet", func() { |
22 | 85 | cluster = &rabbitmqv1beta1.RabbitmqCluster{ |
23 | 86 | ObjectMeta: metav1.ObjectMeta{ |
24 | | - Name: "rabbitmq-" + testCase, |
25 | 87 | Namespace: defaultNamespace, |
| 88 | + Name: "rabbitmq-scale-out", |
26 | 89 | }, |
27 | 90 | } |
28 | 91 | Expect(client.Create(ctx, cluster)).To(Succeed()) |
29 | 92 | waitForClusterCreation(ctx, cluster, client) |
30 | 93 |
|
31 | | - // ensure that cfm and statefulSet does not have annotations set when configurations haven't changed |
32 | 94 | cfm := configMap(ctx, cluster, "server-conf") |
33 | 95 | Expect(cfm.Annotations).ShouldNot(HaveKey("rabbitmq.com/serverConfUpdatedAt")) |
34 | | - |
35 | 96 | sts := statefulSet(ctx, cluster) |
36 | 97 | Expect(sts.Annotations).ShouldNot(HaveKey("rabbitmq.com/lastRestartAt")) |
37 | 98 |
|
38 | | - // update rabbitmq server configurations |
39 | 99 | Expect(updateWithRetry(cluster, func(r *rabbitmqv1beta1.RabbitmqCluster) { |
40 | | - if testCase == "additional-config" { |
41 | | - r.Spec.Rabbitmq.AdditionalConfig = "test_config=0" |
42 | | - } |
43 | | - if testCase == "advanced-config" { |
44 | | - r.Spec.Rabbitmq.AdvancedConfig = "sample-advanced-config." |
45 | | - } |
46 | | - if testCase == "env-config" { |
47 | | - r.Spec.Rabbitmq.EnvConfig = "some-env-variable" |
48 | | - } |
| 100 | + r.Spec.Replicas = pointer.Int32Ptr(5) |
49 | 101 | })).To(Succeed()) |
50 | 102 |
|
51 | | - By("annotating the server-conf ConfigMap") |
52 | | - // ensure annotations from the server-conf ConfigMap |
53 | | - var annotations map[string]string |
54 | | - Eventually(func() map[string]string { |
55 | | - cfm := configMap(ctx, cluster, "server-conf") |
56 | | - annotations = cfm.Annotations |
57 | | - return annotations |
58 | | - }, 5).Should(HaveKey("rabbitmq.com/serverConfUpdatedAt")) |
59 | | - _, err := time.Parse(time.RFC3339, annotations["rabbitmq.com/serverConfUpdatedAt"]) |
60 | | - Expect(err).NotTo(HaveOccurred(), "Annotation rabbitmq.com/serverConfUpdatedAt was not a valid RFC3339 timestamp") |
61 | | - |
62 | | - By("annotating the sts podTemplate") |
63 | | - // ensure statefulSet annotations |
64 | | - Eventually(func() map[string]string { |
65 | | - sts := statefulSet(ctx, cluster) |
66 | | - annotations = sts.Spec.Template.Annotations |
67 | | - return annotations |
68 | | - }, 5).Should(HaveKey("rabbitmq.com/lastRestartAt")) |
69 | | - _, err = time.Parse(time.RFC3339, annotations["rabbitmq.com/lastRestartAt"]) |
70 | | - Expect(err).NotTo(HaveOccurred(), "Annotation rabbitmq.com/lastRestartAt was not a valid RFC3339 timestamp") |
71 | | - |
72 | | - // delete rmq cluster |
73 | | - Expect(client.Delete(ctx, cluster)).To(Succeed()) |
74 | | - waitForClusterDeletion(ctx, cluster, client) |
75 | | - }, |
| 103 | + Consistently(func() map[string]string { |
| 104 | + return configMap(ctx, cluster, "server-conf").Annotations |
| 105 | + }, 3, 0.3).ShouldNot(HaveKey("rabbitmq.com/serverConfUpdatedAt")) |
76 | 106 |
|
77 | | - Entry("spec.rabbitmq.additionalConfig is updated", "additional-config"), |
78 | | - Entry("spec.rabbitmq.advancedConfig is updated", "advanced-config"), |
79 | | - Entry("spec.rabbitmq.envConfig is updated", "env-config"), |
80 | | - ) |
| 107 | + Consistently(func() map[string]string { |
| 108 | + sts := statefulSet(ctx, cluster) |
| 109 | + return sts.Spec.Template.Annotations |
| 110 | + }, 3, 0.3).ShouldNot(HaveKey("rabbitmq.com/lastRestartAt")) |
| 111 | + }) |
| 112 | + }) |
81 | 113 | }) |
0 commit comments