Warn if the watched namespace does not exist

This commit is contained in:
Sergey Dudoladov 2018-02-07 17:43:05 +01:00
parent 74fa7b9492
commit de2a028592
2 changed files with 12 additions and 0 deletions

View File

@ -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())

View File

@ -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()