Skip to content

Commit 2b7af1b

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

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

kubernetes/e2e_test/test_client.py

Lines changed: 41 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,23 @@ 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+
while True:
78+
try:
79+
resp = api.read_namespaced_service_account(name='default',
80+
namespace='default')
81+
except ApiException as e:
82+
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
83+
!six.PY3 and e.status != httplib.NOT_FOUND):
84+
print('error: %s' % e)
85+
self.fail(msg="unexpected error getting default service account")
86+
print('default service not found yet: %s' % e)
87+
time.sleep(1)
88+
continue
89+
self.assertEqual('default', resp.metadata.name)
90+
break
91+
6892
resp = api.create_namespaced_pod(body=pod_manifest,
6993
namespace='default')
7094
self.assertEqual(name, resp.metadata.name)
@@ -130,6 +154,23 @@ def test_exit_code(self):
130154

131155
name = 'busybox-test-' + short_uuid()
132156
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
157+
158+
# wait for the default service account to be created
159+
while True:
160+
try:
161+
resp = api.read_namespaced_service_account(name='default',
162+
namespace='default')
163+
except ApiException as e:
164+
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
165+
!six.PY3 and e.status != httplib.NOT_FOUND):
166+
print('error: %s' % e)
167+
self.fail(msg="unexpected error getting default service account")
168+
print('default service not found yet: %s' % e)
169+
time.sleep(1)
170+
continue
171+
self.assertEqual('default', resp.metadata.name)
172+
break
173+
133174
resp = api.create_namespaced_pod(body=pod_manifest,
134175
namespace='default')
135176
self.assertEqual(name, resp.metadata.name)

0 commit comments

Comments
 (0)