Skip to content

Commit

Permalink
pod e2e: wait for the default service account to be created
Browse files Browse the repository at this point in the history
  • Loading branch information
roycaihw committed Jan 13, 2021
1 parent 3b95adc commit 9093103
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions 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
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
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

0 comments on commit 9093103

Please sign in to comment.