Skip to content

Commit

Permalink
[#1053] Test migration from ActiveMQArtemisAddress CRs to broker prop…
Browse files Browse the repository at this point in the history
…erties
  • Loading branch information
brusdev committed Nov 20, 2024
1 parent d7656ad commit 61fcf51
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions controllers/activemqartemisaddress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 61fcf51

Please sign in to comment.