mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-03 10:15:36 +02:00
Fix resync of the clusters
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user