Skip to content

Commit b0b5f73

Browse files
committed
Add e2e test for pruning remote revisions
Signed-off-by: Nick Fox <[email protected]>
1 parent f23dacc commit b0b5f73

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/e2e/multicluster/multicluster_primaryremote_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package multicluster
1919
import (
2020
"context"
2121
"fmt"
22+
"slices"
2223
"time"
2324

2425
v1 "github.com/istio-ecosystem/sail-operator/api/v1"
@@ -302,6 +303,81 @@ spec:
302303
})
303304
})
304305

306+
When("A revision is no longer in use", func() {
307+
BeforeAll(func(ctx SpecContext) {
308+
// Switch the update strategy to revision based to create a new revision.
309+
Expect(k1.Patch(
310+
"istio",
311+
istioName,
312+
"merge",
313+
`{"spec":{"updateStrategy": {"type": "RevisionBased", "inactiveRevisionDeletionGracePeriodSeconds": 0}}}`)).
314+
To(Succeed(), "Error patching istio "+istioName)
315+
316+
Eventually(func(g Gomega) {
317+
list := &v1.IstioRevisionList{}
318+
g.Expect(clPrimary.List(ctx, list)).To(Succeed())
319+
g.Expect(list.Items).To(HaveLen(2))
320+
}).Should(Succeed())
321+
322+
// Find the latest rev
323+
// Migrate the pods over to the new revision. Both sample app and east/west gateway.
324+
istio := &v1.Istio{}
325+
_, err = common.GetObject(ctx, clPrimary, kube.Key(istioName), istio)
326+
Expect(err).NotTo(HaveOccurred())
327+
328+
Expect(k1.Patch("namespace", "sample", "merge", fmt.Sprintf(`{"metadata":{"labels":{"istio.io/rev":"%s"}}}`, istio.Status.ActiveRevisionName))).
329+
To(Succeed(), "Error patching sample namespace")
330+
331+
Expect(clPrimary.DeleteAllOf(ctx, &corev1.Pod{}, client.InNamespace("sample"))).To(Succeed())
332+
333+
Eventually(func(g Gomega) {
334+
samplePods := &corev1.PodList{}
335+
g.Expect(clPrimary.List(ctx, samplePods, client.InNamespace("sample"))).To(Succeed())
336+
for _, pod := range samplePods.Items {
337+
g.Expect(pod.DeletionTimestamp).To(BeNil())
338+
g.Expect(pod).Should(HaveCondition(corev1.PodReady, metav1.ConditionTrue), "Pod is not Ready in sample namespace; unexpected Condition")
339+
g.Expect(pod.Annotations["istio.io/rev"]).Should(Equal(istio.Status.ActiveRevisionName))
340+
}
341+
}).Should(Succeed())
342+
343+
patch := fmt.Sprintf(
344+
`{"metadata": {"labels":{"istio.io/rev":"%s"}}, "spec": {"template": {"metadata": {"labels": {"istio.io/rev": "%s"}}}}}`,
345+
istio.Status.ActiveRevisionName,
346+
istio.Status.ActiveRevisionName,
347+
)
348+
Log("Patch", patch)
349+
Expect(k1.WithNamespace(controlPlaneNamespace).Patch("deployments", "istio-eastwestgateway", "merge", patch)).To(Succeed(), "Error patching istio-eastwestgateway deployment")
350+
Eventually(func(g Gomega) {
351+
gatewayPods := &corev1.PodList{}
352+
g.Expect(clPrimary.List(ctx, gatewayPods, client.InNamespace(controlPlaneNamespace), client.MatchingLabels{"istio": "eastwestgateway"})).To(Succeed())
353+
for _, pod := range gatewayPods.Items {
354+
g.Expect(pod.DeletionTimestamp).To(BeNil())
355+
g.Expect(pod).Should(HaveCondition(corev1.PodReady, metav1.ConditionTrue), "Pod is not Ready in sample namespace; unexpected Condition")
356+
g.Expect(pod.Annotations["istio.io/rev"]).Should(Equal(istio.Status.ActiveRevisionName))
357+
}
358+
}).Should(Succeed())
359+
})
360+
361+
It("Sees the old revision as no longer in use", func(ctx SpecContext) {
362+
Eventually(func(g Gomega) {
363+
list := &v1.IstioRevisionList{}
364+
g.Expect(clPrimary.List(ctx, list)).To(Succeed())
365+
g.Expect(list.Items).To(HaveLen(2))
366+
367+
oldRevIndex := slices.IndexFunc(list.Items, func(rev v1.IstioRevision) bool {
368+
return rev.Status.GetCondition(v1.IstioRevisionConditionInUse).Status == metav1.ConditionFalse
369+
})
370+
g.Expect(oldRevIndex).ToNot(Equal(-1))
371+
}).Should(Succeed())
372+
})
373+
374+
It("Doesn't delete the old revision", func(ctx SpecContext) {
375+
list := &v1.IstioRevisionList{}
376+
Expect(clPrimary.List(ctx, list)).To(Succeed())
377+
Expect(list.Items).To(HaveLen(2))
378+
})
379+
})
380+
305381
When("Istio CR is deleted in both clusters", func() {
306382
BeforeEach(func() {
307383
Expect(k1.WithNamespace(controlPlaneNamespace).Delete("istio", istioName)).To(Succeed(), "primary Istio CR failed to be deleted")

0 commit comments

Comments
 (0)