mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 22:41:35 +02:00
Use unified type for the namespaced object names
This commit is contained in:
@@ -29,8 +29,8 @@ type Controller struct {
|
||||
Config
|
||||
opConfig *config.Config
|
||||
logger *logrus.Entry
|
||||
clusters map[spec.ClusterName]*cluster.Cluster
|
||||
stopChMap map[spec.ClusterName]chan struct{}
|
||||
clusters map[spec.NamespacedName]*cluster.Cluster
|
||||
stopChMap map[spec.NamespacedName]chan struct{}
|
||||
waitCluster sync.WaitGroup
|
||||
|
||||
postgresqlInformer cache.SharedIndexInformer
|
||||
@@ -51,8 +51,8 @@ func New(controllerConfig *Config, operatorConfig *config.Config) *Controller {
|
||||
Config: *controllerConfig,
|
||||
opConfig: operatorConfig,
|
||||
logger: logger.WithField("pkg", "controller"),
|
||||
clusters: make(map[spec.ClusterName]*cluster.Cluster),
|
||||
stopChMap: make(map[spec.ClusterName]chan struct{}),
|
||||
clusters: make(map[spec.NamespacedName]*cluster.Cluster),
|
||||
stopChMap: make(map[spec.NamespacedName]chan struct{}),
|
||||
podCh: make(chan spec.PodEvent),
|
||||
}
|
||||
}
|
||||
|
||||
+3
-10
@@ -55,13 +55,6 @@ func (c *Controller) podWatchFunc(options api.ListOptions) (watch.Interface, err
|
||||
return c.KubeClient.CoreV1Client.Pods(c.PodNamespace).Watch(opts)
|
||||
}
|
||||
|
||||
func PodNameFromMeta(meta v1.ObjectMeta) spec.PodName {
|
||||
return spec.PodName{
|
||||
Namespace: meta.Namespace,
|
||||
Name: meta.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) podAdd(obj interface{}) {
|
||||
pod, ok := obj.(*v1.Pod)
|
||||
if !ok {
|
||||
@@ -70,7 +63,7 @@ func (c *Controller) podAdd(obj interface{}) {
|
||||
|
||||
podEvent := spec.PodEvent{
|
||||
ClusterName: util.PodClusterName(pod),
|
||||
PodName: PodNameFromMeta(pod.ObjectMeta),
|
||||
PodName: util.NameFromMeta(pod.ObjectMeta),
|
||||
CurPod: pod,
|
||||
EventType: spec.PodEventAdd,
|
||||
}
|
||||
@@ -91,7 +84,7 @@ func (c *Controller) podUpdate(prev, cur interface{}) {
|
||||
|
||||
podEvent := spec.PodEvent{
|
||||
ClusterName: util.PodClusterName(curPod),
|
||||
PodName: PodNameFromMeta(curPod.ObjectMeta),
|
||||
PodName: util.NameFromMeta(curPod.ObjectMeta),
|
||||
PrevPod: prevPod,
|
||||
CurPod: curPod,
|
||||
EventType: spec.PodEventUpdate,
|
||||
@@ -108,7 +101,7 @@ func (c *Controller) podDelete(obj interface{}) {
|
||||
|
||||
podEvent := spec.PodEvent{
|
||||
ClusterName: util.PodClusterName(pod),
|
||||
PodName: PodNameFromMeta(pod.ObjectMeta),
|
||||
PodName: util.NameFromMeta(pod.ObjectMeta),
|
||||
CurPod: pod,
|
||||
EventType: spec.PodEventDelete,
|
||||
}
|
||||
|
||||
@@ -41,11 +41,7 @@ func (c *Controller) clusterListFunc(options api.ListOptions) (runtime.Object, e
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Can't cast object to postgresql")
|
||||
}
|
||||
clusterName := spec.ClusterName{
|
||||
Namespace: pg.Metadata.Namespace,
|
||||
Name: pg.Metadata.Name,
|
||||
}
|
||||
|
||||
clusterName := util.NameFromMeta(pg.Metadata)
|
||||
cl := cluster.New(clusterConfig, *pg, c.logger.Logger)
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
@@ -83,10 +79,7 @@ func (c *Controller) postgresqlAdd(obj interface{}) {
|
||||
return
|
||||
}
|
||||
|
||||
clusterName := spec.ClusterName{
|
||||
Namespace: pg.Metadata.Namespace,
|
||||
Name: pg.Metadata.Name,
|
||||
}
|
||||
clusterName := util.NameFromMeta(pg.Metadata)
|
||||
|
||||
_, ok = c.clusters[clusterName]
|
||||
if ok {
|
||||
@@ -123,10 +116,7 @@ func (c *Controller) postgresqlUpdate(prev, cur interface{}) {
|
||||
c.logger.Errorf("Can't cast to postgresql spec")
|
||||
}
|
||||
|
||||
clusterName := spec.ClusterName{
|
||||
Namespace: pgNew.Metadata.Namespace,
|
||||
Name: pgNew.Metadata.Name,
|
||||
}
|
||||
clusterName := util.NameFromMeta(pgNew.Metadata)
|
||||
|
||||
//TODO: Do not update cluster which is currently creating
|
||||
if pgPrev.Metadata.ResourceVersion == pgNew.Metadata.ResourceVersion {
|
||||
@@ -155,10 +145,7 @@ func (c *Controller) postgresqlDelete(obj interface{}) {
|
||||
c.logger.Errorf("Can't cast to postgresql spec")
|
||||
return
|
||||
}
|
||||
clusterName := spec.ClusterName{
|
||||
Namespace: pgCur.Metadata.Namespace,
|
||||
Name: pgCur.Metadata.Name,
|
||||
}
|
||||
clusterName := util.NameFromMeta(pgCur.Metadata)
|
||||
pgCluster, ok := c.clusters[clusterName]
|
||||
if !ok {
|
||||
c.logger.Errorf("Unknown cluster: %s", clusterName)
|
||||
|
||||
+11
-4
@@ -3,7 +3,6 @@ package controller
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
extv1beta "k8s.io/client-go/pkg/apis/extensions/v1beta1"
|
||||
|
||||
@@ -26,7 +25,9 @@ func (c *Controller) makeClusterConfig() cluster.Config {
|
||||
|
||||
func (c *Controller) getOAuthToken() (string, error) {
|
||||
// Temporary getting postgresql-operator secret from the NamespaceDefault
|
||||
credentialsSecret, err := c.KubeClient.Secrets(api.NamespaceDefault).Get(c.opConfig.OAuthTokenSecretName)
|
||||
credentialsSecret, err := c.KubeClient.
|
||||
Secrets(c.opConfig.OAuthTokenSecretName.Namespace).
|
||||
Get(c.opConfig.OAuthTokenSecretName.Name)
|
||||
|
||||
if err != nil {
|
||||
c.logger.Debugf("Oauth token secret name: %s", c.opConfig.OAuthTokenSecretName)
|
||||
@@ -75,15 +76,19 @@ func (c *Controller) createTPR() error {
|
||||
}
|
||||
|
||||
func (c *Controller) getInfrastructureRoles() (result map[string]spec.PgUser, err error) {
|
||||
if c.opConfig.InfrastructureRolesSecretName == "" {
|
||||
if c.opConfig.InfrastructureRolesSecretName == (spec.NamespacedName{}) {
|
||||
// we don't have infrastructure roles defined, bail out
|
||||
return nil, nil
|
||||
}
|
||||
infraRolesSecret, err := c.KubeClient.Secrets(api.NamespaceDefault).Get(c.opConfig.InfrastructureRolesSecretName)
|
||||
|
||||
infraRolesSecret, err := c.KubeClient.
|
||||
Secrets(c.opConfig.InfrastructureRolesSecretName.Namespace).
|
||||
Get(c.opConfig.InfrastructureRolesSecretName.Name)
|
||||
if err != nil {
|
||||
c.logger.Debugf("Infrastructure roles secret name: %s", c.opConfig.InfrastructureRolesSecretName)
|
||||
return nil, fmt.Errorf("Can't get infrastructure roles Secret: %s", err)
|
||||
}
|
||||
|
||||
data := infraRolesSecret.Data
|
||||
result = make(map[string]spec.PgUser)
|
||||
Users:
|
||||
@@ -112,9 +117,11 @@ Users:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if t.Name != "" {
|
||||
result[t.Name] = t
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user