Skip to content

Commit 60e7d04

Browse files
committed
Make it possible to link a specific container to a Sidecar in the manifest tests
1 parent 496cd16 commit 60e7d04

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
@@ -257,7 +257,9 @@ def iterate_deployables_service_monitor_parts(
257257

258258
@pytest.fixture
259259
def template_to_deployable_details(deployables_details: tuple[DeployableDetails]):
260-
def _template_to_deployable_details(template: dict[str, Any]) -> DeployableDetails:
260+
def _template_to_deployable_details(
261+
template: dict[str, Any], container_name: str | None = None
262+
) -> DeployableDetails:
261263
# As per test_labels this doesn't have the release_name prefixed to it
262264
manifest_name: str = template["metadata"]["labels"]["app.kubernetes.io/name"]
263265

@@ -279,6 +281,10 @@ def _template_to_deployable_details(template: dict[str, Any]) -> DeployableDetai
279281
match = deployable_details
280282

281283
assert match is not None, f"{template_id(template)} can't be linked to any (sub-)component"
284+
match = match.deployable_details_for_container(container_name)
285+
assert match is not None, (
286+
f"{template_id(template)} can't be linked to any (sub-)component or specific container"
287+
)
282288
return match
283289

284290
return _template_to_deployable_details

0 commit comments

Comments
 (0)