Use the dynamic pod name in e2e when used on the same cluster many times
@@ -10,18 +10,18 @@ def test_pods_reacted():
example_py = os.path.join(os.path.dirname(__file__), 'example.py')
with kopf.testing.KopfRunner(['run', '--standalone', '--verbose', example_py]) as runner:
- _create_pod()
+ name = _create_pod()
time.sleep(5) # give it some time to react
- _delete_pod()
+ _delete_pod(name)
time.sleep(1) # give it some time to react
assert runner.exception is None
assert runner.exit_code == 0
- assert '[default/kopf-pod-1] Creation event:' in runner.stdout
- assert '[default/kopf-pod-1] === Pod killing happens in 30s.' in runner.stdout
- assert '[default/kopf-pod-1] Deletion event:' in runner.stdout
- assert '[default/kopf-pod-1] === Pod killing is cancelled!' in runner.stdout
+ assert f'[default/{name}] Creation event:' in runner.stdout
+ assert f'[default/{name}] === Pod killing happens in 30s.' in runner.stdout
+ assert f'[default/{name}] Deletion event:' in runner.stdout
+ assert f'[default/{name}] === Pod killing is cancelled!' in runner.stdout
def _create_pod():
@@ -29,7 +29,7 @@ def _create_pod():
pod = pykube.Pod(api, {
'apiVersion': 'v1',
'kind': 'Pod',
- 'metadata': {'name': 'kopf-pod-1', 'namespace': 'default'},
+ 'metadata': {'generateName': 'kopf-pod-', 'namespace': 'default'},
'spec': {
'containers': [{
'name': 'the-only-one',
@@ -38,9 +38,10 @@ def _create_pod():
}]},
})
pod.create()
+ return pod.name
-def _delete_pod():
+def _delete_pod(name):
api = pykube.HTTPClient(pykube.KubeConfig.from_file())
- pod = pykube.Pod.objects(api, namespace='default').get_by_name('kopf-pod-1')
+ pod = pykube.Pod.objects(api, namespace='default').get_by_name(name)
pod.delete()
