- msg = 'Tiller deployment not found in cluster {}'.format(cluster_uuid)
- self.error(msg)
-
- self.debug('namespace for tiller: {}'.format(namespace))
-
- force_str = '--force'
-
- if namespace:
- # delete tiller deployment
- self.debug('Deleting tiller deployment for cluster {}, namespace {}'.format(cluster_uuid, namespace))
- command = '{} --namespace {} --kubeconfig={} {} delete deployment tiller-deploy'\
- .format(self.kubectl_command, namespace, config_filename, force_str)
- await self._local_async_exec(command=command, raise_exception_on_error=False)
-
- # uninstall tiller from cluster
- self.debug('Uninstalling tiller from cluster {}'.format(cluster_uuid))
- command = '{} --kubeconfig={} --home={} reset'\
- .format(self._helm_command, config_filename, helm_dir)
- self.debug('resetting: {}'.format(command))
- output, rc = await self._local_async_exec(command=command, raise_exception_on_error=True)
- else:
- self.debug('namespace not found')
-
- # delete cluster directory
- dir = self.fs.path + '/' + cluster_uuid
- self.debug('Removing directory {}'.format(dir))
- shutil.rmtree(dir, ignore_errors=True)
-
- return True
-
- async def install(
- self,
- cluster_uuid: str,
- kdu_model: str,
- atomic: bool = True,
- timeout: float = 300,
- params: dict = None,
- db_dict: dict = None,
- kdu_name: str = None
- ):
-
- self.debug('installing {} in cluster {}'.format(kdu_model, cluster_uuid))
-
- # config filename
- kube_dir, helm_dir, config_filename, cluster_dir = \
- self._get_paths(cluster_name=cluster_uuid, create_if_not_exist=True)
-
- # params to str
- # params_str = K8sHelmConnector._params_to_set_option(params)
- params_str, file_to_delete = self._params_to_file_option(cluster_uuid=cluster_uuid, params=params)
-
- timeout_str = ''
- if timeout:
- timeout_str = '--timeout {}'.format(timeout)
-
- # atomic
- atomic_str = ''
- if atomic:
- atomic_str = '--atomic'
-
- # version
- version_str = ''
- if ':' in kdu_model:
- parts = kdu_model.split(sep=':')
- if len(parts) == 2:
- version_str = '--version {}'.format(parts[1])
- kdu_model = parts[0]
-
- # generate a name for the release. Then, check if already exists
- kdu_instance = None
- while kdu_instance is None:
- kdu_instance = K8sHelmConnector._generate_release_name(kdu_model)
- try:
- result = await self._status_kdu(
- cluster_uuid=cluster_uuid,
- kdu_instance=kdu_instance,
- show_error_log=False
- )
- if result is not None:
- # instance already exists: generate a new one
- kdu_instance = None
- except K8sException:
- 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)
- self.debug('installing: {}'.format(command))
-
- if atomic:
- # exec helm in a task
- exec_task = asyncio.ensure_future(
- coro_or_future=self._local_async_exec(command=command, raise_exception_on_error=False)