Skip to content

Commit

Permalink
Initial support for deploying Frontend resources (#175)
Browse files Browse the repository at this point in the history
* Initial support for deploying Frontend resources

* Close http session after fetch
  • Loading branch information
bsquizz authored Jan 27, 2022
1 parent ccc2fce commit a2e81e7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
13 changes: 13 additions & 0 deletions bonfire/bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]

Expand Down Expand Up @@ -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)

Expand All @@ -753,6 +761,7 @@ def _process(
single_replicas,
component_filter,
local,
frontends,
)
return processor.process()

Expand Down Expand Up @@ -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)
Expand All @@ -802,6 +812,7 @@ def _cmd_process(
single_replicas,
component_filter,
local,
frontends,
)
print(json.dumps(processed_templates, indent=2))

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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"]:
Expand Down
35 changes: 30 additions & 5 deletions bonfire/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -329,6 +330,7 @@ def __init__(
self.single_replicas = single_replicas
self.component_filter = component_filter
self.local = local
self.frontends = frontends

self._validate()

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 7 additions & 3 deletions bonfire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a2e81e7

Please sign in to comment.