From ea84f9d577e731d7a5a69a2875f0336223535e56 Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Tue, 6 Feb 2018 15:09:00 +0100 Subject: [PATCH] Rename the configmap 'namespace' entry to avoid confusion with the map's owm namespace --- pkg/cluster/resources.go | 2 +- pkg/controller/controller.go | 4 ++-- pkg/controller/node.go | 2 +- pkg/controller/pod.go | 4 ++-- pkg/controller/postgresql.go | 4 ++-- pkg/controller/status.go | 6 +++--- pkg/util/config/config.go | 3 ++- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/cluster/resources.go b/pkg/cluster/resources.go index 37b342b45..4f770aaff 100644 --- a/pkg/cluster/resources.go +++ b/pkg/cluster/resources.go @@ -110,7 +110,7 @@ func (c *Cluster) preScaleDown(newStatefulSet *v1beta1.StatefulSet) error { } podName := fmt.Sprintf("%s-0", c.Statefulset.Name) - masterCandidatePod, err := c.KubeClient.Pods(c.OpConfig.Namespace).Get(podName, metav1.GetOptions{}) + masterCandidatePod, err := c.KubeClient.Pods(c.OpConfig.WatchedNamespace).Get(podName, metav1.GetOptions{}) if err != nil { return fmt.Errorf("could not get master candidate pod: %v", err) } diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 5e1638e24..0986e1a28 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -97,8 +97,8 @@ func (c *Controller) initOperatorConfig() { c.logger.Infoln("no ConfigMap specified. Loading default values") } - if configMapData["namespace"] == "" { // Namespace in ConfigMap has priority over env var - configMapData["namespace"] = c.config.Namespace + if configMapData["watched_namespace"] == "" { // Namespace in ConfigMap has priority over env var + configMapData["watched_namespace"] = c.config.Namespace } if c.config.NoDatabaseAccess { configMapData["enable_database_access"] = "false" diff --git a/pkg/controller/node.go b/pkg/controller/node.go index 98e8f288f..a4a558a2c 100644 --- a/pkg/controller/node.go +++ b/pkg/controller/node.go @@ -80,7 +80,7 @@ func (c *Controller) moveMasterPodsOffNode(node *v1.Node) { opts := metav1.ListOptions{ LabelSelector: labels.Set(c.opConfig.ClusterLabels).String(), } - podList, err := c.KubeClient.Pods(c.opConfig.Namespace).List(opts) + podList, err := c.KubeClient.Pods(c.opConfig.WatchedNamespace).List(opts) if err != nil { c.logger.Errorf("could not fetch list of the pods: %v", err) return diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go index 24b9f8687..070e6da2d 100644 --- a/pkg/controller/pod.go +++ b/pkg/controller/pod.go @@ -17,7 +17,7 @@ func (c *Controller) podListFunc(options metav1.ListOptions) (runtime.Object, er TimeoutSeconds: options.TimeoutSeconds, } - return c.KubeClient.Pods(c.opConfig.Namespace).List(opts) + return c.KubeClient.Pods(c.opConfig.WatchedNamespace).List(opts) } func (c *Controller) podWatchFunc(options metav1.ListOptions) (watch.Interface, error) { @@ -27,7 +27,7 @@ func (c *Controller) podWatchFunc(options metav1.ListOptions) (watch.Interface, TimeoutSeconds: options.TimeoutSeconds, } - return c.KubeClient.Pods(c.opConfig.Namespace).Watch(opts) + return c.KubeClient.Pods(c.opConfig.WatchedNamespace).Watch(opts) } func (c *Controller) dispatchPodEvent(clusterName spec.NamespacedName, event spec.PodEvent) { diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index 96b2052b5..25b4617a8 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -46,7 +46,7 @@ func (c *Controller) clusterListFunc(options metav1.ListOptions) (runtime.Object req := c.KubeClient.CRDREST. Get(). - Namespace(c.opConfig.Namespace). + Namespace(c.opConfig.WatchedNamespace). Resource(constants.CRDResource). VersionedParams(&options, metav1.ParameterCodec) @@ -110,7 +110,7 @@ func (c *Controller) clusterWatchFunc(options metav1.ListOptions) (watch.Interfa options.Watch = true r, err := c.KubeClient.CRDREST. Get(). - Namespace(c.opConfig.Namespace). + Namespace(c.opConfig.WatchedNamespace). Resource(constants.CRDResource). VersionedParams(&options, metav1.ParameterCodec). FieldsSelectorParam(nil). diff --git a/pkg/controller/status.go b/pkg/controller/status.go index bc9480e36..6aef0347c 100644 --- a/pkg/controller/status.go +++ b/pkg/controller/status.go @@ -16,7 +16,7 @@ import ( // ClusterStatus provides status of the cluster func (c *Controller) ClusterStatus(team, cluster string) (*spec.ClusterStatus, error) { clusterName := spec.NamespacedName{ - Namespace: c.opConfig.Namespace, + Namespace: c.opConfig.WatchedNamespace, Name: team + "-" + cluster, } @@ -92,7 +92,7 @@ func (c *Controller) GetStatus() *spec.ControllerStatus { // ClusterLogs dumps cluster ring logs func (c *Controller) ClusterLogs(team, name string) ([]*spec.LogEntry, error) { clusterName := spec.NamespacedName{ - Namespace: c.opConfig.Namespace, + Namespace: c.opConfig.WatchedNamespace, Name: team + "-" + name, } @@ -214,7 +214,7 @@ func (c *Controller) WorkerStatus(workerID uint32) (*spec.WorkerStatus, error) { // ClusterHistory dumps history of cluster changes func (c *Controller) ClusterHistory(team, name string) ([]*spec.Diff, error) { clusterName := spec.NamespacedName{ - Namespace: c.opConfig.Namespace, + Namespace: c.opConfig.WatchedNamespace, Name: team + "-" + name, } diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index e0a520b08..3253d6288 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -6,6 +6,7 @@ import ( "time" "fmt" + "github.com/zalando-incubator/postgres-operator/pkg/spec" ) @@ -66,7 +67,7 @@ type Config struct { Resources Auth Scalyr - Namespace string `name:"namespace"` + WatchedNamespace string `name:"watched_namespace"` EtcdHost string `name:"etcd_host" default:"etcd-client.default.svc.cluster.local:2379"` DockerImage string `name:"docker_image" default:"registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4"` ServiceAccountName string `name:"service_account_name" default:"operator"`