@@ -35,6 +35,7 @@ import (
3535 testclocks "k8s.io/utils/clock/testing"
3636 "sigs.k8s.io/controller-runtime/pkg/client"
3737
38+ kbappsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
3839 dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
3940 "github.com/apecloud/kubeblocks/pkg/constant"
4041 dprestore "github.com/apecloud/kubeblocks/pkg/dataprotection/restore"
@@ -483,10 +484,10 @@ var _ = Describe("Restore Controller test", func() {
483484 })
484485
485486 Context ("test postReady stage" , func () {
486- var _ * testdp.BackupClusterInfo
487+ var backupClusterInfo * testdp.BackupClusterInfo
487488 BeforeEach (func () {
488489 By ("fake a new cluster" )
489- _ = testdp .NewFakeCluster (& testCtx )
490+ backupClusterInfo = testdp .NewFakeCluster (& testCtx )
490491 })
491492
492493 It ("test post ready actions" , func () {
@@ -580,6 +581,7 @@ var _ = Describe("Restore Controller test", func() {
580581 })).Should (Succeed ())
581582
582583 })
584+
583585 It ("test parameters env" , func () {
584586 By ("set schema and parameters in actionSet" )
585587 testdp .MockActionSetWithSchema (& testCtx , actionSet )
@@ -602,6 +604,56 @@ var _ = Describe("Restore Controller test", func() {
602604 By ("expect parameters env in restore jobs" )
603605 checkJobParametersEnv (restore )
604606 })
607+
608+ It ("respects DoReadyRestoreAfterClusterRunning annotation" , func () {
609+ By ("set annotation for actionset" )
610+ Expect (testapps .ChangeObj (& testCtx , actionSet , func (set * dpv1alpha1.ActionSet ) {
611+ set .Spec .Restore .PrepareData = nil
612+ if set .Annotations == nil {
613+ set .Annotations = make (map [string ]string )
614+ }
615+ set .Annotations [constant .DoReadyRestoreAfterClusterRunningAnnotationKey ] = "true"
616+ })).Should (Succeed ())
617+
618+ By ("create restore cr" )
619+ matchLabels := map [string ]string {
620+ constant .AppInstanceLabelKey : testdp .ClusterName ,
621+ }
622+ restore := initResourcesAndWaitRestore (true , false , false , "" , dpv1alpha1 .RestorePhaseRunning ,
623+ func (f * testdp.MockRestoreFactory ) {
624+ f .
625+ SetConnectCredential (testdp .ClusterName ).
626+ SetJobActionConfig (matchLabels ).
627+ SetExecActionConfig (matchLabels ).
628+ SetLabels (matchLabels )
629+ }, nil )
630+
631+ By ("check event fired" )
632+ Eventually (func () bool {
633+ eventList := & corev1.EventList {}
634+ err := k8sClient .List (ctx , eventList , client .InNamespace (backupClusterInfo .Cluster .Namespace ))
635+ if err != nil {
636+ return false
637+ }
638+ for _ , e := range eventList .Items {
639+ if e .Reason == dprestore .ReasonWaitForClusterRunning && e .InvolvedObject .Name == restore .Name {
640+ return true
641+ }
642+ }
643+ return false
644+
645+ }).Should (BeTrue ())
646+
647+ By ("mock cluster running" )
648+ Expect (testapps .ChangeObjStatus (& testCtx , backupClusterInfo .Cluster , func () {
649+ backupClusterInfo .Cluster .Status .Phase = kbappsv1 .RunningClusterPhase
650+ })).Should (Succeed ())
651+
652+ By ("check job created" )
653+ Eventually (testapps .List (& testCtx , generics .JobSignature ,
654+ client.MatchingLabels {dprestore .DataProtectionRestoreLabelKey : restore .Name },
655+ client .InNamespace (testCtx .DefaultNamespace ))).Should (HaveLen (2 ))
656+ })
605657 })
606658
607659 Context ("test cross namespace" , func () {
0 commit comments