self,
namespace,
cluster_uuid,
+ labels,
):
"""
Create a namespace in a specific cluster
- :param namespace: namespace to be created
+ :param namespace: Namespace to be created
:param cluster_uuid: K8s cluster uuid used to retrieve kubeconfig
+ :param labels: Dictionary with labels for the new namespace
:returns: None
"""
paths, env = self._init_paths_env(
kubectl = Kubectl(config_file=paths["kube_config"])
await kubectl.create_namespace(
name=namespace,
+ labels=labels,
)
async def delete_namespace(
delay=1,
fallback=Exception("Failed creating the namespace"),
)
- async def create_namespace(self, name: str):
+ async def create_namespace(self, name: str, labels: dict = None):
"""
Create a namespace
:param: name: Name of the namespace to be created
+ :param: labels: Dictionary with labels for the new namespace
"""
v1_core = self.clients[CORE_CLIENT]
- metadata = V1ObjectMeta(name=name)
+ metadata = V1ObjectMeta(name=name, labels=labels)
namespace = V1Namespace(
metadata=metadata,
)
def setUp(self, mock_load_kube_config):
super(CreateNamespaceClass, self).setUp()
self.namespace = "osm"
+ self.labels = {"key": "value"}
self.kubectl = Kubectl()
@asynctest.fail_on(active_handles=True)
self,
mock_create_namespace,
):
- metadata = V1ObjectMeta(name=self.namespace)
+ metadata = V1ObjectMeta(name=self.namespace, labels=self.labels)
+ namespace = V1Namespace(
+ metadata=metadata,
+ )
+ await self.kubectl.create_namespace(
+ name=self.namespace,
+ labels=self.labels,
+ )
+ mock_create_namespace.assert_called_once_with(namespace)
+
+ async def test_namespace_is_created_default_labels(
+ self,
+ mock_create_namespace,
+ ):
+ metadata = V1ObjectMeta(name=self.namespace, labels=None)
namespace = V1Namespace(
metadata=metadata,
)