github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/controller/registry/reconciler/grpc_polling.go (about) 1 package reconciler 2 3 import ( 4 "time" 5 6 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 7 8 "github.com/operator-framework/api/pkg/operators/v1alpha1" 9 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer" 10 ) 11 12 // SyncRegistryUpdateInterval returns a duration to use when requeuing the catalog source for reconciliation. 13 // This ensures that the catalog is being synced on the correct time interval based on its spec. 14 // Note: this function assumes the catalog has an update strategy set. 15 func SyncRegistryUpdateInterval(source *v1alpha1.CatalogSource, now time.Time) time.Duration { 16 pollingInterval := source.Spec.UpdateStrategy.Interval.Duration 17 latestPoll := source.Status.LatestImageRegistryPoll 18 creationTimestamp := source.CreationTimestamp.Time 19 20 // Resync before next default sync if the polling interval is less than the default 21 if pollingInterval <= queueinformer.DefaultResyncPeriod { 22 return pollingInterval 23 } 24 // Resync based on the delta between the default sync and the actual last poll if the interval is greater than the default 25 return defaultOr(latestPoll, pollingInterval, creationTimestamp, now) 26 } 27 28 // defaultOr returns either the default resync period or the time remaining until the next poll is due, whichever is smaller. 29 // For example, if the polling interval is 40 minutes, OLM will sync after ~30 minutes and see that the next sync 30 // for this catalog should be in 10 minutes, sooner than the default 15 minutes, and return 10 minutes. 31 func defaultOr(latestPoll *metav1.Time, pollingInterval time.Duration, creationTimestamp time.Time, now time.Time) time.Duration { 32 if latestPoll.IsZero() { 33 latestPoll = &metav1.Time{Time: creationTimestamp} 34 } 35 36 remaining := latestPoll.Add(pollingInterval).Sub(now) 37 // sync ahead of the default interval in the case where now + default sync is after the last sync plus the interval 38 if remaining < queueinformer.DefaultResyncPeriod { 39 return remaining 40 } 41 // return the default sync period otherwise: the next sync cycle will check again 42 return queueinformer.DefaultResyncPeriod 43 }