From 64df3fc65e810a4ecfea7446bd5fcb1c535cc0f5 Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Wed, 28 May 2025 14:39:13 +0100 Subject: [PATCH] Validate that workload selectors match the labels in the template. --- newsfragments/496.internal.md | 1 + tests/manifests/test_labels.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 newsfragments/496.internal.md diff --git a/newsfragments/496.internal.md b/newsfragments/496.internal.md new file mode 100644 index 00000000..3cbb908a --- /dev/null +++ b/newsfragments/496.internal.md @@ -0,0 +1 @@ +Validate that workload selectors match the labels in the template. diff --git a/tests/manifests/test_labels.py b/tests/manifests/test_labels.py index 2a1e079d..73b97ecc 100644 --- a/tests/manifests/test_labels.py +++ b/tests/manifests/test_labels.py @@ -128,3 +128,15 @@ async def test_our_labels_are_named_consistently(templates): assert has_match, ( f"{template_id(template)} has label {our_label} that does not match one of {acceptable_matches=}" ) + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_workloads_selector_matches_labels(templates): + for template in templates: + if template["kind"] in ("Deployment", "StatefulSet"): + for label in template["spec"]["selector"]["matchLabels"]: + assert ( + template["spec"]["template"]["metadata"]["labels"][label] + == template["spec"]["selector"]["matchLabels"][label] + )