From 16a710a99a14eac4cb6dacc2d40d3c3b6a53cc5b Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Thu, 31 May 2018 18:26:36 +0200 Subject: [PATCH] Avoid possible skipping SYNC events. OB1 bug in the condition deciding whether to sync. --- pkg/controller/postgresql.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index c89a2473a..cb689b70a 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -39,6 +39,8 @@ func (c *Controller) clusterResync(stopCh <-chan struct{}, wg *sync.WaitGroup) { } } +// TODO: make a separate function to be called from InitSharedInformers +// clusterListFunc obtains a list of all PostgreSQL clusters and runs sync when necessary func (c *Controller) clusterListFunc(options metav1.ListOptions) (runtime.Object, error) { var list spec.PostgresqlList var activeClustersCnt, failedClustersCnt int @@ -58,7 +60,9 @@ func (c *Controller) clusterListFunc(options metav1.ListOptions) (runtime.Object c.logger.Warningf("could not unmarshal list of clusters: %v", err) } - if time.Now().Unix()-atomic.LoadInt64(&c.lastClusterSyncTime) <= int64(c.opConfig.ResyncPeriod.Seconds()) { + timeFromPreviousSync := time.Now().Unix() - atomic.LoadInt64(&c.lastClusterSyncTime) + if timeFromPreviousSync < int64(c.opConfig.ResyncPeriod.Seconds()) { + c.logger.Infof("not running SYNC, previous sync happened %d seconds ago", timeFromPreviousSync) return &list, err }