Skip to content

e2e: use labels for configmap api; wait for default service account creation #1348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2021
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
2 changes: 1 addition & 1 deletion kubernetes/base
Submodule base updated 3 files
+4 −0 .travis.yml
+5 −2 dynamic/test_client.py
+3 −1 tox.ini
53 changes: 52 additions & 1 deletion kubernetes/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@
import time
import unittest
import uuid
import six

from kubernetes.client import api_client
from kubernetes.client.api import core_v1_api
from kubernetes.e2e_test import base
from kubernetes.stream import stream, portforward
from kubernetes.stream.ws_client import ERROR_CHANNEL
from kubernetes.client.rest import ApiException

import six.moves.urllib.request as urllib_request

if six.PY3:
from http import HTTPStatus
else:
import httplib

def short_uuid():
id = str(uuid.uuid4())
return id[-12:]
Expand Down Expand Up @@ -65,6 +72,27 @@ def test_pod_apis(self):

name = 'busybox-test-' + short_uuid()
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")

# wait for the default service account to be created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to give a timeout than wait forever

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/hold
wait for test results

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold cancel
The test is green

timeout = time.time() + 30
while True:
if time.time() > timeout:
print('timeout waiting for default service account creation')
break
try:
resp = api.read_namespaced_service_account(name='default',
namespace='default')
except ApiException as e:
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
six.PY3 is False and e.status != httplib.NOT_FOUND):
print('error: %s' % e)
self.fail(msg="unexpected error getting default service account")
print('default service not found yet: %s' % e)
time.sleep(1)
continue
self.assertEqual('default', resp.metadata.name)
break

resp = api.create_namespaced_pod(body=pod_manifest,
namespace='default')
self.assertEqual(name, resp.metadata.name)
Expand Down Expand Up @@ -130,6 +158,28 @@ def test_exit_code(self):

name = 'busybox-test-' + short_uuid()
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")

# wait for the default service account to be created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

timeout = time.time() + 30
while True:
if time.time() > timeout:
print('timeout waiting for default service account creation')
break

try:
resp = api.read_namespaced_service_account(name='default',
namespace='default')
except ApiException as e:
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
six.PY3 is False and e.status != httplib.NOT_FOUND):
print('error: %s' % e)
self.fail(msg="unexpected error getting default service account")
print('default service not found yet: %s' % e)
time.sleep(1)
continue
self.assertEqual('default', resp.metadata.name)
break

resp = api.create_namespaced_pod(body=pod_manifest,
namespace='default')
self.assertEqual(name, resp.metadata.name)
Expand Down Expand Up @@ -443,6 +493,7 @@ def test_configmap_apis(self):
"apiVersion": "v1",
"metadata": {
"name": name,
"labels": {"e2e-tests": "true"},
},
"data": {
"config.json": "{\"command\":\"/usr/bin/mysqld_safe\"}",
Expand All @@ -466,7 +517,7 @@ def test_configmap_apis(self):
resp = api.delete_namespaced_config_map(
name=name, body={}, namespace='default')

resp = api.list_namespaced_config_map('default', pretty=True)
resp = api.list_namespaced_config_map('default', pretty=True, label_selector="e2e-tests=true")
self.assertEqual([], resp.items)

def test_node_apis(self):
Expand Down
8 changes: 5 additions & 3 deletions kubernetes/e2e_test/test_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def config_map_with_value(name, value):
"kind": "ConfigMap",
"metadata": {
"name": name,
"labels": {"e2e-tests": "true"},
},
"data": {
"key": value,
Expand All @@ -57,7 +58,7 @@ def test_watch_configmaps(self):
body=configmap_a, namespace='default')

# list all configmaps and extract the resource version
resp = api.list_namespaced_config_map('default')
resp = api.list_namespaced_config_map('default', label_selector="e2e-tests=true")
rv = resp.metadata.resource_version

# create another configmap
Expand All @@ -73,7 +74,7 @@ def test_watch_configmaps(self):

# delete all configmaps
api.delete_collection_namespaced_config_map(
namespace='default')
namespace='default', label_selector="e2e-tests=true")

w = watch.Watch()
# expect to observe all events happened after the initial LIST
Expand All @@ -83,7 +84,8 @@ def test_watch_configmaps(self):
for event in w.stream(api.list_namespaced_config_map,
namespace='default',
resource_version=rv,
timeout_seconds=5):
timeout_seconds=5,
label_selector="e2e-tests=true"):
self.assertEqual(event['type'], expect[i])
# Kubernetes doesn't guarantee the order of the two objects
# being deleted
Expand Down