Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/630.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In tests for pods to services labels match, skip pods part of a previous-generation replicaset.
15 changes: 15 additions & 0 deletions tests/integration/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from lightkube import AsyncClient
from lightkube import operators as op
from lightkube.resources.apps_v1 import ReplicaSet
from lightkube.resources.core_v1 import Pod, Service
from prometheus_client.parser import text_string_to_metric_families

Expand Down Expand Up @@ -42,6 +43,20 @@ async def test_services_have_matching_labels(
async for pod in kube_client.list(Pod, namespace=generated_data.ess_namespace, labels=label_selectors):
if pod.status and pod.status.phase in ("Terminating", "Succeeded"):
continue # Skip terminating pods
# For Pods part of a replicaset we must ignore pods which template-hash do not match
# the latest replicaset `pod-template-hash`
if pod.metadata and pod.metadata.labels and pod.metadata.labels.get("pod-template-hash"):
async for rs in kube_client.list(
ReplicaSet,
namespace=generated_data.ess_namespace,
labels={"pod-template-hash": op.equal(pod.metadata.labels["pod-template-hash"])},
):
# we check if the rs desires replicas
if rs.spec and rs.spec.replicas:
break
else:
# Skip pods which do not have a ReplicaSet desiring replicas
continue
assert service.metadata, f"Encountered a service without metadata : {service}"
assert pod.metadata, f"Encountered a pod without metadata : {pod}"
assert pod.metadata.labels, f"Encountered a pod without labels : {pod}"
Expand Down
Loading