Skip to content

Commit aece2c0

Browse files
committed
Add tests to see reconciler filter works
Add tests to verify that GenerationChangedPredicate correctly filters status-only updates and prevents unnecessary Nova reconciliations.
1 parent f67fb79 commit aece2c0

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

test/functional/nova_controller_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,3 +2103,74 @@ var _ = Describe("application credentials", func() {
21032103
})
21042104
})
21052105
})
2106+
2107+
var _ = Describe("Nova controller - predicates", func() {
2108+
When("Nova CR with child resources exists", func() {
2109+
BeforeEach(func() {
2110+
CreateNovaWithNCellsAndEnsureReady(1, &novaNames)
2111+
})
2112+
2113+
It("do not - reconcile Nova when NovaAPI CR status changes", func() {
2114+
nova := GetNova(novaNames.NovaName)
2115+
// get initial resourceVersion
2116+
initialResourceVersion := nova.ResourceVersion
2117+
2118+
// Update nova-api status (not spec)
2119+
Eventually(func(g Gomega) {
2120+
api := GetNovaAPI(novaNames.APIName)
2121+
api.Status.ReadyCount = 999
2122+
// here only updating status and not object spec
2123+
g.Expect(k8sClient.Status().Update(ctx, api)).Should(Succeed())
2124+
}, timeout, interval).Should(Succeed())
2125+
2126+
// Check nova resourceVersion did not change
2127+
// so above update call did not make any new reconciliation to change resourceversion
2128+
Consistently(func(g Gomega) {
2129+
nova = GetNova(novaNames.NovaName)
2130+
g.Expect(nova.ResourceVersion).To(Equal(initialResourceVersion))
2131+
// here we must wait for full duration to ensure no delayed reconciliation was triggered.
2132+
// checking consistently for 25 sec
2133+
}, consistencyTimeout, interval).Should(Succeed())
2134+
})
2135+
2136+
It("do - reconcile Nova when child CR spec changes", func() {
2137+
nova := GetNova(novaNames.NovaName)
2138+
initialResourceVersion := nova.ResourceVersion
2139+
2140+
Eventually(func(g Gomega) {
2141+
api := GetNovaAPI(novaNames.APIName)
2142+
api.Spec.Replicas = ptr.To(int32(3))
2143+
// update api spec
2144+
g.Expect(k8sClient.Update(ctx, api)).Should(Succeed())
2145+
}, timeout, interval).Should(Succeed())
2146+
2147+
// Verify Nova resourceVersion did change
2148+
// Nova should reconcile due to spec change
2149+
Eventually(func(g Gomega) {
2150+
nova = GetNova(novaNames.NovaName)
2151+
g.Expect(nova.ResourceVersion).ToNot(Equal(initialResourceVersion))
2152+
}, timeout, interval).Should(Succeed())
2153+
})
2154+
2155+
It("do - reconcile Nova when TransportURL spec changes", func() {
2156+
transportURL := infra.GetTransportURL(cell0.TransportURLName)
2157+
Expect(transportURL).ToNot(BeNil())
2158+
2159+
nova := GetNova(novaNames.NovaName)
2160+
initialResourceVersion := nova.ResourceVersion
2161+
2162+
// Update TransportURL spec
2163+
Eventually(func(g Gomega) {
2164+
transportURL = infra.GetTransportURL(cell0.TransportURLName)
2165+
transportURL.Spec.RabbitmqClusterName = "rabbitmq-notification"
2166+
g.Expect(k8sClient.Update(ctx, transportURL)).Should(Succeed())
2167+
}, timeout, interval).Should(Succeed())
2168+
2169+
// Verify Nova resourceVersion did change
2170+
Eventually(func(g Gomega) {
2171+
nova = GetNova(novaNames.NovaName)
2172+
g.Expect(nova.ResourceVersion).ToNot(Equal(initialResourceVersion))
2173+
}, timeout, interval).Should(Succeed())
2174+
})
2175+
})
2176+
})

0 commit comments

Comments
 (0)