@@ -19,6 +19,7 @@ package multicluster
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "slices"
22
23
"time"
23
24
24
25
v1 "github.com/istio-ecosystem/sail-operator/api/v1"
@@ -302,6 +303,81 @@ spec:
302
303
})
303
304
})
304
305
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
+
305
381
When ("Istio CR is deleted in both clusters" , func () {
306
382
BeforeEach (func () {
307
383
Expect (k1 .WithNamespace (controlPlaneNamespace ).Delete ("istio" , istioName )).To (Succeed (), "primary Istio CR failed to be deleted" )
0 commit comments