@@ -501,8 +501,150 @@ var _ = Describe("Instance Controller", func() {
501501 })
502502
503503 // It("reconfigure", func() {
504- // // TODO
505- // })
504+ It ("reconfigure" , func () {
505+ var (
506+ reconfigure string
507+ parameters map [string ]string
508+ )
509+
510+ testapps .MockKBAgentClient (func (recorder * kbacli.MockClientMockRecorder ) {
511+ recorder .Action (gomock .Any (), gomock .Any ()).DoAndReturn (func (ctx context.Context , req kbagentproto.ActionRequest ) (kbagentproto.ActionResponse , error ) {
512+ if req .Action == "reconfigure" {
513+ reconfigure = req .Action
514+ parameters = req .Parameters
515+ }
516+ return kbagentproto.ActionResponse {}, nil
517+ }).AnyTimes ()
518+ })
519+ defer kbacli .UnsetMockClient ()
520+
521+ createInstObj (instName , func (f * testapps.MockInstanceFactory ) {
522+ f .AddConfigs (
523+ workloads.ConfigTemplate {
524+ Name : "server" ,
525+ Generation : int64 (1 ),
526+ },
527+ workloads.ConfigTemplate {
528+ Name : "logging" ,
529+ Generation : int64 (2 ),
530+ },
531+ )
532+ })
533+
534+ mockPodReady (instObj .Namespace , instObj .Name )
535+
536+ By ("check the init config status" )
537+ Eventually (testapps .CheckObj (& testCtx , instKey , func (g Gomega , inst * workloads.Instance ) {
538+ g .Expect (inst .Status .Configs ).Should (Equal ([]workloads.InstanceConfigStatus {
539+ {Name : "server" , Generation : int64 (1 )},
540+ {Name : "logging" , Generation : int64 (2 )},
541+ }))
542+ })).Should (Succeed ())
543+
544+ By ("check the reconfigure action not called" )
545+ Consistently (func (g Gomega ) {
546+ g .Expect (reconfigure ).Should (BeEmpty ())
547+ g .Expect (parameters ).Should (BeNil ())
548+ }).Should (Succeed ())
549+
550+ By ("update configs" )
551+ Expect (testapps .GetAndChangeObj (& testCtx , instKey , func (inst * workloads.Instance ) {
552+ inst .Spec .Configs [1 ].Generation = 128
553+ inst .Spec .Configs [1 ].Reconfigure = testapps .NewLifecycleAction ("reconfigure" )
554+ inst .Spec .Configs [1 ].Parameters = map [string ]string {"foo" : "bar" }
555+ })()).ShouldNot (HaveOccurred ())
556+
557+ By ("check the config status updated" )
558+ Eventually (testapps .CheckObj (& testCtx , instKey , func (g Gomega , inst * workloads.Instance ) {
559+ g .Expect (inst .Status .Configs ).Should (Equal ([]workloads.InstanceConfigStatus {
560+ {Name : "server" , Generation : int64 (1 )},
561+ {Name : "logging" , Generation : int64 (128 )},
562+ }))
563+ })).Should (Succeed ())
564+
565+ By ("check the reconfigure action call" )
566+ Eventually (func (g Gomega ) {
567+ g .Expect (reconfigure ).Should (Equal ("reconfigure" ))
568+ g .Expect (parameters ).Should (HaveKeyWithValue ("foo" , "bar" ))
569+ }).Should (Succeed ())
570+ })
571+
572+ It ("reconfigure after config removed and added back" , func () {
573+ var (
574+ reconfigure string
575+ parameters map [string ]string
576+ )
577+
578+ testapps .MockKBAgentClient (func (recorder * kbacli.MockClientMockRecorder ) {
579+ recorder .Action (gomock .Any (), gomock .Any ()).DoAndReturn (func (ctx context.Context , req kbagentproto.ActionRequest ) (kbagentproto.ActionResponse , error ) {
580+ if req .Action == "reconfigure" {
581+ reconfigure = req .Action
582+ parameters = req .Parameters
583+ }
584+ return kbagentproto.ActionResponse {}, nil
585+ }).AnyTimes ()
586+ })
587+ defer kbacli .UnsetMockClient ()
588+
589+ createInstObj (instName , func (f * testapps.MockInstanceFactory ) {
590+ f .AddConfigs (
591+ workloads.ConfigTemplate {
592+ Name : "server" ,
593+ Generation : int64 (1 ),
594+ },
595+ workloads.ConfigTemplate {
596+ Name : "logging" ,
597+ Generation : int64 (2 ),
598+ },
599+ )
600+ })
601+
602+ mockPodReady (instObj .Namespace , instObj .Name )
603+
604+ By ("check the init config status" )
605+ Eventually (testapps .CheckObj (& testCtx , instKey , func (g Gomega , inst * workloads.Instance ) {
606+ g .Expect (inst .Status .Configs ).Should (Equal ([]workloads.InstanceConfigStatus {
607+ {Name : "server" , Generation : int64 (1 )},
608+ {Name : "logging" , Generation : int64 (2 )},
609+ }))
610+ })).Should (Succeed ())
611+
612+ By ("remove one config from spec" )
613+ Expect (testapps .GetAndChangeObj (& testCtx , instKey , func (inst * workloads.Instance ) {
614+ inst .Spec .Configs = inst .Spec .Configs [:1 ]
615+ })()).ShouldNot (HaveOccurred ())
616+
617+ By ("check the removed config status pruned" )
618+ Eventually (testapps .CheckObj (& testCtx , instKey , func (g Gomega , inst * workloads.Instance ) {
619+ g .Expect (inst .Status .Configs ).Should (Equal ([]workloads.InstanceConfigStatus {
620+ {Name : "server" , Generation : int64 (1 )},
621+ }))
622+ })).Should (Succeed ())
623+
624+ By ("add the config back with same generation" )
625+ Expect (testapps .GetAndChangeObj (& testCtx , instKey , func (inst * workloads.Instance ) {
626+ inst .Spec .Configs = append (inst .Spec .Configs , workloads.ConfigTemplate {
627+ Name : "logging" ,
628+ Generation : int64 (2 ),
629+ Reconfigure : testapps .NewLifecycleAction ("reconfigure" ),
630+ Parameters : map [string ]string {"foo" : "bar" },
631+ })
632+ })()).ShouldNot (HaveOccurred ())
633+
634+ By ("check the config status restored" )
635+ Eventually (testapps .CheckObj (& testCtx , instKey , func (g Gomega , inst * workloads.Instance ) {
636+ g .Expect (inst .Status .Configs ).Should (Equal ([]workloads.InstanceConfigStatus {
637+ {Name : "server" , Generation : int64 (1 )},
638+ {Name : "logging" , Generation : int64 (2 )},
639+ }))
640+ })).Should (Succeed ())
641+
642+ By ("check the reconfigure action call" )
643+ Eventually (func (g Gomega ) {
644+ g .Expect (reconfigure ).Should (Equal ("reconfigure" ))
645+ g .Expect (parameters ).Should (HaveKeyWithValue ("foo" , "bar" ))
646+ }).Should (Succeed ())
647+ })
506648 //
507649 // It("member join", func() {
508650 // // TODO
0 commit comments