introduce Cluster interface

This commit is contained in:
Murat Kabilov
2017-07-13 15:26:22 +02:00
parent 4ec4c71d27
commit 333dfdd640
5 changed files with 48 additions and 23 deletions
+2 -3
View File
@@ -10,7 +10,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"github.com/zalando-incubator/postgres-operator/pkg/cluster"
"github.com/zalando-incubator/postgres-operator/pkg/spec"
"github.com/zalando-incubator/postgres-operator/pkg/util/config"
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
@@ -31,7 +30,7 @@ type Controller struct {
logger *logrus.Entry
clustersMu sync.RWMutex
clusters map[spec.NamespacedName]*cluster.Cluster
clusters map[spec.NamespacedName]spec.Cluster
stopChs map[spec.NamespacedName]chan struct{}
postgresqlInformer cache.SharedIndexInformer
@@ -56,7 +55,7 @@ func New(controllerConfig *Config, operatorConfig *config.Config) *Controller {
Config: *controllerConfig,
opConfig: operatorConfig,
logger: logger.WithField("pkg", "controller"),
clusters: make(map[spec.NamespacedName]*cluster.Cluster),
clusters: make(map[spec.NamespacedName]spec.Cluster),
stopChs: make(map[spec.NamespacedName]chan struct{}),
podCh: make(chan spec.PodEvent),
}
+4 -11
View File
@@ -134,9 +134,7 @@ func (c *Controller) processEvent(obj interface{}) error {
c.clustersMu.Unlock()
if err := cl.Create(); err != nil {
cl.Error = fmt.Errorf("could not create cluster: %v", err)
logger.Errorf("%v", cl.Error)
logger.Errorf("could not create cluster '%s': %v", clusterName, err)
return nil
}
@@ -149,17 +147,14 @@ func (c *Controller) processEvent(obj interface{}) error {
return nil
}
if err := cl.Update(event.NewSpec); err != nil {
cl.Error = fmt.Errorf("could not update cluster: %s", err)
logger.Errorf("%v", cl.Error)
logger.Errorf("could not update cluster '%s': %v", clusterName, err)
return nil
}
cl.Error = nil
logger.Infof("Cluster '%s' has been updated", clusterName)
case spec.EventDelete:
logger.Infof("Deletion of the '%s' cluster started", clusterName)
if !clusterFound {
logger.Errorf("Unknown cluster: %s", clusterName)
logger.Errorf("Cluster '%s' is not found", clusterName)
return nil
}
@@ -191,11 +186,9 @@ func (c *Controller) processEvent(obj interface{}) error {
}
if err := cl.Sync(); err != nil {
cl.Error = fmt.Errorf("could not sync cluster '%s': %v", clusterName, err)
logger.Errorf("%v", cl.Error)
logger.Errorf("%v", "could not sync cluster '%s': %v", clusterName, err)
return nil
}
cl.Error = nil
logger.Infof("Cluster '%s' has been synced", clusterName)
}