Warn if the watched namespace does not exist
This commit is contained in:
		
							parent
							
								
									74fa7b9492
								
							
						
					
					
						commit
						de2a028592
					
				|  | @ -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()) | ||||
|  |  | |||
|  | @ -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() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue