Skip to content

Commit 104869b

Browse files
dont expect a service without name
1 parent 07abbd2 commit 104869b

2 files changed

Lines changed: 35 additions & 27 deletions

File tree

tests/integration/lib/helpers.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,45 +110,54 @@ async def get_deployment_marker(kube_client, generated_data, marker: str):
110110

111111
async def run_pod_with_args(kube_client: AsyncClient, namespace, image_name, pod_name, args):
112112
pod = Pod(
113-
metadata=ObjectMeta(name=pod_name + "-" + str(int(time.time()*1000)), namespace=namespace),
114-
spec=PodSpec(restartPolicy="Never",
115-
containers=[Container(name="cmd", image=image_name, args=args,
116-
securityContext=SecurityContext(
117-
seccompProfile=SeccompProfile(type="RuntimeDefault"),
118-
capabilities=Capabilities(drop=["ALL"]),
119-
readOnlyRootFilesystem=True,
120-
allowPrivilegeEscalation=False,
121-
runAsNonRoot=True,
122-
runAsUser=3000,
123-
runAsGroup=3000,
124-
),
125-
)
126-
])
127-
)
113+
metadata=ObjectMeta(name=pod_name + "-" + str(int(time.time() * 1000)), namespace=namespace),
114+
spec=PodSpec(
115+
restartPolicy="Never",
116+
containers=[
117+
Container(
118+
name="cmd",
119+
image=image_name,
120+
args=args,
121+
securityContext=SecurityContext(
122+
seccompProfile=SeccompProfile(type="RuntimeDefault"),
123+
capabilities=Capabilities(drop=["ALL"]),
124+
readOnlyRootFilesystem=True,
125+
allowPrivilegeEscalation=False,
126+
runAsNonRoot=True,
127+
runAsUser=3000,
128+
runAsGroup=3000,
129+
),
130+
)
131+
],
132+
),
133+
)
128134
try:
129135
await kube_client.create(pod)
130136
start_time = time.time()
131137
now = time.time()
132138
completed = False
133139
while start_time + 30 > now and not completed:
134140
found_pod = await kube_client.get(Pod, name=pod.metadata.name, namespace=pod.metadata.namespace)
135-
if (found_pod.status.containerStatuses
141+
if (
142+
found_pod.status.containerStatuses
136143
and found_pod.status.containerStatuses[0].lastState
137144
and found_pod.status.containerStatuses[0].lastState.terminated
138-
and found_pod.status.containerStatuses[0].lastState.terminated.reason == "Completed"):
145+
and found_pod.status.containerStatuses[0].lastState.terminated.reason == "Completed"
146+
):
139147
completed = True
140148
else:
141149
now = time.time()
142150
await asyncio.sleep(1)
143151
else:
144152
if start_time + 30 > now:
145-
raise RuntimeError(f"Pod {pod.metadata.name} did not start in time "
146-
f"(failed after {time.time() - now} seconds), "
147-
f"pod status: {found_pod.status}")
153+
raise RuntimeError(
154+
f"Pod {pod.metadata.name} did not start in time "
155+
f"(failed after {time.time() - now} seconds), "
156+
f"pod status: {found_pod.status}"
157+
)
148158

149159
log_lines = ""
150-
async for log_line in kube_client.log(pod.metadata.name, namespace=pod.metadata.namespace,
151-
container="cmd"):
160+
async for log_line in kube_client.log(pod.metadata.name, namespace=pod.metadata.namespace, container="cmd"):
152161
log_lines += log_line
153162
return log_lines
154163
finally:

tests/integration/test_networking.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ async def test_pods_monitored(
140140
service_port_names = [port.name for port in service.spec.ports if port.name]
141141
if endpoint["port"] in service_port_names:
142142
break
143-
# This Service does not have the named port. Potentially there's another Service that covers it
144-
else:
145-
continue
146143

147144
async for covered_pod in kube_client.list(
148145
Pod, namespace=generated_data.ess_namespace, labels=service.spec.selector
@@ -165,7 +162,6 @@ async def test_pods_monitored(
165162
)
166163

167164

168-
169165
@pytest.mark.skipif(
170166
os.environ.get("SKIP_SERVICE_MONITORS_CRDS", "false") == "true", reason="ServiceMonitors not deployed"
171167
)
@@ -212,7 +208,10 @@ async def has_actual_metrics_on_endpoint(
212208
generated_data.ess_namespace,
213209
"curlimages/curl:latest",
214210
"curl",
215-
["-s", f"http://{service.metadata.name}.{generated_data.ess_namespace}.svc.cluster.local:{port_spec.port}/metrics"],
211+
[
212+
"-s",
213+
f"http://{service.metadata.name}.{generated_data.ess_namespace}.svc.cluster.local:{port_spec.port}/metrics",
214+
],
216215
)
217216
for metric_family in text_string_to_metric_families(metrics_data):
218217
assert metric_family.name, "Metric family has no name"

0 commit comments

Comments
 (0)