Skip to content

Commit 9093103

Browse files
committed
pod e2e: wait for the default service account to be created
1 parent 3b95adc commit 9093103

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

kubernetes/e2e_test/test_client.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@
1919
import time
2020
import unittest
2121
import uuid
22+
import six
2223

2324
from kubernetes.client import api_client
2425
from kubernetes.client.api import core_v1_api
2526
from kubernetes.e2e_test import base
2627
from kubernetes.stream import stream, portforward
2728
from kubernetes.stream.ws_client import ERROR_CHANNEL
29+
from kubernetes.client.rest import ApiException
2830

2931
import six.moves.urllib.request as urllib_request
3032

33+
if six.PY3:
34+
from http import HTTPStatus
35+
else:
36+
import httplib
37+
3138
def short_uuid():
3239
id = str(uuid.uuid4())
3340
return id[-12:]
@@ -65,6 +72,27 @@ def test_pod_apis(self):
6572

6673
name = 'busybox-test-' + short_uuid()
6774
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
75+
76+
# wait for the default service account to be created
77+
timeout = time.time() + 30
78+
while True:
79+
if time.time() > timeout:
80+
print('timeout waiting for default service account creation')
81+
break
82+
try:
83+
resp = api.read_namespaced_service_account(name='default',
84+
namespace='default')
85+
except ApiException as e:
86+
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
87+
six.PY3 is False and e.status != httplib.NOT_FOUND):
88+
print('error: %s' % e)
89+
self.fail(msg="unexpected error getting default service account")
90+
print('default service not found yet: %s' % e)
91+
time.sleep(1)
92+
continue
93+
self.assertEqual('default', resp.metadata.name)
94+
break
95+
6896
resp = api.create_namespaced_pod(body=pod_manifest,
6997
namespace='default')
7098
self.assertEqual(name, resp.metadata.name)
@@ -130,6 +158,28 @@ def test_exit_code(self):
130158

131159
name = 'busybox-test-' + short_uuid()
132160
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
161+
162+
# wait for the default service account to be created
163+
timeout = time.time() + 30
164+
while True:
165+
if time.time() > timeout:
166+
print('timeout waiting for default service account creation')
167+
break
168+
169+
try:
170+
resp = api.read_namespaced_service_account(name='default',
171+
namespace='default')
172+
except ApiException as e:
173+
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
174+
six.PY3 is False and e.status != httplib.NOT_FOUND):
175+
print('error: %s' % e)
176+
self.fail(msg="unexpected error getting default service account")
177+
print('default service not found yet: %s' % e)
178+
time.sleep(1)
179+
continue
180+
self.assertEqual('default', resp.metadata.name)
181+
break
182+
133183
resp = api.create_namespaced_pod(body=pod_manifest,
134184
namespace='default')
135185
self.assertEqual(name, resp.metadata.name)

0 commit comments

Comments
 (0)