@@ -641,50 +641,78 @@ var _ = Describe("InstanceSet Controller", func() {
641641 })
642642
643643 Context ("pod naming rule" , func () {
644- checkPodOrdinal := func (ordinals []int , exist bool ) {
644+ checkPodOrdinal := func (ordinals []int , checkFunc func ( podKey types. NamespacedName ) ) {
645645 for _ , ordinal := range ordinals {
646646 podKey := types.NamespacedName {
647647 Namespace : itsObj .Namespace ,
648648 Name : fmt .Sprintf ("%v-%v" , itsObj .Name , ordinal ),
649649 }
650- if exist {
651- Eventually (testapps .CheckObjExists (& testCtx , podKey , & corev1.Pod {}, true )).Should (Succeed ())
652- } else {
653- Eventually (testapps .CheckObjExists (& testCtx , podKey , & corev1.Pod {}, false )).Should (Succeed ())
654- }
650+ checkFunc (podKey )
655651 }
656652 }
657653
654+ eventuallyExist := func (podKey types.NamespacedName ) {
655+ Eventually (testapps .CheckObjExists (& testCtx , podKey , & corev1.Pod {}, true )).Should (Succeed ())
656+ }
657+
658+ eventuallyNotExist := func (podKey types.NamespacedName ) {
659+ Eventually (testapps .CheckObjExists (& testCtx , podKey , & corev1.Pod {}, false )).Should (Succeed ())
660+ }
661+
662+ consistentlyExist := func (podKey types.NamespacedName ) {
663+ Consistently (testapps .CheckObjExists (& testCtx , podKey , & corev1.Pod {}, true )).Should (Succeed ())
664+ }
665+
666+ consistentlyNotExist := func (podKey types.NamespacedName ) {
667+ Consistently (testapps .CheckObjExists (& testCtx , podKey , & corev1.Pod {}, false )).Should (Succeed ())
668+ }
669+
658670 It ("works with FlatInstanceOrdinal" , func () {
659671 createITSObj (itsName , func (f * testapps.MockInstanceSetFactory ) {
660672 f .SetFlatInstanceOrdinal (true )
661673 f .SetPodManagementPolicy (appsv1 .ParallelPodManagement )
662674 f .SetReplicas (3 )
663675 })
664676
665- checkPodOrdinal ([]int {0 , 1 , 2 }, true )
677+ checkPodOrdinal ([]int {0 , 1 , 2 }, eventuallyExist )
666678 mockPodReady (itsObj .Name + "-0" , itsObj .Name + "-1" , itsObj .Name + "-2" )
679+ By ("check its status" )
680+ Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
681+ g .Expect (its .Status .Ordinals ).Should (HaveExactElements (int32 (0 ), int32 (1 ), int32 (2 )))
682+ })).Should (Succeed ())
667683
668684 // offline one instance
669- Eventually (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
685+ Expect (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
670686 its .Spec .Replicas = ptr.To [int32 ](2 )
671687 its .Spec .OfflineInstances = []string {itsObj .Name + "-1" }
688+ })()).Should (Succeed ())
689+ checkPodOrdinal ([]int {1 }, eventuallyNotExist )
690+ By ("check its status" )
691+ Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
692+ g .Expect (its .Status .Ordinals ).Should (HaveExactElements (int32 (0 ), int32 (2 )))
672693 })).Should (Succeed ())
673- checkPodOrdinal ([]int {1 }, false )
674694
675695 // scale up
676- Eventually (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
696+ Expect (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
677697 its .Spec .Replicas = ptr.To [int32 ](4 )
678- })).Should (Succeed ())
679- checkPodOrdinal ([]int {0 , 2 , 3 , 4 }, true )
698+ })() ).Should (Succeed ())
699+ checkPodOrdinal ([]int {0 , 2 , 3 , 4 }, eventuallyExist )
680700 mockPodReady (itsObj .Name + "-3" , itsObj .Name + "-4" )
701+ By ("check its status" )
702+ Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
703+ g .Expect (its .Status .Ordinals ).Should (HaveExactElements (int32 (0 ), int32 (2 ), int32 (3 ), int32 (4 )))
704+ })).Should (Succeed ())
681705
682- // delete OfflineInstances will not affect running instance
683- Eventually (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
706+ // delete OfflineInstances will not affect running instances
707+ Expect (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
684708 its .Spec .OfflineInstances = []string {}
709+ })()).Should (Succeed ())
710+ checkPodOrdinal ([]int {0 , 2 , 3 , 4 }, consistentlyExist )
711+ checkPodOrdinal ([]int {1 }, consistentlyNotExist )
712+ By ("check its status" )
713+ Consistently (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
714+ g .Expect (its .Status .Ordinals ).Should (HaveExactElements (int32 (0 ), int32 (2 ), int32 (3 ), int32 (4 )))
685715 })).Should (Succeed ())
686- checkPodOrdinal ([]int {0 , 2 , 3 , 4 }, true )
687- checkPodOrdinal ([]int {1 }, false )
688716 })
689717 })
690718})
0 commit comments