| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | package kubernetes | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | // filteredNamespaceExists checks if namespace exists in this cluster | 
					
						
							|  |  |  | // according to any `namespace_labels` plugin configuration specified. | 
					
						
							|  |  |  | // Returns true even for namespaces not exposed by plugin configuration, | 
					
						
							|  |  |  | // see namespaceExposed. | 
					
						
							|  |  |  | func (k *Kubernetes) filteredNamespaceExists(namespace string) bool { | 
					
						
							|  |  |  | 	ns, err := k.APIConn.GetNamespaceByName(namespace) | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 	return ns.ObjectMeta.Name == namespace | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | // configuredNamespace returns true when the namespace is exposed through the plugin | 
					
						
							|  |  |  | // `namespaces` configuration. | 
					
						
							|  |  |  | func (k *Kubernetes) configuredNamespace(namespace string) bool { | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 	_, ok := k.Namespaces[namespace] | 
					
						
							|  |  |  | 	if len(k.Namespaces) > 0 && !ok { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return true | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (k *Kubernetes) namespaceExposed(namespace string) bool { | 
					
						
							|  |  |  | 	return k.configuredNamespace(namespace) && k.filteredNamespaceExists(namespace) | 
					
						
							|  |  |  | } |