Skip to content

Commit 4694f5d

Browse files
dont expect a service without name
1 parent 5486246 commit 4694f5d

2 files changed

Lines changed: 40 additions & 28 deletions

File tree

tests/integration/lib/helpers.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,45 +110,58 @@ 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+
)
134+
assert pod.metadata
135+
assert pod.metadata.name
136+
assert pod.metadata.namespace
128137
try:
129138
await kube_client.create(pod)
130139
start_time = time.time()
131140
now = time.time()
132141
completed = False
133142
while start_time + 30 > now and not completed:
134143
found_pod = await kube_client.get(Pod, name=pod.metadata.name, namespace=pod.metadata.namespace)
135-
if (found_pod.status.containerStatuses
144+
if (
145+
found_pod.status
146+
and found_pod.status.containerStatuses
136147
and found_pod.status.containerStatuses[0].lastState
137148
and found_pod.status.containerStatuses[0].lastState.terminated
138-
and found_pod.status.containerStatuses[0].lastState.terminated.reason == "Completed"):
149+
and found_pod.status.containerStatuses[0].lastState.terminated.reason == "Completed"
150+
):
139151
completed = True
140152
else:
141153
now = time.time()
142154
await asyncio.sleep(1)
143155
else:
144156
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}")
157+
raise RuntimeError(
158+
f"Pod {pod.metadata.name} did not start in time "
159+
f"(failed after {time.time() - now} seconds), "
160+
f"pod status: {found_pod.status}"
161+
)
148162

149163
log_lines = ""
150-
async for log_line in kube_client.log(pod.metadata.name, namespace=pod.metadata.namespace,
151-
container="cmd"):
164+
async for log_line in kube_client.log(pod.metadata.name, namespace=pod.metadata.namespace, container="cmd"):
152165
log_lines += log_line
153166
return log_lines
154167
finally:

tests/integration/test_networking.py

Lines changed: 5 additions & 6 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
)
@@ -203,7 +199,7 @@ async def test_service_monitors_point_to_metrics(
203199
async def has_actual_metrics_on_endpoint(
204200
kube_client: AsyncClient, generated_data: ESSData, service: Service, endpoints
205201
):
206-
assert service.metadataco
202+
assert service.metadata
207203
assert service.spec
208204
assert service.spec.ports
209205
found_metrics = False
@@ -215,7 +211,10 @@ async def has_actual_metrics_on_endpoint(
215211
generated_data.ess_namespace,
216212
"curlimages/curl:latest",
217213
"curl",
218-
["-s", f"http://{service.metadata.name}.{generated_data.ess_namespace}.svc.cluster.local:{port_spec.port}/metrics"],
214+
[
215+
"-s",
216+
f"http://{service.metadata.name}.{generated_data.ess_namespace}.svc.cluster.local:{port_spec.port}/metrics",
217+
],
219218
)
220219
for metric_family in text_string_to_metric_families(metrics_data):
221220
assert metric_family.name, "Metric family has no name"

0 commit comments

Comments
 (0)