@@ -302,6 +302,117 @@ func TestReconcilePhase(t *testing.T) {
302302 wantPhase : corev1alpha1 .LogicalClusterPhaseReady ,
303303 wantStatus : reconcileStatusStopAndRequeue ,
304304 },
305+ {
306+ name : "workspace is unavailable due to disappeared logical cluster and shard is alive - recovers when LC reappears" ,
307+ input : & tenancyv1alpha1.Workspace {
308+ ObjectMeta : metav1.ObjectMeta {
309+ Annotations : map [string ]string {
310+ WorkspaceShardHashAnnotationKey : "shard-hash-1" ,
311+ },
312+ },
313+ Spec : tenancyv1alpha1.WorkspaceSpec {
314+ URL : "http://example.com" ,
315+ Cluster : "cluster-1" ,
316+ },
317+ Status : tenancyv1alpha1.WorkspaceStatus {
318+ Phase : corev1alpha1 .LogicalClusterPhaseUnavailable ,
319+ Conditions : []conditionsv1alpha1.Condition {
320+ {
321+ Type : tenancyv1alpha1 .WorkspaceInitialized ,
322+ Status : corev1 .ConditionFalse ,
323+ Severity : conditionsv1alpha1 .ConditionSeverityError ,
324+ Reason : tenancyv1alpha1 .WorkspaceInitializedWorkspaceDisappeared ,
325+ Message : "LogicalCluster cluster-1 not found" ,
326+ },
327+ },
328+ },
329+ },
330+ getLogicalCluster : func (ctx context.Context , cluster logicalcluster.Path ) (* corev1alpha1.LogicalCluster , error ) {
331+ return & corev1alpha1.LogicalCluster {
332+ Status : corev1alpha1.LogicalClusterStatus {
333+ Initializers : []corev1alpha1.LogicalClusterInitializer {},
334+ },
335+ }, nil
336+ },
337+ getShardByHash : func (hash string ) (* corev1alpha1.Shard , error ) {
338+ return & corev1alpha1.Shard {ObjectMeta : metav1.ObjectMeta {Name : "shard-1" }}, nil
339+ },
340+ wantPhase : corev1alpha1 .LogicalClusterPhaseReady ,
341+ wantStatus : reconcileStatusStopAndRequeue ,
342+ wantCondition : conditionsv1alpha1.Condition {
343+ Type : tenancyv1alpha1 .WorkspaceInitialized ,
344+ Status : corev1 .ConditionTrue ,
345+ },
346+ wantRequeue : true ,
347+ },
348+ {
349+ name : "workspace is unavailable due to disappeared logical cluster and shard is alive - requeues when LC still not found" ,
350+ input : & tenancyv1alpha1.Workspace {
351+ ObjectMeta : metav1.ObjectMeta {
352+ Annotations : map [string ]string {
353+ WorkspaceShardHashAnnotationKey : "shard-hash-1" ,
354+ },
355+ },
356+ Spec : tenancyv1alpha1.WorkspaceSpec {
357+ URL : "http://example.com" ,
358+ Cluster : "cluster-1" ,
359+ },
360+ Status : tenancyv1alpha1.WorkspaceStatus {
361+ Phase : corev1alpha1 .LogicalClusterPhaseUnavailable ,
362+ Conditions : []conditionsv1alpha1.Condition {
363+ {
364+ Type : tenancyv1alpha1 .WorkspaceInitialized ,
365+ Status : corev1 .ConditionFalse ,
366+ Severity : conditionsv1alpha1 .ConditionSeverityError ,
367+ Reason : tenancyv1alpha1 .WorkspaceInitializedWorkspaceDisappeared ,
368+ Message : "LogicalCluster cluster-1 not found" ,
369+ },
370+ },
371+ },
372+ },
373+ getLogicalCluster : func (ctx context.Context , cluster logicalcluster.Path ) (* corev1alpha1.LogicalCluster , error ) {
374+ return nil , apierrors .NewNotFound (corev1alpha1 .Resource ("logicalcluster" ), "cluster-1" )
375+ },
376+ getShardByHash : func (hash string ) (* corev1alpha1.Shard , error ) {
377+ return & corev1alpha1.Shard {ObjectMeta : metav1.ObjectMeta {Name : "shard-1" }}, nil
378+ },
379+ wantPhase : corev1alpha1 .LogicalClusterPhaseUnavailable ,
380+ wantStatus : reconcileStatusStopAndRequeue ,
381+ },
382+ {
383+ name : "workspace is unavailable due to disappeared logical cluster and shard is gone - no recovery" ,
384+ input : & tenancyv1alpha1.Workspace {
385+ ObjectMeta : metav1.ObjectMeta {
386+ Annotations : map [string ]string {
387+ WorkspaceShardHashAnnotationKey : "shard-hash-1" ,
388+ },
389+ },
390+ Spec : tenancyv1alpha1.WorkspaceSpec {
391+ URL : "http://example.com" ,
392+ Cluster : "cluster-1" ,
393+ },
394+ Status : tenancyv1alpha1.WorkspaceStatus {
395+ Phase : corev1alpha1 .LogicalClusterPhaseUnavailable ,
396+ Conditions : []conditionsv1alpha1.Condition {
397+ {
398+ Type : tenancyv1alpha1 .WorkspaceInitialized ,
399+ Status : corev1 .ConditionFalse ,
400+ Severity : conditionsv1alpha1 .ConditionSeverityError ,
401+ Reason : tenancyv1alpha1 .WorkspaceInitializedWorkspaceDisappeared ,
402+ Message : "LogicalCluster cluster-1 not found" ,
403+ },
404+ },
405+ },
406+ },
407+ getLogicalCluster : func (ctx context.Context , cluster logicalcluster.Path ) (* corev1alpha1.LogicalCluster , error ) {
408+ return nil , apierrors .NewNotFound (corev1alpha1 .Resource ("logicalcluster" ), "cluster-1" )
409+ },
410+ getShardByHash : func (hash string ) (* corev1alpha1.Shard , error ) {
411+ return nil , apierrors .NewNotFound (corev1alpha1 .Resource ("shard" ), "shard-hash-1" )
412+ },
413+ wantPhase : corev1alpha1 .LogicalClusterPhaseUnavailable ,
414+ wantStatus : reconcileStatusContinue ,
415+ },
305416 } {
306417 t .Run (testCase .name , func (t * testing.T ) {
307418 requeued := false
0 commit comments