Skip to content

Commit 84b6f5b

Browse files
authored
Merge pull request #3730 from olamilekan000/fix-bug-when-deleting-cachedresource-with-no-existing-reosurce
fix bug when trying to delete a cached resource
2 parents 8dae1f5 + f5fc00a commit 84b6f5b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/reconciler/cache/cachedresources/cachedresources_reconcile_replication.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ func (r *replication) reconcile(ctx context.Context, cachedResource *cachev1alph
7272
controller := r.controllerRegistry.get(controllerName)
7373
// We setup controller even if we are deleting. This is to ensure that we can purge the cache.
7474
// If for some reason was dead, we will recreate it.
75+
danglingResources := cachedResource.Status.ResourceCounts != nil && cachedResource.Status.ResourceCounts.Cache > 0
7576
if controller == nil {
77+
if cachedResource.DeletionTimestamp != nil && !danglingResources {
78+
cachedResource.Status.Phase = cachev1alpha1.CachedResourcePhaseDeleted
79+
return reconcileStatusStopAndRequeue, nil
80+
}
81+
7682
// Global informer is based on the CachedResource type and we construct index based on the schema labels.
7783
controllerCtx, cancel := context.WithCancel(ctx)
7884

@@ -140,7 +146,6 @@ func (r *replication) reconcile(ctx context.Context, cachedResource *cachev1alph
140146
// Check if we need to wait for cleaning. This can be few cases:
141147
// 1. We are in deleting phase, but nothing to delete - we are good.
142148
// 2. We are in deleting phase, and there is something to delete - we need to wait.
143-
danglingResources := cachedResource.Status.ResourceCounts != nil && cachedResource.Status.ResourceCounts.Cache > 0
144149

145150
switch {
146151
case cachedResource.Status.Phase == cachev1alpha1.CachedResourcePhaseDeleting && danglingResources:

0 commit comments

Comments
 (0)