Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kube): Ignore empty override files #76

Merged
merged 1 commit into from
Jan 14, 2025
Merged

Conversation

Dav1dde
Copy link
Member

@Dav1dde Dav1dde commented Jan 14, 2025

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: https://github.com/getsentry/ops/pull/13594

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/sentry_kube/validate_services.py", line 89, in <module>
    test_services()
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/sentry_kube/validate_services.py", line 56, in test_services
    lint_errors_count += lint_and_print(
                         ^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/libsentrykube/lint.py", line 185, in lint_and_print
    for doc in rendered:
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/libsentrykube/kube.py", line 199, in render_services
    out = render_templates(
          ^^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/libsentrykube/kube.py", line [22](https://github.com/getsentry/ops/actions/runs/12765101378/job/35578617967?pr=13594#step:7:23)8, in render_templates
    render_data["values"] = _consolidate_variables(
                            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/libsentrykube/kube.py", line 158, in _consolidate_variables
    hierarchical_values = get_hierarchical_value_overrides(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/libsentrykube/service.py", line [23](https://github.com/getsentry/ops/actions/runs/12765101378/job/35578617967?pr=13594#step:7:24)8, in get_hierarchical_value_overrides
    deep_merge_dict(base_values, region_values)
  File "/home/runner/work/ops/ops/.venv/lib/python3.11/site-packages/libsentrykube/utils.py", line 366, in deep_merge_dict
    for k, v in other.items():
                ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'items'

@Dav1dde Dav1dde requested a review from a team as a code owner January 14, 2025 11:25
@Dav1dde Dav1dde requested a review from Litarnus January 14, 2025 11:25
@Dav1dde Dav1dde self-assigned this Jan 14, 2025
@rgibert rgibert merged commit f888abc into main Jan 14, 2025
6 checks passed
@rgibert rgibert deleted the dav1d/ignore-empty-override branch January 14, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants