|
8 | 8 | import pytest |
9 | 9 | from lightkube import AsyncClient |
10 | 10 | from lightkube import operators as op |
| 11 | +from lightkube.resources.apps_v1 import ReplicaSet |
11 | 12 | from lightkube.resources.core_v1 import Pod, Service |
12 | 13 | from prometheus_client.parser import text_string_to_metric_families |
13 | 14 |
|
@@ -42,6 +43,20 @@ async def test_services_have_matching_labels( |
42 | 43 | async for pod in kube_client.list(Pod, namespace=generated_data.ess_namespace, labels=label_selectors): |
43 | 44 | if pod.status and pod.status.phase in ("Terminating", "Succeeded"): |
44 | 45 | continue # Skip terminating pods |
| 46 | + # For Pods part of a replicaset we must ignore pods which template-hash do not match |
| 47 | + # the latest replicaset `pod-template-hash` |
| 48 | + if pod.metadata and pod.metadata.labels and pod.metadata.labels.get("pod-template-hash"): |
| 49 | + async for rs in kube_client.list( |
| 50 | + ReplicaSet, |
| 51 | + namespace=generated_data.ess_namespace, |
| 52 | + labels={"pod-template-hash": op.equal(pod.metadata.labels["pod-template-hash"])}, |
| 53 | + ): |
| 54 | + # we check if the rs desires replicas |
| 55 | + if rs.spec and rs.spec.replicas: |
| 56 | + break |
| 57 | + else: |
| 58 | + # Skip pods which do not have a ReplicaSet desiring replicas |
| 59 | + continue |
45 | 60 | assert service.metadata, f"Encountered a service without metadata : {service}" |
46 | 61 | assert pod.metadata, f"Encountered a pod without metadata : {pod}" |
47 | 62 | assert pod.metadata.labels, f"Encountered a pod without labels : {pod}" |
|
0 commit comments