diff --git a/bonfire/bonfire.py b/bonfire/bonfire.py index d4bc0fe2..3118d460 100755 --- a/bonfire/bonfire.py +++ b/bonfire/bonfire.py @@ -430,6 +430,13 @@ def _validate_resource_arguments(ctx, param, value): type=str, multiple=True, ), + click.option( + "--frontends", + "-F", + help="Deploy frontends (default: false)", + type=bool, + default=False, + ), _local_option, ] @@ -737,6 +744,7 @@ def _process( single_replicas, component_filter, local, + frontends, ): apps_config = _get_apps_config(source, target_env, ref_env, local_config_path) @@ -753,6 +761,7 @@ def _process( single_replicas, component_filter, local, + frontends, ) return processor.process() @@ -782,6 +791,7 @@ def _cmd_process( single_replicas, component_filter, local, + frontends, ): """Fetch and process application templates""" clowd_env = _get_env_name(namespace, clowd_env) @@ -802,6 +812,7 @@ def _cmd_process( single_replicas, component_filter, local, + frontends, ) print(json.dumps(processed_templates, indent=2)) @@ -898,6 +909,7 @@ def _cmd_config_deploy( import_secrets, secrets_dir, local, + frontends, ): """Process app templates and deploy them to a cluster""" if not has_clowder(): @@ -951,6 +963,7 @@ def _err_handler(err): single_replicas, component_filter, local, + frontends, ) log.debug("app configs:\n%s", json.dumps(apps_config, indent=2)) if not apps_config["items"]: diff --git a/bonfire/processor.py b/bonfire/processor.py index 1d7a81b0..ac1776fe 100644 --- a/bonfire/processor.py +++ b/bonfire/processor.py @@ -316,6 +316,7 @@ def __init__( single_replicas, component_filter, local, + frontends, ): self.apps_config = apps_config self.requested_app_names = self._parse_app_names(app_names) @@ -329,6 +330,7 @@ def __init__( self.single_replicas = single_replicas self.component_filter = component_filter self.local = local + self.frontends = frontends self._validate() @@ -436,13 +438,36 @@ def _process_component(self, component_name): if component_name not in self.processed_components: log.info("processing component %s", component_name) new_items = self._get_component_items(component_name) - self.k8s_list["items"].extend(new_items) - self.processed_components.add(component_name) + # ignore frontends if we're not supposed to deploy them + frontend_found = False + for item in new_items: + kind = item.get("kind").lower() + ver = item.get("apiVersion").lower() + if kind == "frontend" and ver.startswith("cloud.redhat.com"): + frontend_found = True + break - if self.get_dependencies: - # recursively process components to add config for dependent apps to self.k8s_list - self._add_dependencies_to_config(component_name, new_items) + if frontend_found and not self.frontends: + log.info( + "ignoring component %s, user opted to disable frontend deployments", + component_name, + ) + new_items = [] + + if new_items: + self.k8s_list["items"].extend(new_items) + self.processed_components.add(component_name) + + if frontend_found and "frontend-configs" not in self.processed_components: + log.info( + "found a Frontend resource, auto-adding frontend-configs as dependency" + ) + self._process_component("frontend-configs") + + if self.get_dependencies: + # recursively process to add config for dependent apps to self.k8s_list + self._add_dependencies_to_config(component_name, new_items) else: log.debug("component %s already processed", component_name) diff --git a/bonfire/utils.py b/bonfire/utils.py index b0793b19..71a1b886 100644 --- a/bonfire/utils.py +++ b/bonfire/utils.py @@ -174,11 +174,15 @@ def from_config(cls, d): def fetch(self): if self.host == "local": - return self._fetch_local() + result = self._fetch_local() if self.host == "github": - return self._fetch_github() + result = self._fetch_github() if self.host == "gitlab": - return self._fetch_gitlab() + result = self._fetch_gitlab() + + self._session.close() + + return result @cached_property def _gl_certfile(self):