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(
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(
version: str,
atomic: bool,
timeout: float,
+ kubeconfig: str,
) -> str:
timeout_str = ""
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,
version: str,
atomic: bool,
timeout: float,
+ kubeconfig: str,
) -> str:
timeout_str = ""
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:
)
)
- # 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
_, 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(
_, 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
)
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
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))
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
version,
atomic,
timeout,
+ paths["kube_config"],
)
self.log.debug("upgrading: {}".format(command))
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))
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
)
)
)
+ # 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:
"""
@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
"""
@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
@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
"""
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
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,
)
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
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 = ""
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,
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 = ""
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,
)
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
+ )
),
)
- 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(
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
)
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
)
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(
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
)
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(
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
)
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
)
)
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
)
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
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,
),
)
- 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(
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
)
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
)
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"
)
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
)
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
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
)
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
)
)
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
)
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
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,