Skip to content

Commit 2975fa1

Browse files
Merge pull request #630 from element-hq/gaelg/skip-pods-not-current-replicaset
skip pods part of a previous replicaset generation
2 parents f1f06a0 + 62c7081 commit 2975fa1

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

newsfragments/630.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In tests for pods to services labels match, skip pods part of a previous-generation replicaset.

tests/integration/test_networking.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99
from lightkube import AsyncClient
1010
from lightkube import operators as op
11+
from lightkube.resources.apps_v1 import ReplicaSet
1112
from lightkube.resources.core_v1 import Pod, Service
1213
from prometheus_client.parser import text_string_to_metric_families
1314

@@ -42,6 +43,20 @@ async def test_services_have_matching_labels(
4243
async for pod in kube_client.list(Pod, namespace=generated_data.ess_namespace, labels=label_selectors):
4344
if pod.status and pod.status.phase in ("Terminating", "Succeeded"):
4445
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
4560
assert service.metadata, f"Encountered a service without metadata : {service}"
4661
assert pod.metadata, f"Encountered a pod without metadata : {pod}"
4762
assert pod.metadata.labels, f"Encountered a pod without labels : {pod}"

0 commit comments

Comments
 (0)