@@ -107,9 +107,8 @@ var _ = Describe("InstanceSet Controller", func() {
107107 ).Should (Succeed ())
108108 }
109109
110- mockPodReady := func (podNames ... string ) [] * corev1. Pod {
110+ mockPodReady := func (podNames ... string ) {
111111 By ("mock pods ready" )
112- pods := make ([]* corev1.Pod , 0 )
113112 for _ , podName := range podNames {
114113 podKey := types.NamespacedName {
115114 Namespace : itsObj .Namespace ,
@@ -133,10 +132,8 @@ var _ = Describe("InstanceSet Controller", func() {
133132 Image : pod .Spec .Containers [0 ].Image ,
134133 },
135134 }
136- pods = append (pods , pod )
137135 })()).Should (Succeed ())
138136 }
139- return pods
140137 }
141138
142139 Context ("reconciliation" , func () {
@@ -627,173 +624,6 @@ var _ = Describe("InstanceSet Controller", func() {
627624 g .Expect (parameters ).Should (HaveKeyWithValue ("foo" , "bar" ))
628625 }).Should (Succeed ())
629626 })
630-
631- It ("restart" , func () {
632- createITSObj (itsName , func (f * testapps.MockInstanceSetFactory ) {
633- f .SetInstanceUpdateStrategy (& workloads.InstanceUpdateStrategy {
634- Type : kbappsv1 .RollingUpdateStrategyType ,
635- }).AddConfigs ([]workloads.ConfigTemplate {
636- {
637- Name : "server" ,
638- ConfigHash : ptr .To ("123456" ),
639- },
640- {
641- Name : "logging" ,
642- ConfigHash : ptr .To ("654321" ),
643- },
644- }... )
645- })
646-
647- pods := mockPodReady (fmt .Sprintf ("%s-0" , itsObj .Name ))
648- Expect (pods ).Should (HaveLen (1 ))
649-
650- By ("check the init instance status" )
651- Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
652- g .Expect (its .Status .InstanceStatus ).Should (HaveLen (1 ))
653- g .Expect (its .Status .InstanceStatus [0 ]).Should (Equal (workloads.InstanceStatus {
654- PodName : fmt .Sprintf ("%s-0" , itsObj .Name ),
655- Configs : []workloads.InstanceConfigStatus {
656- {
657- Name : "server" ,
658- ConfigHash : ptr .To ("123456" ),
659- },
660- {
661- Name : "logging" ,
662- ConfigHash : ptr .To ("654321" ),
663- },
664- },
665- }))
666- })).Should (Succeed ())
667-
668- By ("update configs to restart" )
669- Expect (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
670- its .Spec .Configs [1 ].ConfigHash = ptr .To ("abcdef" )
671- its .Spec .Configs [1 ].Restart = ptr .To (true )
672- })()).ShouldNot (HaveOccurred ())
673-
674- By ("check the instance status updated" )
675- Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
676- g .Expect (its .Status .InstanceStatus ).Should (HaveLen (1 ))
677- g .Expect (its .Status .InstanceStatus [0 ]).Should (Equal (workloads.InstanceStatus {
678- PodName : fmt .Sprintf ("%s-0" , itsObj .Name ),
679- Configs : []workloads.InstanceConfigStatus {
680- {
681- Name : "server" ,
682- ConfigHash : ptr .To ("123456" ),
683- },
684- {
685- Name : "logging" ,
686- ConfigHash : ptr .To ("abcdef" ),
687- },
688- },
689- }))
690- })).Should (Succeed ())
691-
692- By ("check the instance restarted" )
693- podKey := client .ObjectKeyFromObject (pods [0 ])
694- Eventually (testapps .CheckObj (& testCtx , podKey , func (g Gomega , pod * corev1.Pod ) {
695- // g.Expect(pod.UID).ShouldNot(Equal(pods[0].UID)) TODO: impl
696- })).Should (Succeed ())
697- })
698-
699- It ("reconfigure and restart" , func () {
700- By ("mock reconfigure action calls" )
701- var (
702- reconfigure string
703- parameters map [string ]string
704- )
705- testapps .MockKBAgentClient (func (recorder * kbacli.MockClientMockRecorder ) {
706- recorder .Action (gomock .Any (), gomock .Any ()).DoAndReturn (func (ctx context.Context , req kbaproto.ActionRequest ) (kbaproto.ActionResponse , error ) {
707- if req .Action == "reconfigure" || strings .HasPrefix (req .Action , "udf-reconfigure" ) {
708- reconfigure = req .Action
709- parameters = req .Parameters
710- }
711- return kbaproto.ActionResponse {}, nil
712- }).AnyTimes ()
713- })
714-
715- createITSObj (itsName , func (f * testapps.MockInstanceSetFactory ) {
716- f .SetInstanceUpdateStrategy (& workloads.InstanceUpdateStrategy {
717- Type : kbappsv1 .RollingUpdateStrategyType ,
718- }).AddConfigs ([]workloads.ConfigTemplate {
719- {
720- Name : "server" ,
721- ConfigHash : ptr .To ("123456" ),
722- },
723- {
724- Name : "logging" ,
725- ConfigHash : ptr .To ("654321" ),
726- },
727- }... )
728- })
729-
730- pods := mockPodReady (fmt .Sprintf ("%s-0" , itsObj .Name ))
731- Expect (pods ).Should (HaveLen (1 ))
732-
733- By ("check the init instance status" )
734- Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
735- g .Expect (its .Status .InstanceStatus ).Should (HaveLen (1 ))
736- g .Expect (its .Status .InstanceStatus [0 ]).Should (Equal (workloads.InstanceStatus {
737- PodName : fmt .Sprintf ("%s-0" , itsObj .Name ),
738- Configs : []workloads.InstanceConfigStatus {
739- {
740- Name : "server" ,
741- ConfigHash : ptr .To ("123456" ),
742- },
743- {
744- Name : "logging" ,
745- ConfigHash : ptr .To ("654321" ),
746- },
747- },
748- }))
749- })).Should (Succeed ())
750-
751- By ("check the reconfigure action NOT called" )
752- Eventually (func (g Gomega ) {
753- g .Expect (reconfigure ).Should (BeEmpty ())
754- g .Expect (parameters ).Should (BeNil ())
755- }).Should (Succeed ())
756-
757- By ("update configs to reconfigure and restart" )
758- Expect (testapps .GetAndChangeObj (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
759- its .Spec .Configs [1 ].ConfigHash = ptr .To ("abcdef" )
760- its .Spec .Configs [1 ].Restart = ptr .To (true )
761- its .Spec .Configs [1 ].Reconfigure = testapps .NewLifecycleAction ("reconfigure" )
762- its .Spec .Configs [1 ].ReconfigureActionName = ""
763- its .Spec .Configs [1 ].Parameters = map [string ]string {"foo" : "bar" }
764- })()).ShouldNot (HaveOccurred ())
765-
766- By ("check the instance status updated" )
767- Eventually (testapps .CheckObj (& testCtx , itsKey , func (g Gomega , its * workloads.InstanceSet ) {
768- g .Expect (its .Status .InstanceStatus ).Should (HaveLen (1 ))
769- g .Expect (its .Status .InstanceStatus [0 ]).Should (Equal (workloads.InstanceStatus {
770- PodName : fmt .Sprintf ("%s-0" , itsObj .Name ),
771- Configs : []workloads.InstanceConfigStatus {
772- {
773- Name : "server" ,
774- ConfigHash : ptr .To ("123456" ),
775- },
776- {
777- Name : "logging" ,
778- ConfigHash : ptr .To ("abcdef" ),
779- },
780- },
781- }))
782- })).Should (Succeed ())
783-
784- By ("check the reconfigure action call" )
785- Eventually (func (g Gomega ) {
786- g .Expect (reconfigure ).Should (Equal ("reconfigure" ))
787- g .Expect (parameters ).ShouldNot (BeNil ())
788- g .Expect (parameters ).Should (HaveKeyWithValue ("foo" , "bar" ))
789- }).Should (Succeed ())
790-
791- By ("check the instance restarted" )
792- podKey := client .ObjectKeyFromObject (pods [0 ])
793- Eventually (testapps .CheckObj (& testCtx , podKey , func (g Gomega , pod * corev1.Pod ) {
794- // g.Expect(pod.UID).ShouldNot(Equal(pods[0].UID)) TODO: impl
795- })).Should (Succeed ())
796- })
797627 })
798628
799629 Context ("pod naming rule" , func () {
0 commit comments