Merge pull request #1348 from roycaihw/configmap-e2e/labels

e2e: use labels for configmap api; wait for default service account creation
This commit is contained in:
Kubernetes Prow Robot 2021-01-12 19:18:35 -08:00 committed by GitHub
commit 3e615b60b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 5 deletions

@ -1 +1 @@
Subproject commit 2da2b981ca806b25487ad92d01a2164815c18517
Subproject commit b0021104307c99bac5b2a7e353df21d864f85809

View File

@ -19,15 +19,22 @@ import socket
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:]
@ -65,6 +72,27 @@ class TestClient(unittest.TestCase):
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
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)
@ -130,6 +158,28 @@ class TestClient(unittest.TestCase):
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
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)
@ -443,6 +493,7 @@ class TestClient(unittest.TestCase):
"apiVersion": "v1",
"metadata": {
"name": name,
"labels": {"e2e-tests": "true"},
},
"data": {
"config.json": "{\"command\":\"/usr/bin/mysqld_safe\"}",
@ -466,7 +517,7 @@ class TestClient(unittest.TestCase):
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):

View File

@ -32,6 +32,7 @@ def config_map_with_value(name, value):
"kind": "ConfigMap",
"metadata": {
"name": name,
"labels": {"e2e-tests": "true"},
},
"data": {
"key": value,
@ -57,7 +58,7 @@ class TestClient(unittest.TestCase):
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
@ -73,7 +74,7 @@ class TestClient(unittest.TestCase):
# 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
@ -83,7 +84,8 @@ class TestClient(unittest.TestCase):
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