From d5d83a4250eebe2e82fcb9986bcc1d3db5610c3d Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 7 Apr 2020 11:08:16 +0000 Subject: [PATCH] adding optional namespace to K8s install Change-Id: Ib433aff72f68f56359917a8a3716e6b798ea330b Signed-off-by: tierno --- n2vc/k8s_conn.py | 4 +++- n2vc/k8s_helm_conn.py | 15 +++++++++++---- n2vc/k8s_juju_conn.py | 6 ++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/n2vc/k8s_conn.py b/n2vc/k8s_conn.py index a82919a..3305ac5 100644 --- a/n2vc/k8s_conn.py +++ b/n2vc/k8s_conn.py @@ -162,7 +162,8 @@ class K8sConnector(abc.ABC, Loggable): timeout: float = 300, params: dict = None, db_dict: dict = None, - kdu_name: str = None + kdu_name: str = None, + namespace: str = None ): """ Deploys of a new KDU instance. It would implicitly rely on the `install` call to deploy the Chart/Bundle @@ -183,6 +184,7 @@ class K8sConnector(abc.ABC, Loggable): It contains a dict with {collection: , filter: {}, path: }, e.g. {collection: "nsrs", filter: {_id: , path: "_admin.deployed.K8S.3"} :param kdu_name: Name of the KDU instance to be installed + :param namespace: K8s namespace to use for the KDU instance :return: True if successful """ diff --git a/n2vc/k8s_helm_conn.py b/n2vc/k8s_helm_conn.py index 1efacc4..b367e74 100644 --- a/n2vc/k8s_helm_conn.py +++ b/n2vc/k8s_helm_conn.py @@ -327,7 +327,8 @@ class K8sHelmConnector(K8sConnector): timeout: float = 300, params: dict = None, db_dict: dict = None, - kdu_name: str = None + kdu_name: str = None, + namespace: str = None ): self.log.debug('installing {} in cluster {}'.format(kdu_model, cluster_uuid)) @@ -348,6 +349,10 @@ class K8sHelmConnector(K8sConnector): atomic_str = '' if atomic: atomic_str = '--atomic' + # namespace + namespace_str = '' + if namespace: + namespace_str = "--namespace {}".format(namespace) # version version_str = '' @@ -374,9 +379,11 @@ class K8sHelmConnector(K8sConnector): pass # helm repo install - command = '{} install {} --output yaml --kubeconfig={} --home={} {} {} --name={} {} {}'\ - .format(self._helm_command, atomic_str, config_filename, helm_dir, - params_str, timeout_str, kdu_instance, kdu_model, version_str) + command = '{helm} install {atomic} --output yaml --kubeconfig={config} --home={dir} {params} {timeout} ' \ + '--name={name} {ns} {model} {ver}'.format(helm=self._helm_command, atomic=atomic_str, + config=config_filename, dir=helm_dir, params=params_str, + timeout=timeout_str, name=kdu_instance, ns=namespace_str, + model=kdu_model, ver=version_str) self.log.debug('installing: {}'.format(command)) if atomic: diff --git a/n2vc/k8s_juju_conn.py b/n2vc/k8s_juju_conn.py index 3316087..550ad12 100644 --- a/n2vc/k8s_juju_conn.py +++ b/n2vc/k8s_juju_conn.py @@ -306,7 +306,8 @@ class K8sJujuConnector(K8sConnector): timeout: float = 300, params: dict = None, db_dict: dict = None, - kdu_name: str = None + kdu_name: str = None, + namespace: str = None ) -> bool: """Install a bundle @@ -318,6 +319,7 @@ class K8sJujuConnector(K8sConnector): to finish :param params dict: Key-value pairs of instantiation parameters :param kdu_name: Name of the KDU instance to be installed + :param namespace: K8s namespace to use for the KDU instance :return: If successful, returns ? """ @@ -396,7 +398,7 @@ class K8sJujuConnector(K8sConnector): ) self.log.debug("All units active.") - except concurrent.futures._base.TimeoutError: + except concurrent.futures._base.TimeoutError: # TODO use asyncio.TimeoutError os.chdir(previous_workdir) self.log.debug("[install] Timeout exceeded; resetting cluster") await self.reset(cluster_uuid) -- 2.25.1