@@ -74,6 +74,47 @@ func TestInjectRestoreIntentRemovesStaleOptionalAnnotations(t *testing.T) {
7474 require .Equal (t , "backup-ns" , * vct .Spec .DataSourceRef .Namespace )
7575}
7676
77+ func TestInjectRestoreIntentOmitsDataSourceRefNamespaceForSameNamespaceSource (t * testing.T ) {
78+ cluster := & appsv1.Cluster {}
79+ cluster .Name = "test-cluster"
80+ cluster .Namespace = "test-ns"
81+ cluster .Spec .Restore = & appsv1.ClusterRestore {
82+ Source : appsv1.ClusterRestoreSource {
83+ APIGroup : testRestoreSourceAPIGroup ,
84+ Kind : testRestoreSourceKind ,
85+ Name : "backup" ,
86+ Namespace : "test-ns" ,
87+ },
88+ }
89+ vct := & appsv1.PersistentVolumeClaimTemplate {Name : "data" }
90+
91+ injectRestoreIntentToVCT (cluster , "redis" , vct )
92+
93+ require .Equal (t , "test-ns" , vct .Annotations [constant .RestoreSourceNamespaceAnnotationKey ])
94+ require .NotNil (t , vct .Spec .DataSourceRef )
95+ require .Nil (t , vct .Spec .DataSourceRef .Namespace )
96+ }
97+
98+ func TestInjectRestoreIntentOmitsDataSourceRefNamespaceForDefaultNamespaceSource (t * testing.T ) {
99+ cluster := & appsv1.Cluster {}
100+ cluster .Name = "test-cluster"
101+ cluster .Namespace = "test-ns"
102+ cluster .Spec .Restore = & appsv1.ClusterRestore {
103+ Source : appsv1.ClusterRestoreSource {
104+ APIGroup : testRestoreSourceAPIGroup ,
105+ Kind : testRestoreSourceKind ,
106+ Name : "backup" ,
107+ },
108+ }
109+ vct := & appsv1.PersistentVolumeClaimTemplate {Name : "data" }
110+
111+ injectRestoreIntentToVCT (cluster , "redis" , vct )
112+
113+ require .Equal (t , "test-ns" , vct .Annotations [constant .RestoreSourceNamespaceAnnotationKey ])
114+ require .NotNil (t , vct .Spec .DataSourceRef )
115+ require .Nil (t , vct .Spec .DataSourceRef .Namespace )
116+ }
117+
77118func TestClusterRestoreSourceAPIGroupIsRequiredByCRD (t * testing.T ) {
78119 data , err := os .ReadFile ("../../../config/crd/bases/apps.kubeblocks.io_clusters.yaml" )
79120 require .NoError (t , err )
0 commit comments