Skip to content

Commit

Permalink
Add env vars to specify trusted apps/components (#344)
Browse files Browse the repository at this point in the history
* Add env vars to specify trusted apps/components

* Relocate where trusted app/component is checked

* Fix log message
  • Loading branch information
bsquizz authored Jan 19, 2024
1 parent 624eecb commit 925d879
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions bonfire/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
os.getenv("BONFIRE_DEFAULT_FALLBACK_REF_ENV", "insights-stage")
)

# list of apps we will not remove resource requests/limits for
TRUSTED_APPS = ["host-inventory"]
if os.getenv("BONFIRE_TRUSTED_APPS"):
TRUSTED_APPS = os.getenv("BONFIRE_TRUSTED_APPS").split(",")

# list of components we will not remove requests/limits for
TRUSTED_COMPONENTS = []
if os.getenv("BONFIRE_TRUSTED_COMPONENTS"):
TRUSTED_COMPONENTS = os.getenv("BONFIRE_TRUSTED_COMPONENTS").split(",")

ELASTICSEARCH_HOST = os.getenv("ELASTICSEARCH_HOST", DEFAULT_ELASTICSEARCH_HOST)
ELASTICSEARCH_APIKEY = os.getenv("ELASTICSEARCH_APIKEY")
ENABLE_TELEMETRY = os.getenv("ENABLE_TELEMETRY", DEFAULT_ENABLE_TELEMETRY).lower() == "true"
Expand Down
18 changes: 15 additions & 3 deletions bonfire/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,21 @@ def _get_component_items(self, component_name):

# evaluate --remove-resources/--no-remove-resources
app_name = self._get_app_for_component(component_name)
should_remove_resources = _should_remove(
self.remove_resources, self.no_remove_resources, app_name, component_name, default=True
)

# if app/component is trusted, do not remove its resources
should_remove_resources = False
if app_name in conf.TRUSTED_APPS:
log.debug("should_remove: app '%s' listed in trusted apps", app_name)
elif component_name in conf.TRUSTED_COMPONENTS:
log.debug("should_remove: component '%s' listed in trusted components", component_name)
else:
should_remove_resources = _should_remove(
self.remove_resources,
self.no_remove_resources,
app_name,
component_name,
default=True,
)
log.debug("should_remove_resources evaluates to %s", should_remove_resources)
if should_remove_resources:
_remove_resource_config(new_items)
Expand Down

0 comments on commit 925d879

Please sign in to comment.