From 61fcf51d02879f87d8f10ca86011eba66cb6d01b Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Wed, 20 Nov 2024 11:35:59 +0100 Subject: [PATCH] [#1053] Test migration from ActiveMQArtemisAddress CRs to broker properties --- .../activemqartemisaddress_controller_test.go | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/controllers/activemqartemisaddress_controller_test.go b/controllers/activemqartemisaddress_controller_test.go index 0df4c1a2..8b02ffd7 100644 --- a/controllers/activemqartemisaddress_controller_test.go +++ b/controllers/activemqartemisaddress_controller_test.go @@ -1052,6 +1052,125 @@ var _ = Describe("Address controller tests", func() { }, timeout, interval).Should(Succeed()) }) }) + + Context("Address CR migration test", Label("address-migration-test"), func() { + It("Migrate to broker properties when RemoveFromBrokerOnDelete is false", func() { + addressName := "TEST-ADDRESS" + queueName := "TEST-QUEUE" + routingType := "anycast" + + By("deploy a broker cr") + brokerCr, createdBrokerCr := DeployCustomBroker(defaultNamespace, nil) + podName := namer.CrToSS(brokerCr.Name) + "-0" + + By("deploy an address cr") + addressCr, createdAddressCr := DeployCustomAddress(defaultNamespace, func(candidate *brokerv1beta1.ActiveMQArtemisAddress) { + candidate.Spec.AddressName = addressName + candidate.Spec.QueueName = &queueName + candidate.Spec.RoutingType = &routingType + candidate.Spec.RemoveFromBrokerOnDelete = false + }) + + By("verify the queue exists") + CheckQueueExistInPod(brokerCr.Name, podName, queueName, defaultNamespace) + CheckQueueAttribute(brokerCr.Name, podName, defaultNamespace, queueName, addressName, "anycast", "ConfigurationManaged", "true") + + brokerKey := types.NamespacedName{Name: createdBrokerCr.Name, Namespace: createdBrokerCr.Namespace} + Eventually(func(g Gomega) { + By("adding broker properties") + g.Expect(k8sClient.Get(ctx, brokerKey, createdBrokerCr)).Should(Succeed()) + createdBrokerCr.Spec.BrokerProperties = []string{ + "addressConfigurations.TEST-ADDRESS.queueConfigs.TEST-QUEUE.routingType=ANYCAST", + "addressConfigurations.TEST-ADDRESS.queueConfigs.TEST-QUEUE.durable=true", + } + g.Expect(k8sClient.Update(ctx, createdBrokerCr)).Should(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + addressKey := types.NamespacedName{Name: createdAddressCr.Name, Namespace: createdAddressCr.Namespace} + Eventually(func(g Gomega) { + By("deleting address CR") + g.Expect(k8sClient.Get(ctx, addressKey, createdAddressCr)).Should(Succeed()) + g.Expect(k8sClient.Delete(ctx, createdAddressCr)).Should(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + Eventually(func(g Gomega) { + By("checking lscrs secret is gone") + expectedSecuritySecret := &corev1.Secret{} + expectedSecuritySecretKey := types.NamespacedName{Name: "secret-address-" + addressCr.Name, Namespace: defaultNamespace} + g.Expect(k8sClient.Get(ctx, expectedSecuritySecretKey, expectedSecuritySecret)).ShouldNot(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + By("verify the queue exists") + CheckQueueExistInPod(brokerCr.Name, podName, queueName, defaultNamespace) + CheckQueueAttribute(brokerCr.Name, podName, defaultNamespace, queueName, addressName, "anycast", "ConfigurationManaged", "true") + + By("cleanup") + CleanResource(createdBrokerCr, brokerCr.Name, defaultNamespace) + CleanResource(createdAddressCr, addressCr.Name, defaultNamespace) + }) + + It("Migrate to broker properties when RemoveFromBrokerOnDelete is true", func() { + addressName := "TEST-ADDRESS" + queueName := "TEST-QUEUE" + routingType := "anycast" + + By("deploy a broker cr") + brokerCr, createdBrokerCr := DeployCustomBroker(defaultNamespace, nil) + podName := namer.CrToSS(brokerCr.Name) + "-0" + + By("deploy an address cr") + addressCr, createdAddressCr := DeployCustomAddress(defaultNamespace, func(candidate *brokerv1beta1.ActiveMQArtemisAddress) { + candidate.Spec.AddressName = addressName + candidate.Spec.QueueName = &queueName + candidate.Spec.RoutingType = &routingType + candidate.Spec.RemoveFromBrokerOnDelete = true + }) + + By("verify the queue exists") + CheckQueueExistInPod(brokerCr.Name, podName, queueName, defaultNamespace) + CheckQueueAttribute(brokerCr.Name, podName, defaultNamespace, queueName, addressName, "anycast", "ConfigurationManaged", "true") + + addressKey := types.NamespacedName{Name: createdAddressCr.Name, Namespace: createdAddressCr.Namespace} + Eventually(func(g Gomega) { + By("disabling RemoveFromBrokerOnDelete") + g.Expect(k8sClient.Get(ctx, addressKey, createdAddressCr)).Should(Succeed()) + createdAddressCr.Spec.RemoveFromBrokerOnDelete = false + g.Expect(k8sClient.Update(ctx, createdAddressCr)).Should(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + brokerKey := types.NamespacedName{Name: createdBrokerCr.Name, Namespace: createdBrokerCr.Namespace} + Eventually(func(g Gomega) { + By("adding broker properties") + g.Expect(k8sClient.Get(ctx, brokerKey, createdBrokerCr)).Should(Succeed()) + createdBrokerCr.Spec.BrokerProperties = []string{ + "addressConfigurations.TEST-ADDRESS.queueConfigs.TEST-QUEUE.routingType=ANYCAST", + "addressConfigurations.TEST-ADDRESS.queueConfigs.TEST-QUEUE.durable=true", + } + g.Expect(k8sClient.Update(ctx, createdBrokerCr)).Should(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + Eventually(func(g Gomega) { + By("deleting address CR") + g.Expect(k8sClient.Get(ctx, addressKey, createdAddressCr)).Should(Succeed()) + g.Expect(k8sClient.Delete(ctx, createdAddressCr)).Should(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + Eventually(func(g Gomega) { + By("checking lscrs secret is gone") + expectedSecuritySecret := &corev1.Secret{} + expectedSecuritySecretKey := types.NamespacedName{Name: "secret-address-" + addressCr.Name, Namespace: defaultNamespace} + g.Expect(k8sClient.Get(ctx, expectedSecuritySecretKey, expectedSecuritySecret)).ShouldNot(Succeed()) + }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) + + By("verify the queue exists") + CheckQueueExistInPod(brokerCr.Name, podName, queueName, defaultNamespace) + CheckQueueAttribute(brokerCr.Name, podName, defaultNamespace, queueName, addressName, "anycast", "ConfigurationManaged", "true") + + By("cleanup") + CleanResource(createdBrokerCr, brokerCr.Name, defaultNamespace) + CleanResource(createdAddressCr, addressCr.Name, defaultNamespace) + }) + }) }) func CheckQueueExistInPod(brokerCrName string, podName string, queueName string, namespace string) {