Skip to content

Commit

Permalink
fix(kube): Ignore empty override files (#76)
Browse files Browse the repository at this point in the history
When a region override exists, but it is empty, parsing fails. Instead
the empty file should just be treated as empty.

`safe_load` returns `None` if the file contains no YAML documents (aka
when it is empty).

Came up in: getsentry/ops#13594
  • Loading branch information
Dav1dde authored Jan 14, 2025
1 parent 6dfaf79 commit f888abc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions libsentrykube/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ def get_service_values(service_name: str, external: bool = False) -> dict:
service_path = get_service_path(service_name)
try:
with open(service_path / "_values.yaml", "rb") as f:
values = yaml.safe_load(f)
return yaml.safe_load(f) or {}
except FileNotFoundError:
values = {}
return values
return {}


def get_service_value_override_path(
Expand Down Expand Up @@ -139,7 +138,7 @@ def get_service_value_overrides(
)

with open(service_override_file, "rb") as f:
values = yaml.safe_load(f)
values = yaml.safe_load(f) or {}

return values
except FileNotFoundError:
Expand All @@ -162,9 +161,7 @@ def get_common_regional_override(
)

with open(common_service_override_file, "rb") as f:
common_override_values = yaml.safe_load(f)

return common_override_values
return yaml.safe_load(f) or {}
except FileNotFoundError:
return {}

Expand Down Expand Up @@ -214,7 +211,7 @@ def get_hierarchical_value_overrides(
)

with open(service_override_file, "rb") as f:
base_values = yaml.safe_load(f)
base_values = yaml.safe_load(f) or {}
except FileNotFoundError:
base_values = {}

Expand Down Expand Up @@ -268,7 +265,7 @@ def get_tools_managed_service_value_overrides(

if service_override_file.exists() and service_override_file.is_file():
with open(service_override_file, "rb") as f:
return yaml.safe_load(f)
return yaml.safe_load(f) or {}

return {}

Expand Down

0 comments on commit f888abc

Please sign in to comment.