Skip to content

Commit

Permalink
UPSTREAM: <carry>: garbage collector monitors syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Oct 26, 2022
1 parent 174e3ad commit 5accbca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/controller/garbagecollector/garbagecollector_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package garbagecollector

import (
"context"
"fmt"
"reflect"
"time"
Expand All @@ -30,9 +31,9 @@ import (
"k8s.io/kubernetes/pkg/controller/garbagecollector/metrics"
)

func (gc *GarbageCollector) Sync(discoveryClient discovery.ServerResourcesInterface, period time.Duration, stopCh <-chan struct{}) {
func (gc *GarbageCollector) ResyncMonitors(ctx context.Context, discoveryClient discovery.ServerResourcesInterface) {
oldResources := make(map[schema.GroupVersionResource]struct{})
wait.Until(func() {
func() {
// Get the current resource list from discovery.
newResources := gc.GetDeletableResources(discoveryClient)

Expand Down Expand Up @@ -98,20 +99,20 @@ func (gc *GarbageCollector) Sync(discoveryClient discovery.ServerResourcesInterf
// informers keep attempting to sync in the background, so retrying doesn't interrupt them.
// the call to resyncMonitors on the reattempt will no-op for resources that still exist.
// note that workers stay paused until we successfully resync.
if !cache.WaitForNamedCacheSync(fmt.Sprintf("%s: garbage collector", gc.clusterName), waitForStopOrTimeout(stopCh, period), gc.dependencyGraphBuilder.IsSynced) {
if !cache.WaitForNamedCacheSync(fmt.Sprintf("%s: garbage collector", gc.clusterName), ctx.Done(), gc.dependencyGraphBuilder.IsSynced) {
utilruntime.HandleError(fmt.Errorf("%s: timed out waiting for dependency graph builder sync during GC sync (attempt %d)", gc.clusterName, attempt))
metrics.GarbageCollectorResourcesSyncError.Inc()
return false, nil
}

// success, break out of the loop
return true, nil
}, stopCh)
}, ctx.Done())

// Finally, keep track of our new state. Do this after all preceding steps
// have succeeded to ensure we'll retry on subsequent syncs if an error
// occurred.
oldResources = newResources
klog.V(2).Infof("%s: synced garbage collector", gc.clusterName)
}, period, stopCh)
}()
}

0 comments on commit 5accbca

Please sign in to comment.