Fix resync of the clusters

This commit is contained in:
Murat Kabilov
2017-06-08 11:51:48 +02:00
committed by GitHub
parent bdc2db97ac
commit e104a67260
5 changed files with 32 additions and 4 deletions
+22
View File
@@ -3,6 +3,8 @@ package controller
import (
"fmt"
"reflect"
"sync/atomic"
"time"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/meta"
@@ -18,6 +20,19 @@ import (
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
)
func (c *Controller) clusterResync(stopCh <-chan struct{}) {
ticker := time.NewTicker(c.opConfig.ResyncPeriod)
for {
select {
case <-ticker.C:
c.clusterListFunc(api.ListOptions{ResourceVersion: "0"})
case <-stopCh:
return
}
}
}
func (c *Controller) clusterListFunc(options api.ListOptions) (runtime.Object, error) {
c.logger.Info("Getting list of currently running clusters")
@@ -37,6 +52,11 @@ func (c *Controller) clusterListFunc(options api.ListOptions) (runtime.Object, e
return nil, fmt.Errorf("could not extract list of postgresql objects: %v", err)
}
if time.Now().Unix()-atomic.LoadInt64(&c.lastClusterSyncTime) <= int64(c.opConfig.ResyncPeriod.Seconds()) {
c.logger.Debugln("skipping resync of clusters")
return object, err
}
var activeClustersCnt, failedClustersCnt int
for _, obj := range objList {
pg, ok := obj.(*spec.Postgresql)
@@ -63,6 +83,8 @@ func (c *Controller) clusterListFunc(options api.ListOptions) (runtime.Object, e
c.logger.Infof("No clusters running")
}
atomic.StoreInt64(&c.lastClusterSyncTime, time.Now().Unix())
return object, err
}