Skip to content

Commit 84099ae

Browse files
committed
Make it possible to link a specific container to a Sidecar in the manifest tests
1 parent 061dfe7 commit 84099ae

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/manifests/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def set_helm_values(self, all_values: dict[str, Any], propertyType: PropertyType
155155
def owns_manifest_named(self, manifest_name: str) -> bool:
156156
pass
157157

158+
@abc.abstractmethod
159+
def deployable_details_for_container(self, container_name: str | None) -> "DeployableDetails | None":
160+
pass
161+
158162

159163
@dataclass(unsafe_hash=True)
160164
class SidecarDetails(DeployableDetails):
@@ -187,6 +191,9 @@ def owns_manifest_named(self, manifest_name: str) -> bool:
187191

188192
return manifest_name.startswith(self.name)
189193

194+
def deployable_details_for_container(self, container_name: str | None) -> DeployableDetails | None:
195+
return self if container_name is not None and container_name.startswith(self.name) else None
196+
190197

191198
@dataclass(unsafe_hash=True)
192199
class SubComponentDetails(DeployableDetails):
@@ -201,6 +208,12 @@ def __post_init__(self):
201208
def owns_manifest_named(self, manifest_name: str) -> bool:
202209
return manifest_name.startswith(self.name)
203210

211+
def deployable_details_for_container(self, container_name: str | None) -> DeployableDetails:
212+
for sidecar in self.sidecars:
213+
if sidecar.deployable_details_for_container(container_name) is not None:
214+
return sidecar
215+
return self
216+
204217

205218
@dataclass(unsafe_hash=True)
206219
class ComponentDetails(DeployableDetails):
@@ -265,6 +278,12 @@ def owns_manifest_named(self, manifest_name: str) -> bool:
265278

266279
return manifest_name.startswith(self.name)
267280

281+
def deployable_details_for_container(self, container_name: str | None) -> DeployableDetails:
282+
for sidecar in self.sidecars:
283+
if sidecar.deployable_details_for_container(container_name) is not None:
284+
return sidecar
285+
return self
286+
268287

269288
all_components_details = [
270289
ComponentDetails(

tests/manifests/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ def iterate_synapse_workers_parts(
295295

296296
@pytest.fixture
297297
def template_to_deployable_details(deployables_details: tuple[DeployableDetails]):
298-
def _template_to_deployable_details(template: dict[str, Any]) -> DeployableDetails:
298+
def _template_to_deployable_details(
299+
template: dict[str, Any], container_name: str | None = None
300+
) -> DeployableDetails:
299301
# As per test_labels this doesn't have the release_name prefixed to it
300302
manifest_name: str = template["metadata"]["labels"]["app.kubernetes.io/name"]
301303

@@ -317,6 +319,10 @@ def _template_to_deployable_details(template: dict[str, Any]) -> DeployableDetai
317319
match = deployable_details
318320

319321
assert match is not None, f"{template_id(template)} can't be linked to any (sub-)component"
322+
match = match.deployable_details_for_container(container_name)
323+
assert match is not None, (
324+
f"{template_id(template)} can't be linked to any (sub-)component or specific container"
325+
)
320326
return match
321327

322328
return _template_to_deployable_details

0 commit comments

Comments
 (0)