Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1053] Test migration from ActiveMQArtemisAddress CRs to broker properties #1054

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions controllers/activemqartemisaddress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,195 @@ 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 configDelete is FORCE", func() {
addressName := "TEST-ADDRESS"
queueName := "TEST-QUEUE"
routingType := "anycast"

By("deploy a broker cr")
brokerCr, createdBrokerCr := DeployCustomBroker(defaultNamespace, func(candidate *brokerv1beta1.ActiveMQArtemis) {
candidate.Spec.BrokerProperties = []string{
"addressSettings.#.configDeleteAddresses=FORCE",
"addressSettings.#.configDeleteQueues=FORCE",
}
})
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{
"addressSettings.#.configDeleteAddresses=FORCE",
"addressSettings.#.configDeleteQueues=FORCE",
"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("verify config applied")
g.Expect(k8sClient.Get(ctx, brokerKey, createdBrokerCr)).Should(Succeed())
condition := meta.FindStatusCondition(createdBrokerCr.Status.Conditions, brokerv1beta1.ConfigAppliedConditionType)
g.Expect(condition).NotTo(BeNil())
g.Expect(condition.Status).To(Equal(metav1.ConditionTrue))
}, 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 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
Loading