Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/martinl/additional-config-overri…
Browse files Browse the repository at this point in the history
…des' into martinl/additional-config-overrides
  • Loading branch information
Litarnus committed Nov 21, 2024
2 parents 8c1aecf + acdc150 commit 8292130
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 6 additions & 2 deletions libsentrykube/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
get_service_template_files,
get_service_values,
get_service_value_overrides,
get_tools_managed_service_value_overrides, get_hierarchical_value_overrides,
get_tools_managed_service_value_overrides,
get_hierarchical_value_overrides,
)
from libsentrykube.utils import (
deep_merge_dict,
Expand Down Expand Up @@ -138,7 +139,9 @@ def _consolidate_variables(
)
deep_merge_dict(service_values, managed_values)

hierarchical_values = get_hierarchical_value_overrides(service_name, customer_name, cluster_name, external)
hierarchical_values = get_hierarchical_value_overrides(
service_name, customer_name, cluster_name, external
)
deep_merge_dict(service_values, hierarchical_values)

# Service data overrides from clusters/
Expand Down Expand Up @@ -249,6 +252,7 @@ def render_templates(

return "\n---\n".join(rendered_templates)


def materialize(customer_name: str, service_name: str, cluster_name: str) -> bool:
"""
Render a service and saves it to a file.
Expand Down
26 changes: 15 additions & 11 deletions libsentrykube/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def get_service_value_overrides(

# Try to load the config only after {cluster_name}.yaml was successfully loaded because the common override
# only makes sense if there is a cluster config
common_override_values = get_common_regional_override(service_name, region_name, external)
common_override_values = get_common_regional_override(
service_name, region_name, external
)

if common_override_values:
deep_merge_dict(common_override_values, values)
Expand All @@ -137,10 +139,9 @@ def get_service_value_overrides(
except FileNotFoundError:
return {}


def get_common_regional_override(
service_name: str,
region_name: str,
external: bool = False
service_name: str, region_name: str, external: bool = False
) -> dict:
"""
Helper function to load common regional configuration values.
Expand All @@ -149,7 +150,10 @@ def get_common_regional_override(
settings shared across all clusters in that region.
"""
try:
common_service_override_file = get_service_value_override_path(service_name, region_name, external) / "_values.yaml"
common_service_override_file = (
get_service_value_override_path(service_name, region_name, external)
/ "_values.yaml"
)

with open(common_service_override_file, "rb") as f:
common_override_values = yaml.safe_load(f)
Expand All @@ -158,11 +162,12 @@ def get_common_regional_override(
except FileNotFoundError:
return {}


def get_hierarchical_value_overrides(
service_name: str,
region_name: str,
cluster_name: str = "default",
external: bool = False
external: bool = False,
) -> dict:
"""
Enables hierarchical configuration overrides with shared base values.
Expand Down Expand Up @@ -199,7 +204,9 @@ def get_hierarchical_value_overrides(

try:
service_override_file = (
get_service_value_override_path(service_name, override_group.name, external)
get_service_value_override_path(
service_name, override_group.name, external
)
/ "_values.yaml"
)

Expand All @@ -210,10 +217,7 @@ def get_hierarchical_value_overrides(

region_path = f"{override_group.name}/{region_name}"
region_values = get_service_value_overrides(
service_name,
region_path,
cluster_name,
external
service_name, region_path, cluster_name, external
)

if not region_values:
Expand Down

0 comments on commit 8292130

Please sign in to comment.