Set informer resync period in an equivalent fashion like k8s
Informers will resync every 12 to 24 hours.
package controller
import (
+ "math/rand"
"sync"
"time"
@@ -30,9 +31,8 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
- "kubevirt.io/kubevirt/pkg/kubecli"
-
kubev1 "kubevirt.io/kubevirt/pkg/api/v1"
+ "kubevirt.io/kubevirt/pkg/kubecli"
"kubevirt.io/kubevirt/pkg/log"
)
@@ -67,7 +67,8 @@ func NewKubeInformerFactory(restClient *rest.RESTClient, clientSet kubecli.Kubev
return &kubeInformerFactory{
restClient: restClient,
clientSet: clientSet,
- defaultResync: 0,
+ // Resulting resync period will be between 12 and 24 hours, like the default for k8s
+ defaultResync: resyncPeriod(12 * time.Hour),
informers: make(map[string]cache.SharedIndexInformer),
startedInformers: make(map[string]bool),
}
@@ -142,3 +143,9 @@ func (f *kubeInformerFactory) KubeVirtPod() cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(lw, &k8sv1.Pod{}, f.defaultResync, cache.Indexers{})
})
}
+
+// resyncPeriod computes the time interval a shared informer waits before resyncing with the api server
+func resyncPeriod(minResyncPeriod time.Duration) time.Duration {
+ factor := rand.Float64() + 1
+ return time.Duration(float64(minResyncPeriod.Nanoseconds()) * factor)
+}
