Allow for "*" as placeholder for any namespace
@@ -48,6 +48,15 @@ class K8sInventory():
return False
return True
+ def preprocess_namespace(self, namespace):
+ # Check if namespace is None instead of using "or" as Kubernetes treats
+ # an empty string as the */all wildcard
+ if namespace is None:
+ namespace = "default"
+ if namespace == "*":
+ namespace = ""
+ return namespace
+
def find_namespaces(self):
""" Returns all namespaces.
"""
@@ -65,10 +74,7 @@ class K8sInventory():
def find_deployments(self, namespace=None, labels=None):
""" Find deployments for a namespace (default to "default" namespace).
"""
- # Check if namespace is None instead of using "or" as Kubernetes treats
- # an empty string as the */all wildcard
- if namespace is None:
- namespace = "default"
+ namespace = self.preprocess_namespace(namespace)
return [
item.metadata.name
for item in self.k8s_client.list_deployments(
@@ -80,10 +86,7 @@ class K8sInventory():
def find_pods(self, namespace, selector=None, deployment_name=None):
""" Find pods in a namespace, for a deployment or selector.
"""
- # Check if namespace is None instead of using "or" as Kubernetes treats
- # an empty string as the */all wildcard
- if namespace is None:
- namespace = "default"
+ namespace = self.preprocess_namespace(namespace)
pods = self.k8s_client.list_pods(
namespace=namespace,
selector=selector,
