Skip to content

Commit e14b589

Browse files
test automount service account policy against jobs
1 parent 0369eb1 commit e14b589

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

newsfragments/625.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check automount service account policy against Job in tests.

tests/manifests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class DeployableDetails(abc.ABC):
9797
has_db: bool = field(default=False, hash=False)
9898
has_image: bool = field(default=None, hash=False) # type: ignore[assignment]
9999
has_ingress: bool = field(default=True, hash=False)
100+
has_automount_service_account_token: bool = field(default=False, hash=False)
100101
has_workloads: bool = field(default=True, hash=False)
101102
has_replicas: bool = field(default=None, hash=False) # type: ignore[assignment]
102103
has_service_monitor: bool = field(default=None, hash=False) # type: ignore[assignment]
@@ -410,6 +411,7 @@ def make_synapse_worker_sub_component(worker_name: str, worker_type: str) -> Sub
410411
},
411412
has_image=False,
412413
has_ingress=False,
414+
has_automount_service_account_token=True,
413415
has_replicas=False,
414416
has_service_monitor=False,
415417
has_topology_spread_constraints=False,
@@ -429,6 +431,7 @@ def make_synapse_worker_sub_component(worker_name: str, worker_type: str) -> Sub
429431
},
430432
has_image=False,
431433
has_ingress=False,
434+
has_automount_service_account_token=True,
432435
has_replicas=False,
433436
has_service_monitor=False,
434437
has_topology_spread_constraints=False,
@@ -531,6 +534,7 @@ def make_synapse_worker_sub_component(worker_name: str, worker_type: str) -> Sub
531534
PropertyType.StartupProbe: ValuesFilePath.not_supported(),
532535
},
533536
has_ingress=False,
537+
has_automount_service_account_token=True,
534538
has_replicas=False,
535539
has_service_monitor=False,
536540
has_topology_spread_constraints=False,

tests/manifests/test_serviceaccounts.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
import pytest
88

99
from . import DeployableDetails, PropertyType, all_deployables_details, values_files_to_test
10-
from .utils import iterate_deployables_workload_parts, template_id
10+
from .utils import iterate_deployables_workload_parts, template_id, template_to_deployable_details
1111

1212

1313
@pytest.mark.parametrize("values_file", values_files_to_test)
1414
@pytest.mark.asyncio_cooperative
1515
async def test_dont_automount_serviceaccount_tokens(templates):
1616
for template in templates:
17-
if template["kind"] in ["Deployment", "StatefulSet"]:
18-
assert not template["spec"]["template"]["spec"]["automountServiceAccountToken"], (
19-
f"ServiceAccount token automounted for {template_id(template)}"
20-
)
17+
deployable_details = template_to_deployable_details(template)
18+
assert (
19+
deployable_details.has_automount_service_account_token
20+
== template["spec"]["template"]["spec"]["automountServiceAccountToken"]
21+
)
2122

2223

2324
@pytest.mark.parametrize("values_file", values_files_to_test)

0 commit comments

Comments
 (0)