tests/manifests: handle init-secrets job

This commit is contained in:
Gaël Goinvic committed 2025-02-04 17:03:10 +01:00
1 parent 086b7bc354
commit ea8b3cef58
7 files changed
+21 -16

No files matched your search

+5
View File
@@ -6,6 +6,11 @@ import copy
from typing import Any, Dict
_raw_component_details = {
"initSecrets": {
"hyphened_name": "init-secrets",
"has_service_monitor": False,
"has_ingress": False,
},
"elementWeb": {
"hyphened_name": "element-web",
"has_service_monitor": False,
+4 -4
View File
@@ -12,7 +12,7 @@ from .utils import iterate_component_workload_parts
@pytest.mark.asyncio_cooperative
async def test_sets_nonRoot_uids_gids_in_pod_securityContext_by_default(templates):
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
assert (
@@ -48,7 +48,7 @@ async def test_can_nuke_pod_securityContext_ids(component, values, make_template
)
for template in await make_templates(values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
assert (
@@ -65,7 +65,7 @@ async def test_can_nuke_pod_securityContext_ids(component, values, make_template
@pytest.mark.asyncio_cooperative
async def test_sets_seccompProfile_in_pod_securityContext_by_default(templates):
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
assert (
@@ -91,7 +91,7 @@ async def test_can_nuke_pod_securityContext_seccompProfile(component, values, ma
)
for template in await make_templates(values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
assert (
+1 -1
View File
@@ -70,7 +70,7 @@ async def test_secrets_consistency(templates):
This test checks if each secret is correctly associated with its respective volume and container,
ensuring that no inconsistencies or missing configurations exist.
"""
workloads = [t for t in templates if t["kind"] in ("Deployment", "StatefulSet")]
workloads = [t for t in templates if t["kind"] in ("Deployment", "StatefulSet", "Job")]
for template in workloads:
# Gather all containers and initContainers from the template spec
containers = template["spec"]["template"]["spec"].get("containers", []) + template["spec"]["template"][
+2 -2
View File
@@ -24,7 +24,7 @@ def find_services_matching_selector(templates: Iterator[Any], selector: Dict[str
def find_workload_ids_matching_selector(templates: Iterator[Any], selector: Dict[str, str]) -> list[str]:
workload_ids = []
for template in templates:
if template["kind"] in ("Deployment", "StatefulSet") and selector_match(
if template["kind"] in ("Deployment", "StatefulSet", "Job") and selector_match(
template["spec"]["template"]["metadata"]["labels"], selector
):
workload_ids.append(f"{template['kind']}/{template['metadata']['name']}")
@@ -99,7 +99,7 @@ async def test_service_monitored_as_appropriate(component, values: dict, make_te
template["kind"] != "ServiceMonitor"
), f"{component} unexpectedly has a ServiceMonitor when all are turned off"
if (
template["kind"] in ["Deployment", "StatefulSet"]
template["kind"] in ["Deployment", "StatefulSet", "Job"]
and template["metadata"]["labels"].get("servicemonitor", "some") != "none"
):
workloads_to_cover.add(f"{template['kind']}/{template['metadata']['name']}")
+4 -4
View File
@@ -14,7 +14,7 @@ from .utils import iterate_component_workload_parts
@pytest.mark.asyncio_cooperative
async def test_dont_automount_serviceaccount_tokens(templates):
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
assert not template["spec"]["template"]["spec"][
@@ -29,7 +29,7 @@ async def test_uses_serviceaccount_named_as_per_pod_controller_by_default(templa
serviceaccount_names = set()
covered_serviceaccount_names = set()
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
workloads_by_id[f"{template['kind']}/{template['metadata']['name']}"] = template
elif template["kind"] == "ServiceAccount":
serviceaccount_names.add(template["metadata"]["name"])
@@ -67,7 +67,7 @@ async def test_uses_serviceaccount_named_as_values_if_specified(component, value
workloads_by_id = {}
serviceaccount_names = []
for template in await make_templates(values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
workloads_by_id[f"{template['kind']}/{template['metadata']['name']}"] = template
elif template["kind"] == "ServiceAccount":
serviceaccount_names.append(template["metadata"]["name"])
@@ -104,7 +104,7 @@ async def test_does_not_create_serviceaccounts_if_configured_not_to(component, v
serviceaccount_names = set()
covered_serviceaccount_names = set()
for template in await make_templates(sub_component_values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id_suffix = f" (for {sub_component})" if sub_component != "" else ""
workloads_by_id[f"{template['kind']}/{template['metadata']['name']}{id_suffix}"] = template
elif template["kind"] == "ServiceAccount":
+4 -4
View File
@@ -26,7 +26,7 @@ global_toleration = {
@pytest.mark.asyncio_cooperative
async def test_no_tolerations_by_default(templates):
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
assert (
@@ -42,7 +42,7 @@ async def test_all_components_and_sub_components_render_tolerations(component, v
)
for template in await make_templates(values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
pod_spec = template["spec"]["template"]["spec"]
@@ -57,7 +57,7 @@ async def test_global_tolerations_render(values, make_templates):
values.setdefault("tolerations", []).append(global_toleration)
for template in await make_templates(values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
pod_spec = template["spec"]["template"]["spec"]
@@ -78,7 +78,7 @@ async def test_merges_global_and_specific_tolerations(component, values, make_te
values.get("tolerations").append(global_toleration)
for template in await make_templates(values):
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"
pod_spec = template["spec"]["template"]["spec"]
+1 -1
View File
@@ -13,7 +13,7 @@ async def test_volumes_mounts_exists(templates):
configmaps_names = [t["metadata"]["name"] for t in templates if t["kind"] == "ConfigMap"]
secrets_names = [t["metadata"]["name"] for t in templates if t["kind"] == "Secret"]
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet"]:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
volumes_names = []
for volume in template["spec"]["template"]["spec"].get("volumes", []):
volumes_names.append(volume["name"])