diff --git a/cmd/main.go b/cmd/main.go index 0ac5817bb..0805e08b4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -37,7 +37,10 @@ func init() { if configMapRawName != "" { operatorNamespace := string(operatorNamespaceBytes) + config.Namespace = operatorNamespace + namespacedConfigMapName := operatorNamespace + "/" + configMapRawName + log.Printf("Looking for the operator configmap at the same namespace the operator resides. Fully qualified configmap name: %v", namespacedConfigMapName) err := config.ConfigMapName.Decode(namespacedConfigMapName) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index c697217e4..00f9bb21c 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -105,8 +105,13 @@ func (c *Controller) initOperatorConfig() { } if configMapData["watched_namespace"] == "" { - c.logger.Infoln("No namespace to watch specified. Fall back to watching the 'default' namespace.") - configMapData["watched_namespace"] = v1.NamespaceDefault + c.logger.Infof("No namespace to watch specified. By convention, the operator falls back to watching the namespace it is deployed to: '%v' \n", c.config.Namespace) + configMapData["watched_namespace"] = c.config.Namespace + } + + _, err := c.KubeClient.ServiceAccounts(configMapData["watched_namespace"]).Get("operator", metav1.GetOptions{}) + if err != nil { + c.logger.Warnf("Cannot find the 'operator' service account in the watched namepsace %q. Pods will not be able to start. Error: %v", c.opConfig.WatchedNamespace, err) } if c.config.NoDatabaseAccess { diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index 1b4dc9a00..5db47c76b 100644 --- a/pkg/util/k8sutil/k8sutil.go +++ b/pkg/util/k8sutil/k8sutil.go @@ -32,6 +32,7 @@ type KubernetesClient struct { v1core.PersistentVolumeClaimsGetter v1core.ConfigMapsGetter v1core.NodesGetter + v1core.ServiceAccountsGetter v1beta1.StatefulSetsGetter policyv1beta1.PodDisruptionBudgetsGetter apiextbeta1.CustomResourceDefinitionsGetter @@ -72,6 +73,7 @@ func NewFromConfig(cfg *rest.Config) (KubernetesClient, error) { kubeClient.ServicesGetter = client.CoreV1() kubeClient.EndpointsGetter = client.CoreV1() kubeClient.SecretsGetter = client.CoreV1() + kubeClient.ServiceAccountsGetter = client.CoreV1() kubeClient.ConfigMapsGetter = client.CoreV1() kubeClient.PersistentVolumeClaimsGetter = client.CoreV1() kubeClient.PersistentVolumesGetter = client.CoreV1()