From de2a0285923f46ceb504e98ba6e277d23224ba8b Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Wed, 7 Feb 2018 17:43:05 +0100 Subject: [PATCH] Warn if the watched namespace does not exist --- pkg/controller/controller.go | 10 ++++++++++ pkg/util/k8sutil/k8sutil.go | 2 ++ 2 files changed, 12 insertions(+) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index f905ade50..944033143 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -143,6 +143,16 @@ func (c *Controller) initOperatorConfig() { func (c *Controller) initController() { c.initClients() c.initOperatorConfig() + + // earliest point where we can check if the namespace to watch actually exists + if c.opConfig.WatchedNamespace != v1.NamespaceAll { + _, err := c.KubeClient.Namespaces().Get(c.opConfig.WatchedNamespace, metav1.GetOptions{}) + if err != nil { + c.logger.Warnf("Operator was told to watch the %q namespace but was unable to confirm it existense via Kubernetes API. Falling back to watching all namespaces instead (done automatically by k8s)", c.opConfig.WatchedNamespace) + } + + } + c.initSharedInformers() c.logger.Infof("config: %s", c.opConfig.MustMarshal()) diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index 1b4dc9a00..5f40148c4 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.NamespacesGetter v1beta1.StatefulSetsGetter policyv1beta1.PodDisruptionBudgetsGetter apiextbeta1.CustomResourceDefinitionsGetter @@ -76,6 +77,7 @@ func NewFromConfig(cfg *rest.Config) (KubernetesClient, error) { kubeClient.PersistentVolumeClaimsGetter = client.CoreV1() kubeClient.PersistentVolumesGetter = client.CoreV1() kubeClient.NodesGetter = client.CoreV1() + kubeClient.NamespacesGetter = client.CoreV1() kubeClient.StatefulSetsGetter = client.AppsV1beta1() kubeClient.PodDisruptionBudgetsGetter = client.PolicyV1beta1() kubeClient.RESTClient = client.CoreV1().RESTClient()