Skip to content

Commit 1635150

Browse files
authored
Merge pull request #123 from dims/try-localkube-for-e2e
Switch to minikube/localkube
2 parents cfd34ef + 353e8cc commit 1635150

File tree

8 files changed

+85
-188
lines changed

8 files changed

+85
-188
lines changed

.travis.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,8 @@ env:
1313
- TOXENV=docs
1414
- TOXENV=coverage,codecov
1515

16-
# We use hitch (https://hitch-tls.org/) to setup TLS proxy from 8443 to 8080. while hitch is
17-
# in the ubuntu xenial main repos, it's not available by default on trusty. So we use the
18-
# ppa from here : https://launchpad.net/~0k53d-karl-f830m/+archive/ubuntu/hitch
19-
before_install:
20-
- sudo add-apt-repository ppa:0k53d-karl-f830m/hitch -y
21-
- sudo apt-get -qq update
22-
- sudo apt-get install hitch
23-
2416
install:
2517
- pip install tox
26-
- hitch --frontend=[*]:8443 --backend=[localhost]:8080 --daemon $TRAVIS_BUILD_DIR/scripts/example.pem
2718

2819
script:
2920
- tox

kubernetes/client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def request(self, method, url, query_params=None, headers=None,
346346
"""
347347
# FIXME(dims) : We need a better way to figure out which
348348
# calls end up using web sockets
349-
if url.endswith('/exec') and method == "GET":
349+
if url.endswith('/exec') and (method == "GET" or method == "POST"):
350350
return ws_client.GET(self.config,
351351
url,
352352
query_params=query_params,

kubernetes/e2e_test/base.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@
1212

1313
import copy
1414
import os
15+
import unittest
1516
import urllib3
1617

1718
from kubernetes.client.configuration import configuration
19+
from kubernetes.config import kube_config
1820

19-
def is_k8s_running():
20-
try:
21-
urllib3.PoolManager().request('GET', '127.0.0.1:8080')
22-
return True
23-
except urllib3.exceptions.HTTPError:
24-
return False
21+
DEFAULT_E2E_HOST = '127.0.0.1'
2522

2623

27-
def setSSLConfiguration():
24+
def get_e2e_configuration():
2825
config = copy.copy(configuration)
29-
config.verify_ssl = True
30-
config.ssl_ca_cert = os.path.dirname(__file__) + '/../../scripts/example.pem'
31-
config.assert_hostname = False
32-
return config
26+
config.host = None
27+
if os.path.exists(
28+
os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)):
29+
kube_config.load_kube_config(client_configuration=config)
30+
else:
31+
print('Unable to load config from %s' %
32+
kube_config.KUBE_CONFIG_DEFAULT_LOCATION)
33+
for url in ['https://%s:8443' % DEFAULT_E2E_HOST,
34+
'http://%s:8080' % DEFAULT_E2E_HOST]:
35+
try:
36+
urllib3.PoolManager().request('GET', url)
37+
config.host = url
38+
config.verify_ssl = False
39+
break
40+
except urllib3.exceptions.HTTPError:
41+
pass
42+
if config.host is None:
43+
raise unittest.SkipTest('Unable to find a running Kubernetes instance')
44+
print('Running test against : %s' % config.host)
45+
return config

kubernetes/e2e_test/test_batch.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@
1717

1818
from kubernetes.client import api_client
1919
from kubernetes.client.apis import batch_v1_api
20-
from kubernetes.client.configuration import configuration
2120
from kubernetes.e2e_test import base
2221

2322

2423
class TestClientBatch(unittest.TestCase):
2524

2625
@classmethod
2726
def setUpClass(cls):
28-
cls.API_URL = 'http://127.0.0.1:8080/'
29-
cls.config = configuration
27+
cls.config = base.get_e2e_configuration()
28+
3029

31-
@unittest.skipUnless(
32-
base.is_k8s_running(), "Kubernetes is not available")
3330
def test_job_apis(self):
34-
client = api_client.ApiClient(self.API_URL, config=self.config)
31+
client = api_client.ApiClient(config=self.config)
3532
api = batch_v1_api.BatchV1Api(client)
3633

3734
name = 'test-job-' + str(uuid.uuid4())
@@ -59,12 +56,4 @@ def test_job_apis(self):
5956
self.assertEqual(name, resp.metadata.name)
6057

6158
resp = api.delete_namespaced_job(
62-
name=name, body={}, namespace='default')
63-
64-
65-
class TestClientBatchSSL(TestClientBatch):
66-
67-
@classmethod
68-
def setUpClass(cls):
69-
cls.API_URL = 'https://127.0.0.1:8443/'
70-
cls.config = base.setSSLConfiguration()
59+
name=name, body={}, namespace='default')

kubernetes/e2e_test/test_client.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ class TestClient(unittest.TestCase):
2626

2727
@classmethod
2828
def setUpClass(cls):
29-
cls.API_URL = 'http://127.0.0.1:8080/'
30-
cls.config = configuration
29+
cls.config = base.get_e2e_configuration()
3130

32-
@unittest.skipUnless(
33-
base.is_k8s_running(), "Kubernetes is not available")
3431
def test_pod_apis(self):
35-
client = api_client.ApiClient(self.API_URL, config=self.config)
32+
client = api_client.ApiClient(config=self.config)
3633
api = core_v1_api.CoreV1Api(client)
3734

3835
name = 'busybox-test-' + str(uuid.uuid4())
@@ -79,16 +76,22 @@ def test_pod_apis(self):
7976
print('EXEC response : %s' % resp)
8077
self.assertEqual(3, len(resp.splitlines()))
8178

79+
exec_command = 'uptime'
80+
resp = api.connect_post_namespaced_pod_exec(name, 'default',
81+
command=exec_command,
82+
stderr=False, stdin=False,
83+
stdout=True, tty=False)
84+
print('EXEC response : %s' % resp)
85+
self.assertEqual(1, len(resp.splitlines()))
86+
8287
number_of_pods = len(api.list_pod_for_all_namespaces().items)
8388
self.assertTrue(number_of_pods > 0)
8489

8590
resp = api.delete_namespaced_pod(name=name, body={},
8691
namespace='default')
8792

88-
@unittest.skipUnless(
89-
base.is_k8s_running(), "Kubernetes is not available")
9093
def test_service_apis(self):
91-
client = api_client.ApiClient(self.API_URL, config=self.config)
94+
client = api_client.ApiClient(config=self.config)
9295
api = core_v1_api.CoreV1Api(client)
9396

9497
name = 'frontend-' + str(uuid.uuid4())
@@ -126,10 +129,8 @@ def test_service_apis(self):
126129
resp = api.delete_namespaced_service(name=name,
127130
namespace='default')
128131

129-
@unittest.skipUnless(
130-
base.is_k8s_running(), "Kubernetes is not available")
131132
def test_replication_controller_apis(self):
132-
client = api_client.ApiClient(self.API_URL, config=self.config)
133+
client = api_client.ApiClient(config=self.config)
133134
api = core_v1_api.CoreV1Api(client)
134135

135136
name = 'frontend-' + str(uuid.uuid4())
@@ -161,10 +162,8 @@ def test_replication_controller_apis(self):
161162
resp = api.delete_namespaced_replication_controller(
162163
name=name, body={}, namespace='default')
163164

164-
@unittest.skipUnless(
165-
base.is_k8s_running(), "Kubernetes is not available")
166165
def test_configmap_apis(self):
167-
client = api_client.ApiClient(self.API_URL, config=self.config)
166+
client = api_client.ApiClient(config=self.config)
168167
api = core_v1_api.CoreV1Api(client)
169168

170169
name = 'test-configmap-' + str(uuid.uuid4())
@@ -199,21 +198,11 @@ def test_configmap_apis(self):
199198
resp = api.list_namespaced_config_map('kube-system', pretty=True)
200199
self.assertEqual([], resp.items)
201200

202-
@unittest.skipUnless(
203-
base.is_k8s_running(), "Kubernetes is not available")
204201
def test_node_apis(self):
205-
client = api_client.ApiClient(self.API_URL, config=self.config)
202+
client = api_client.ApiClient(config=self.config)
206203
api = core_v1_api.CoreV1Api(client)
207204

208205
for item in api.list_node().items:
209206
node = api.read_node(name=item.metadata.name)
210207
self.assertTrue(len(node.metadata.labels) > 0)
211-
self.assertTrue(isinstance(node.metadata.labels, dict))
212-
213-
214-
class TestClientSSL(TestClient):
215-
216-
@classmethod
217-
def setUpClass(cls):
218-
cls.API_URL = 'https://127.0.0.1:8443/'
219-
cls.config = base.setSSLConfiguration()
208+
self.assertTrue(isinstance(node.metadata.labels, dict))

kubernetes/e2e_test/test_extensions.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ class TestClientExtensions(unittest.TestCase):
2727

2828
@classmethod
2929
def setUpClass(cls):
30-
cls.API_URL = 'http://127.0.0.1:8080/'
31-
cls.config = configuration
30+
cls.config = base.get_e2e_configuration()
3231

33-
@unittest.skipUnless(
34-
base.is_k8s_running(), "Kubernetes is not available")
3532
def test_create_deployment(self):
36-
client = api_client.ApiClient(self.API_URL, config=self.config)
33+
client = api_client.ApiClient(config=self.config)
3734
api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
3835
name = 'nginx-deployment-' + str(uuid.uuid4())
3936
deployment = '''apiVersion: extensions/v1beta1
@@ -62,10 +59,8 @@ def test_create_deployment(self):
6259
options = v1_delete_options.V1DeleteOptions()
6360
resp = api.delete_namespaced_deployment(name, 'default', body=options)
6461

65-
@unittest.skipUnless(
66-
base.is_k8s_running(), "Kubernetes is not available")
6762
def test_create_daemonset(self):
68-
client = api_client.ApiClient(self.API_URL, config=self.config)
63+
client = api_client.ApiClient(config=self.config)
6964
api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
7065
name = 'nginx-app-' + str(uuid.uuid4())
7166
daemonset = {
@@ -97,12 +92,4 @@ def test_create_daemonset(self):
9792
self.assertIsNotNone(resp)
9893

9994
options = v1_delete_options.V1DeleteOptions()
100-
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
101-
102-
103-
class TestClientExtensionsSSL(TestClientExtensions):
104-
105-
@classmethod
106-
def setUpClass(cls):
107-
cls.API_URL = 'https://127.0.0.1:8443/'
108-
cls.config = base.setSSLConfiguration()
95+
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)

scripts/example.pem

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)