Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Invalidate discovery cache periodically
Browse files Browse the repository at this point in the history
The cluster resource definitions may not be stable throughout the life of the
cluster.

We were already invalidating the cache every time a CRD object was altered and
replaying the CRD changes every 5 minutes.

However, that's not enough because CRD-unrelated changes seem to happen when the
cluster bootstraps.
  • Loading branch information
Alfonso Acosta committed Mar 25, 2019
1 parent 1521741 commit 33abf1d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cluster/kubernetes/cached_disco.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,32 @@ func makeCachedDiscovery(d discovery.DiscoveryInterface, c crd.Interface, shutdo
}

handler := handlerFn(cachedDisco)
store, controller := toolscache.NewInformer(lw, &crdv1beta1.CustomResourceDefinition{}, 5*time.Minute, handler)
store, controller := toolscache.NewInformer(lw, &crdv1beta1.CustomResourceDefinition{}, 0, handler)
go cachedDisco.invalidatePeriodically(shutdown)
go controller.Run(shutdown)
return cachedDisco, store, controller
}

func (d *cachedDiscovery) invalidatePeriodically(shutdown <-chan struct{}) {
// Make the first period shorter since we may be bootstrapping a
// newly-created cluster and the resource definitions may not be
// complete/stable yet.
initialPeriodDuration := 1 * time.Minute
subsequentPeriodsDuration := 5 * initialPeriodDuration
isInitialPeriod := true
ticker := time.NewTicker(initialPeriodDuration)
for {
select {
case <-ticker.C:
if isInitialPeriod {
ticker.Stop()
ticker = time.NewTicker(subsequentPeriodsDuration)
}
isInitialPeriod = false
d.Invalidate()
case <-shutdown:
ticker.Stop()
return
}
}
}

0 comments on commit 33abf1d

Please sign in to comment.