bugfix: kubeconfig passed for helm commands. Bug 1789 19/11419/1 v11.0.0 v11.0.0rc2
authorbravof <fbravo@whitestack.com>
Wed, 17 Nov 2021 14:14:57 +0000 (11:14 -0300)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 26 Nov 2021 14:39:41 +0000 (15:39 +0100)
Change-Id: Idf8e9141e46296d45dbaa0260e8c9a55b445eb54
Signed-off-by: bravof <fbravo@whitestack.com>
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
n2vc/k8s_helm3_conn.py
n2vc/k8s_helm_base_conn.py
n2vc/k8s_helm_conn.py
n2vc/tests/unit/test_k8s_helm3_conn.py
n2vc/tests/unit/test_k8s_helm_conn.py

index edefc86..5544e3c 100644 (file)
@@ -284,15 +284,17 @@ class K8sHelm3Connector(K8sHelmBaseConnector):
 
         return _rc
 
-    async def _get_services(self, cluster_id: str, kdu_instance: str, namespace: str):
+    async def _get_services(
+        self, cluster_id: str, kdu_instance: str, namespace: str, kubeconfig: str
+    ):
 
         # init config, env
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
-        command1 = "{} get manifest {} --namespace={}".format(
-            self._helm_command, kdu_instance, namespace
+        command1 = "env KUBECONFIG={} {} get manifest {} --namespace={}".format(
+            kubeconfig, self._helm_command, kdu_instance, namespace
         )
         command2 = "{} get --namespace={} -f -".format(self.kubectl_command, namespace)
         output, _rc = await self._local_async_exec_pipe(
@@ -372,8 +374,8 @@ class K8sHelm3Connector(K8sHelmBaseConnector):
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
-        command = "{} status {} --namespace={} --output yaml".format(
-            self._helm_command, kdu_instance, namespace
+        command = "env KUBECONFIG={} {} status {} --namespace={} --output yaml".format(
+            paths["kube_config"], self._helm_command, kdu_instance, namespace
         )
 
         output, rc = await self._local_async_exec(
@@ -410,6 +412,7 @@ class K8sHelm3Connector(K8sHelmBaseConnector):
         version: str,
         atomic: bool,
         timeout: float,
+        kubeconfig: str,
     ) -> str:
 
         timeout_str = ""
@@ -431,8 +434,9 @@ class K8sHelm3Connector(K8sHelmBaseConnector):
             version_str = "--version {}".format(version)
 
         command = (
-            "{helm} install {name} {atomic} --output yaml  "
+            "env KUBECONFIG={kubeconfig} {helm} install {name} {atomic} --output yaml  "
             "{params} {timeout} {ns} {model} {ver}".format(
+                kubeconfig=kubeconfig,
                 helm=self._helm_command,
                 name=kdu_instance,
                 atomic=atomic_str,
@@ -454,6 +458,7 @@ class K8sHelm3Connector(K8sHelmBaseConnector):
         version: str,
         atomic: bool,
         timeout: float,
+        kubeconfig: str,
     ) -> str:
 
         timeout_str = ""
@@ -476,31 +481,34 @@ class K8sHelm3Connector(K8sHelmBaseConnector):
             namespace_str = "--namespace {}".format(namespace)
 
         command = (
-            "{helm} upgrade {name} {model} {namespace} {atomic} --output yaml {params} "
-            "{timeout}  {ver}".format(
-                helm=self._helm_command,
-                name=kdu_instance,
-                namespace=namespace_str,
-                atomic=atomic_str,
-                params=params_str,
-                timeout=timeout_str,
-                model=kdu_model,
-                ver=version_str,
-            )
+            "env KUBECONFIG={kubeconfig} {helm} upgrade {name} {model} {namespace} {atomic} "
+            "--output yaml {params} {timeout} {ver}"
+        ).format(
+            kubeconfig=kubeconfig,
+            helm=self._helm_command,
+            name=kdu_instance,
+            namespace=namespace_str,
+            atomic=atomic_str,
+            params=params_str,
+            timeout=timeout_str,
+            model=kdu_model,
+            ver=version_str,
         )
         return command
 
     def _get_rollback_command(
-        self, kdu_instance: str, namespace: str, revision: float
+        self, kdu_instance: str, namespace: str, revision: float, kubeconfig: str
     ) -> str:
-        return "{} rollback {} {} --namespace={} --wait".format(
-            self._helm_command, kdu_instance, revision, namespace
+        return "env KUBECONFIG={} {} rollback {} {} --namespace={} --wait".format(
+            kubeconfig, self._helm_command, kdu_instance, revision, namespace
         )
 
-    def _get_uninstall_command(self, kdu_instance: str, namespace: str) -> str:
+    def _get_uninstall_command(
+        self, kdu_instance: str, namespace: str, kubeconfig: str
+    ) -> str:
 
-        return "{} uninstall {} --namespace={}".format(
-            self._helm_command, kdu_instance, namespace
+        return "env KUBECONFIG={} {} uninstall {} --namespace={}".format(
+            kubeconfig, self._helm_command, kdu_instance, namespace
         )
 
     def _get_helm_chart_repos_ids(self, cluster_uuid) -> list:
index cca0cab..20fa337 100644 (file)
@@ -158,23 +158,27 @@ class K8sHelmBaseConnector(K8sConnector):
             )
         )
 
-        # sync local dir
-        self.fs.sync(from_path=cluster_id)
-
         # init_env
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
+        # sync local dir
+        self.fs.sync(from_path=cluster_id)
+
         # helm repo update
-        command = "{} repo update".format(self._helm_command)
+        command = "env KUBECONFIG={} {} repo update".format(
+            paths["kube_config"], self._helm_command
+        )
         self.log.debug("updating repo: {}".format(command))
         await self._local_async_exec(
             command=command, raise_exception_on_error=False, env=env
         )
 
         # helm repo add name url
-        command = "{} repo add {} {}".format(self._helm_command, name, url)
+        command = "env KUBECONFIG={} {} repo add {} {}".format(
+            paths["kube_config"], self._helm_command, name, url
+        )
         self.log.debug("adding repo: {}".format(command))
         await self._local_async_exec(
             command=command, raise_exception_on_error=True, env=env
@@ -193,15 +197,17 @@ class K8sHelmBaseConnector(K8sConnector):
         _, cluster_id = self._get_namespace_cluster_id(cluster_uuid)
         self.log.debug("list repositories for cluster {}".format(cluster_id))
 
-        # sync local dir
-        self.fs.sync(from_path=cluster_id)
-
         # config filename
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
-        command = "{} repo list --output yaml".format(self._helm_command)
+        # sync local dir
+        self.fs.sync(from_path=cluster_id)
+
+        command = "env KUBECONFIG={} {} repo list --output yaml".format(
+            paths["kube_config"], self._helm_command
+        )
 
         # Set exception to false because if there are no repos just want an empty list
         output, _rc = await self._local_async_exec(
@@ -226,15 +232,17 @@ class K8sHelmBaseConnector(K8sConnector):
         _, cluster_id = self._get_namespace_cluster_id(cluster_uuid)
         self.log.debug("remove {} repositories for cluster {}".format(name, cluster_id))
 
-        # sync local dir
-        self.fs.sync(from_path=cluster_id)
-
         # init env, paths
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
-        command = "{} repo remove {}".format(self._helm_command, name)
+        # sync local dir
+        self.fs.sync(from_path=cluster_id)
+
+        command = "env KUBECONFIG={} {} repo remove {}".format(
+            paths["kube_config"], self._helm_command, name
+        )
         await self._local_async_exec(
             command=command, raise_exception_on_error=True, env=env
         )
@@ -328,6 +336,11 @@ class K8sHelmBaseConnector(K8sConnector):
         kdu_name: str = None,
         namespace: str = None,
     ):
+        # init env, paths
+        paths, env = self._init_paths_env(
+            cluster_name=cluster_id, create_if_not_exist=True
+        )
+
         # params to str
         params_str, file_to_delete = self._params_to_file_option(
             cluster_id=cluster_id, params=params
@@ -342,7 +355,14 @@ class K8sHelmBaseConnector(K8sConnector):
                 kdu_model = parts[0]
 
         command = self._get_install_command(
-            kdu_model, kdu_instance, namespace, params_str, version, atomic, timeout
+            kdu_model,
+            kdu_instance,
+            namespace,
+            params_str,
+            version,
+            atomic,
+            timeout,
+            paths["kube_config"],
         )
 
         self.log.debug("installing: {}".format(command))
@@ -427,6 +447,9 @@ class K8sHelmBaseConnector(K8sConnector):
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
+        # sync local dir
+        self.fs.sync(from_path=cluster_id)
+
         # params to str
         params_str, file_to_delete = self._params_to_file_option(
             cluster_id=cluster_id, params=params
@@ -448,6 +471,7 @@ class K8sHelmBaseConnector(K8sConnector):
             version,
             atomic,
             timeout,
+            paths["kube_config"],
         )
 
         self.log.debug("upgrading: {}".format(command))
@@ -561,8 +585,11 @@ class K8sHelmBaseConnector(K8sConnector):
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
+        # sync local dir
+        self.fs.sync(from_path=cluster_id)
+
         command = self._get_rollback_command(
-            kdu_instance, instance_info["namespace"], revision
+            kdu_instance, instance_info["namespace"], revision, paths["kube_config"]
         )
 
         self.log.debug("rolling_back: {}".format(command))
@@ -653,7 +680,12 @@ class K8sHelmBaseConnector(K8sConnector):
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
-        command = self._get_uninstall_command(kdu_instance, instance_info["namespace"])
+        # sync local dir
+        self.fs.sync(from_path=cluster_id)
+
+        command = self._get_uninstall_command(
+            kdu_instance, instance_info["namespace"], paths["kube_config"]
+        )
         output, _rc = await self._local_async_exec(
             command=command, raise_exception_on_error=True, env=env
         )
@@ -746,11 +778,18 @@ class K8sHelmBaseConnector(K8sConnector):
             )
         )
 
+        # init env, paths
+        paths, env = self._init_paths_env(
+            cluster_name=cluster_id, create_if_not_exist=True
+        )
+
         # sync local dir
         self.fs.sync(from_path=cluster_id)
 
         # get list of services names for kdu
-        service_names = await self._get_services(cluster_id, kdu_instance, namespace)
+        service_names = await self._get_services(
+            cluster_id, kdu_instance, namespace, paths["kube_config"]
+        )
 
         service_list = []
         for service in service_names:
@@ -970,7 +1009,7 @@ class K8sHelmBaseConnector(K8sConnector):
         """
 
     @abc.abstractmethod
-    async def _get_services(self, cluster_id, kdu_instance, namespace):
+    async def _get_services(self, cluster_id, kdu_instance, namespace, kubeconfig):
         """
         Implements the helm version dependent method to obtain services from a helm instance
         """
@@ -990,7 +1029,15 @@ class K8sHelmBaseConnector(K8sConnector):
 
     @abc.abstractmethod
     def _get_install_command(
-        self, kdu_model, kdu_instance, namespace, params_str, version, atomic, timeout
+        self,
+        kdu_model,
+        kdu_instance,
+        namespace,
+        params_str,
+        version,
+        atomic,
+        timeout,
+        kubeconfig,
     ) -> str:
         """
         Obtain command to be executed to delete the indicated instance
@@ -998,20 +1045,32 @@ class K8sHelmBaseConnector(K8sConnector):
 
     @abc.abstractmethod
     def _get_upgrade_command(
-        self, kdu_model, kdu_instance, namespace, params_str, version, atomic, timeout
+        self,
+        kdu_model,
+        kdu_instance,
+        namespace,
+        params_str,
+        version,
+        atomic,
+        timeout,
+        kubeconfig,
     ) -> str:
         """
         Obtain command to be executed to upgrade the indicated instance
         """
 
     @abc.abstractmethod
-    def _get_rollback_command(self, kdu_instance, namespace, revision) -> str:
+    def _get_rollback_command(
+        self, kdu_instance, namespace, revision, kubeconfig
+    ) -> str:
         """
         Obtain command to be executed to rollback the indicated instance
         """
 
     @abc.abstractmethod
-    def _get_uninstall_command(self, kdu_instance: str, namespace: str) -> str:
+    def _get_uninstall_command(
+        self, kdu_instance: str, namespace: str, kubeconfig: str
+    ) -> str:
         """
         Obtain command to be executed to delete the indicated instance
         """
index 6bbc0fa..13a3114 100644 (file)
@@ -233,14 +233,16 @@ class K8sHelmConnector(K8sHelmBaseConnector):
 
         return paths, env
 
-    async def _get_services(self, cluster_id, kdu_instance, namespace):
+    async def _get_services(self, cluster_id, kdu_instance, namespace, kubeconfig):
 
         # init config, env
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
 
-        command1 = "{} get manifest {} ".format(self._helm_command, kdu_instance)
+        command1 = "env KUBECONFIG={} {} get manifest {} ".format(
+            kubeconfig, self._helm_command, kdu_instance
+        )
         command2 = "{} get --namespace={} -f -".format(self.kubectl_command, namespace)
         output, _rc = await self._local_async_exec_pipe(
             command1, command2, env=env, raise_exception_on_error=True
@@ -464,7 +466,9 @@ class K8sHelmConnector(K8sHelmBaseConnector):
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
         )
-        command = "{} status {} --output yaml".format(self._helm_command, kdu_instance)
+        command = ("env KUBECONFIG={} {} status {} --output yaml").format(
+            paths["kube_config"], self._helm_command, kdu_instance
+        )
         output, rc = await self._local_async_exec(
             command=command,
             raise_exception_on_error=True,
@@ -515,6 +519,10 @@ class K8sHelmConnector(K8sHelmBaseConnector):
             )
 
     async def _is_install_completed(self, cluster_id: str, kdu_instance: str) -> bool:
+        # init config, env
+        paths, env = self._init_paths_env(
+            cluster_name=cluster_id, create_if_not_exist=True
+        )
 
         status = await self._status_kdu(
             cluster_id=cluster_id, kdu_instance=kdu_instance, return_text=False
@@ -567,7 +575,15 @@ class K8sHelmConnector(K8sHelmBaseConnector):
         return ready
 
     def _get_install_command(
-        self, kdu_model, kdu_instance, namespace, params_str, version, atomic, timeout
+        self,
+        kdu_model,
+        kdu_instance,
+        namespace,
+        params_str,
+        version,
+        atomic,
+        timeout,
+        kubeconfig,
     ) -> str:
 
         timeout_str = ""
@@ -589,8 +605,9 @@ class K8sHelmConnector(K8sHelmBaseConnector):
             version_str = version_str = "--version {}".format(version)
 
         command = (
-            "{helm} install {atomic} --output yaml  "
+            "env KUBECONFIG={kubeconfig} {helm} install {atomic} --output yaml  "
             "{params} {timeout} --name={name} {ns} {model} {ver}".format(
+                kubeconfig=kubeconfig,
                 helm=self._helm_command,
                 atomic=atomic_str,
                 params=params_str,
@@ -604,7 +621,15 @@ class K8sHelmConnector(K8sHelmBaseConnector):
         return command
 
     def _get_upgrade_command(
-        self, kdu_model, kdu_instance, namespace, params_str, version, atomic, timeout
+        self,
+        kdu_model,
+        kdu_instance,
+        namespace,
+        params_str,
+        version,
+        atomic,
+        timeout,
+        kubeconfig,
     ) -> str:
 
         timeout_str = ""
@@ -621,7 +646,10 @@ class K8sHelmConnector(K8sHelmBaseConnector):
         if version:
             version_str = "--version {}".format(version)
 
-        command = "{helm} upgrade {atomic} --output yaml {params} {timeout} {name} {model} {ver}".format(
+        command = (
+            "env KUBECONFIG={kubeconfig} {helm} upgrade {atomic} --output yaml {params} {timeout} {name} {model} {ver}"
+        ).format(
+            kubeconfig=kubeconfig,
             helm=self._helm_command,
             atomic=atomic_str,
             params=params_str,
@@ -632,10 +660,16 @@ class K8sHelmConnector(K8sHelmBaseConnector):
         )
         return command
 
-    def _get_rollback_command(self, kdu_instance, namespace, revision) -> str:
-        return "{} rollback {} {} --wait".format(
-            self._helm_command, kdu_instance, revision
+    def _get_rollback_command(
+        self, kdu_instance, namespace, revision, kubeconfig
+    ) -> str:
+        return "env KUBECONFIG={} {} rollback {} {} --wait".format(
+            kubeconfig, self._helm_command, kdu_instance, revision
         )
 
-    def _get_uninstall_command(self, kdu_instance: str, namespace: str) -> str:
-        return "{} delete --purge  {}".format(self._helm_command, kdu_instance)
+    def _get_uninstall_command(
+        self, kdu_instance: str, namespace: str, kubeconfig: str
+    ) -> str:
+        return "env KUBECONFIG={} {} delete --purge  {}".format(
+            kubeconfig, self._helm_command, kdu_instance
+        )
index 93d0c4c..e3c7707 100644 (file)
@@ -102,8 +102,10 @@ class TestK8sHelm3Conn(asynctest.TestCase):
             ),
         )
 
-        repo_update_command = "/usr/bin/helm3 repo update"
-        repo_add_command = "/usr/bin/helm3 repo add {} {}".format(repo_name, repo_url)
+        repo_update_command = "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 repo update"
+        repo_add_command = (
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 repo add {} {}"
+        ).format(repo_name, repo_url)
         calls = self.helm_conn._local_async_exec.call_args_list
         call0_kargs = calls[0][1]
         self.assertEqual(
@@ -139,7 +141,7 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
-        command = "/usr/bin/helm3 repo list --output yaml"
+        command = "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 repo list --output yaml"
         self.helm_conn._local_async_exec.assert_called_with(
             command=command, env=self.env, raise_exception_on_error=False
         )
@@ -155,7 +157,9 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
-        command = "/usr/bin/helm3 repo remove {}".format(repo_name)
+        command = "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 repo remove {}".format(
+            repo_name
+        )
         self.helm_conn._local_async_exec.assert_called_with(
             command=command, env=self.env, raise_exception_on_error=True
         )
@@ -204,7 +208,8 @@ class TestK8sHelm3Conn(asynctest.TestCase):
             check_every=0,
         )
         command = (
-            "/usr/bin/helm3 install stable-openldap-0005399828 --atomic --output yaml   "
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 "
+            "install stable-openldap-0005399828 --atomic --output yaml   "
             "--timeout 300s --namespace testk8s stable/openldap --version 1.2.2"
         )
         self.helm_conn._local_async_exec.assert_called_once_with(
@@ -262,7 +267,7 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         await self.helm_conn.upgrade(
             self.cluster_uuid, kdu_instance, kdu_model, atomic=True, db_dict=db_dict
         )
-        self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
+        self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
@@ -276,8 +281,9 @@ class TestK8sHelm3Conn(asynctest.TestCase):
             check_every=0,
         )
         command = (
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config "
             "/usr/bin/helm3 upgrade stable-openldap-0005399828 stable/openldap "
-            "--namespace testk8s --atomic --output yaml  --timeout 300s  "
+            "--namespace testk8s --atomic --output yaml  --timeout 300s "
             "--version 1.2.3"
         )
         self.helm_conn._local_async_exec.assert_called_once_with(
@@ -304,7 +310,7 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         await self.helm_conn.rollback(
             self.cluster_uuid, kdu_instance=kdu_instance, revision=1, db_dict=db_dict
         )
-        self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
+        self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
@@ -317,7 +323,10 @@ class TestK8sHelm3Conn(asynctest.TestCase):
             run_once=True,
             check_every=0,
         )
-        command = "/usr/bin/helm3 rollback stable-openldap-0005399828 1 --namespace=testk8s --wait"
+        command = (
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 "
+            "rollback stable-openldap-0005399828 1 --namespace=testk8s --wait"
+        )
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command, env=self.env, raise_exception_on_error=False
         )
@@ -339,13 +348,13 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         )
 
         await self.helm_conn.uninstall(self.cluster_uuid, kdu_instance)
-        self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
+        self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
-        command = "/usr/bin/helm3 uninstall {} --namespace={}".format(
-            kdu_instance, self.namespace
-        )
+        command = (
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 uninstall {} --namespace={}"
+        ).format(kdu_instance, self.namespace)
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command, env=self.env, raise_exception_on_error=True
         )
@@ -368,9 +377,9 @@ class TestK8sHelm3Conn(asynctest.TestCase):
             from_path=self.cluster_id
         )
         self.helm_conn._parse_services.assert_called_once()
-        command1 = "/usr/bin/helm3 get manifest {} --namespace=testk8s".format(
-            kdu_instance
-        )
+        command1 = (
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 get manifest {} --namespace=testk8s"
+        ).format(kdu_instance)
         command2 = "/usr/bin/kubectl get --namespace={} -f -".format(self.namespace)
         self.helm_conn._local_async_exec_pipe.assert_called_once_with(
             command1, command2, env=self.env, raise_exception_on_error=True
@@ -473,9 +482,9 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         await self.helm_conn._status_kdu(
             self.cluster_id, kdu_instance, self.namespace, return_text=True
         )
-        command = "/usr/bin/helm3 status {} --namespace={} --output yaml".format(
-            kdu_instance, self.namespace
-        )
+        command = (
+            "env KUBECONFIG=./tmp/helm3_cluster_id/.kube/config /usr/bin/helm3 status {} --namespace={} --output yaml"
+        ).format(kdu_instance, self.namespace)
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command,
             env=self.env,
index c57c8a4..afc8ca7 100644 (file)
@@ -79,8 +79,10 @@ class TestK8sHelmConn(asynctest.TestCase):
             ),
         )
 
-        repo_update_command = "/usr/bin/helm repo update"
-        repo_add_command = "/usr/bin/helm repo add {} {}".format(repo_name, repo_url)
+        repo_update_command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo update"
+        repo_add_command = (
+            "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo add {} {}"
+        ).format(repo_name, repo_url)
         calls = self.helm_conn._local_async_exec.call_args_list
         call0_kargs = calls[0][1]
         self.assertEqual(
@@ -115,7 +117,7 @@ class TestK8sHelmConn(asynctest.TestCase):
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
-        command = "/usr/bin/helm repo list --output yaml"
+        command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo list --output yaml"
         self.helm_conn._local_async_exec.assert_called_with(
             command=command, env=self.env, raise_exception_on_error=False
         )
@@ -130,7 +132,9 @@ class TestK8sHelmConn(asynctest.TestCase):
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
-        command = "/usr/bin/helm repo remove {}".format(repo_name)
+        command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo remove {}".format(
+            repo_name
+        )
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command, env=self.env, raise_exception_on_error=True
         )
@@ -168,7 +172,8 @@ class TestK8sHelmConn(asynctest.TestCase):
             check_every=0,
         )
         command = (
-            "/usr/bin/helm install --atomic --output yaml   --timeout 300 "
+            "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm install "
+            "--atomic --output yaml   --timeout 300 "
             "--name=stable-openldap-0005399828 --namespace testk8s stable/openldap "
             "--version 1.2.2"
         )
@@ -197,7 +202,7 @@ class TestK8sHelmConn(asynctest.TestCase):
         await self.helm_conn.upgrade(
             self.cluster_uuid, kdu_instance, kdu_model, atomic=True, db_dict=db_dict
         )
-        self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
+        self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
@@ -211,8 +216,8 @@ class TestK8sHelmConn(asynctest.TestCase):
             check_every=0,
         )
         command = (
-            "/usr/bin/helm upgrade --atomic --output yaml  --timeout 300 "
-            "stable-openldap-0005399828 stable/openldap --version 1.2.3"
+            "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm upgrade "
+            "--atomic --output yaml  --timeout 300 stable-openldap-0005399828 stable/openldap --version 1.2.3"
         )
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command, env=self.env, raise_exception_on_error=False
@@ -238,7 +243,7 @@ class TestK8sHelmConn(asynctest.TestCase):
         await self.helm_conn.rollback(
             self.cluster_uuid, kdu_instance=kdu_instance, revision=1, db_dict=db_dict
         )
-        self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
+        self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
@@ -251,7 +256,10 @@ class TestK8sHelmConn(asynctest.TestCase):
             run_once=True,
             check_every=0,
         )
-        command = "/usr/bin/helm rollback stable-openldap-0005399828 1 --wait"
+        command = (
+            "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config "
+            "/usr/bin/helm rollback stable-openldap-0005399828 1 --wait"
+        )
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command, env=self.env, raise_exception_on_error=False
         )
@@ -273,11 +281,13 @@ class TestK8sHelmConn(asynctest.TestCase):
         )
 
         await self.helm_conn.uninstall(self.cluster_uuid, kdu_instance)
-        self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
+        self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
         self.helm_conn.fs.reverse_sync.assert_called_once_with(
             from_path=self.cluster_id
         )
-        command = "/usr/bin/helm delete --purge  {}".format(kdu_instance)
+        command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm delete --purge  {}".format(
+            kdu_instance
+        )
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command, env=self.env, raise_exception_on_error=True
         )
@@ -300,7 +310,9 @@ class TestK8sHelmConn(asynctest.TestCase):
             from_path=self.cluster_id
         )
         self.helm_conn._parse_services.assert_called_once()
-        command1 = "/usr/bin/helm get manifest {} ".format(kdu_instance)
+        command1 = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm get manifest {} ".format(
+            kdu_instance
+        )
         command2 = "/usr/bin/kubectl get --namespace={} -f -".format(self.namespace)
         self.helm_conn._local_async_exec_pipe.assert_called_once_with(
             command1, command2, env=self.env, raise_exception_on_error=True
@@ -403,7 +415,9 @@ class TestK8sHelmConn(asynctest.TestCase):
         await self.helm_conn._status_kdu(
             self.cluster_id, kdu_instance, self.namespace, return_text=True
         )
-        command = "/usr/bin/helm status {} --output yaml".format(kdu_instance)
+        command = (
+            "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm status {} --output yaml"
+        ).format(kdu_instance)
         self.helm_conn._local_async_exec.assert_called_once_with(
             command=command,
             env=self.env,