diff --git a/octoploy/__init__.py b/octoploy/__init__.py index 5a5df3b..daab838 100644 --- a/octoploy/__init__.py +++ b/octoploy/__init__.py @@ -1 +1 @@ -__version__ = '1.2.3' +__version__ = '1.2.4' diff --git a/octoploy/config/AppConfig.py b/octoploy/config/AppConfig.py index 0cdcf8e..919e653 100644 --- a/octoploy/config/AppConfig.py +++ b/octoploy/config/AppConfig.py @@ -14,9 +14,11 @@ class AppConfig(BaseConfig): Contains the configuration for the deployment of a single app """ - def __init__(self, config_root: str, path: Optional[str], external_vars: Dict[str, str] = None): + def __init__(self, config_root: str, path: Optional[str], external_vars: Dict[str, str] = None, + root=None): super().__init__(path, external_vars) self._config_root = config_root + self._root = root def get_config_maps(self) -> List[DynamicConfigMap]: """ @@ -24,6 +26,13 @@ def get_config_maps(self) -> List[DynamicConfigMap]: """ return [DynamicConfigMap(data) for data in self.data.get('configmaps', [])] + def get_root(self): + """ + Returns the root configuration + :return: Config + """ + return self._root + def enabled(self) -> bool: """ True if this app is enabled @@ -56,7 +65,7 @@ def get_for_each(self) -> List[AppConfig]: if dc_name is None: raise MissingVar('APP_NAME not defined in forEach for app ' + str(self.get_name())) - config = AppConfig(self._config_root, None, instance_vars) + config = AppConfig(self._config_root, None, instance_vars, self._root) # Inherit all parameters config.data.update(self.data) # Update the DC_NAME diff --git a/octoploy/config/Config.py b/octoploy/config/Config.py index 07b34dd..50018f3 100644 --- a/octoploy/config/Config.py +++ b/octoploy/config/Config.py @@ -61,7 +61,7 @@ class RootConfig(BaseConfig): def __init__(self, config_root: str, path: str): super().__init__(path) self._config_root = config_root - self._oc = None + self._k8s_api = None self._library = None # type: Optional[RootConfig] self._global_var_overrides: Dict[str, str] = {} @@ -117,18 +117,22 @@ def create_api(self) -> K8sApi: Creates a new openshift / k8s client. :return: Client """ - if self._oc is not None: - return self._oc + if self._k8s_api is not None: + return self._k8s_api mode = self._get_mode() if mode == 'oc': - oc = Oc() + k8s_api = Oc() elif mode == 'k8s' or mode == 'k8': - oc = K8() + k8s_api = K8() else: raise ValueError(f'Invalid mode: {mode}') - self._oc = oc - return oc + + context = self.get_kubectl_context() + if context is not None: + k8s_api.switch_context(context) + self._k8s_api = k8s_api + return k8s_api def get_namespace_name(self) -> Optional[str]: """ @@ -230,4 +234,4 @@ def load_app_config(self, name: str) -> AppConfig: raise FileNotFoundError('No index yml file found: ' + index_file) variables = self.get_replacements() - return AppConfig(folder_path, index_file, variables) + return AppConfig(folder_path, index_file, variables, root=self) diff --git a/octoploy/config/DeploymentActionConfig.py b/octoploy/config/DeploymentActionConfig.py index 8cdf347..c6e5d37 100644 --- a/octoploy/config/DeploymentActionConfig.py +++ b/octoploy/config/DeploymentActionConfig.py @@ -20,9 +20,10 @@ def __init__(self, app_config: AppConfig, data): self._data = data self._app_config = app_config - def run(self, oc: K8sApi): + def run(self, k8s: K8sApi): + namespace = self._app_config.get_root().get_namespace_name() if self._data == 'deploy': - oc.rollout(self._app_config.get_name()) + k8s.rollout(self._app_config.get_name(), namespace=namespace) return exec_config = self._data.get('exec', None) @@ -32,7 +33,7 @@ def run(self, oc: K8sApi): dc_name = self._app_config.get_name() self.log.info('Reloading via exec in pods of ' + dc_name) - pods = oc.get_pods(dc_name=dc_name) + pods = k8s.get_pods(dc_name=dc_name, namespace=namespace) for pod in pods: - oc.exec(pod.name, cmd, args) + k8s.exec(pod.name, cmd, args, namespace=namespace) return diff --git a/octoploy/deploy/DeploymentBundle.py b/octoploy/deploy/DeploymentBundle.py index 800c356..8441a40 100644 --- a/octoploy/deploy/DeploymentBundle.py +++ b/octoploy/deploy/DeploymentBundle.py @@ -55,8 +55,6 @@ def deploy(self, deploy_runner: K8sObjectDeployer): Deploys all objects in this bundle :param deploy_runner: Deployment runner which should be used """ - deploy_runner.select_context() - # First sort the objects, we want "deployments" to be the last object type # so all prerequisites are available def sorting(x: BaseObj): diff --git a/octoploy/deploy/K8sObjectDeployer.py b/octoploy/deploy/K8sObjectDeployer.py index bf553c4..0527208 100644 --- a/octoploy/deploy/K8sObjectDeployer.py +++ b/octoploy/deploy/K8sObjectDeployer.py @@ -31,14 +31,6 @@ def __init__(self, root_config: RootConfig, k8sapi: K8sApi, app_config: AppConfi self._to_be_deployed: List[BaseObj] = [] - def select_context(self): - """ - Selects the cluster context - """ - context = self._root_config.get_kubectl_context() - if context is not None: - self._api.switch_context(context) - def add_object(self, k8s_object: BaseObj): """ Adds the given object to the deployment list