diff --git a/.travis.yml b/.travis.yml index f67547b75..17993ef14 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,17 +13,8 @@ env: - TOXENV=docs - TOXENV=coverage,codecov -# We use hitch (https://hitch-tls.org/) to setup TLS proxy from 8443 to 8080. while hitch is -# in the ubuntu xenial main repos, it's not available by default on trusty. So we use the -# ppa from here : https://launchpad.net/~0k53d-karl-f830m/+archive/ubuntu/hitch -before_install: - - sudo add-apt-repository ppa:0k53d-karl-f830m/hitch -y - - sudo apt-get -qq update - - sudo apt-get install hitch - install: - pip install tox - - hitch --frontend=[*]:8443 --backend=[localhost]:8080 --daemon $TRAVIS_BUILD_DIR/scripts/example.pem script: - tox diff --git a/kubernetes/client/api_client.py b/kubernetes/client/api_client.py index c198b15d5..6dbe7137d 100644 --- a/kubernetes/client/api_client.py +++ b/kubernetes/client/api_client.py @@ -346,7 +346,7 @@ class ApiClient(object): """ # FIXME(dims) : We need a better way to figure out which # calls end up using web sockets - if url.endswith('/exec') and method == "GET": + if url.endswith('/exec') and (method == "GET" or method == "POST"): return ws_client.GET(self.config, url, query_params=query_params, diff --git a/kubernetes/e2e_test/base.py b/kubernetes/e2e_test/base.py index 2205a9976..5f04ab7e8 100644 --- a/kubernetes/e2e_test/base.py +++ b/kubernetes/e2e_test/base.py @@ -12,21 +12,34 @@ import copy import os +import unittest import urllib3 from kubernetes.client.configuration import configuration +from kubernetes.config import kube_config -def is_k8s_running(): - try: - urllib3.PoolManager().request('GET', '127.0.0.1:8080') - return True - except urllib3.exceptions.HTTPError: - return False +DEFAULT_E2E_HOST = '127.0.0.1' -def setSSLConfiguration(): +def get_e2e_configuration(): config = copy.copy(configuration) - config.verify_ssl = True - config.ssl_ca_cert = os.path.dirname(__file__) + '/../../scripts/example.pem' - config.assert_hostname = False - return config \ No newline at end of file + config.host = None + if os.path.exists( + os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)): + kube_config.load_kube_config(client_configuration=config) + else: + print('Unable to load config from %s' % + kube_config.KUBE_CONFIG_DEFAULT_LOCATION) + for url in ['https://%s:8443' % DEFAULT_E2E_HOST, + 'http://%s:8080' % DEFAULT_E2E_HOST]: + try: + urllib3.PoolManager().request('GET', url) + config.host = url + config.verify_ssl = False + break + except urllib3.exceptions.HTTPError: + pass + if config.host is None: + raise unittest.SkipTest('Unable to find a running Kubernetes instance') + print('Running test against : %s' % config.host) + return config diff --git a/kubernetes/e2e_test/test_batch.py b/kubernetes/e2e_test/test_batch.py index cb710baea..14800556b 100644 --- a/kubernetes/e2e_test/test_batch.py +++ b/kubernetes/e2e_test/test_batch.py @@ -17,7 +17,6 @@ import uuid from kubernetes.client import api_client from kubernetes.client.apis import batch_v1_api -from kubernetes.client.configuration import configuration from kubernetes.e2e_test import base @@ -25,13 +24,11 @@ class TestClientBatch(unittest.TestCase): @classmethod def setUpClass(cls): - cls.API_URL = 'http://127.0.0.1:8080/' - cls.config = configuration + cls.config = base.get_e2e_configuration() + - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_job_apis(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = batch_v1_api.BatchV1Api(client) name = 'test-job-' + str(uuid.uuid4()) @@ -59,12 +56,4 @@ class TestClientBatch(unittest.TestCase): self.assertEqual(name, resp.metadata.name) resp = api.delete_namespaced_job( - name=name, body={}, namespace='default') - - -class TestClientBatchSSL(TestClientBatch): - - @classmethod - def setUpClass(cls): - cls.API_URL = 'https://127.0.0.1:8443/' - cls.config = base.setSSLConfiguration() + name=name, body={}, namespace='default') \ No newline at end of file diff --git a/kubernetes/e2e_test/test_client.py b/kubernetes/e2e_test/test_client.py index ec2792987..8bc9b3d30 100644 --- a/kubernetes/e2e_test/test_client.py +++ b/kubernetes/e2e_test/test_client.py @@ -26,13 +26,10 @@ class TestClient(unittest.TestCase): @classmethod def setUpClass(cls): - cls.API_URL = 'http://127.0.0.1:8080/' - cls.config = configuration + cls.config = base.get_e2e_configuration() - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_pod_apis(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = core_v1_api.CoreV1Api(client) name = 'busybox-test-' + str(uuid.uuid4()) @@ -79,16 +76,22 @@ class TestClient(unittest.TestCase): print('EXEC response : %s' % resp) self.assertEqual(3, len(resp.splitlines())) + exec_command = 'uptime' + resp = api.connect_post_namespaced_pod_exec(name, 'default', + command=exec_command, + stderr=False, stdin=False, + stdout=True, tty=False) + print('EXEC response : %s' % resp) + self.assertEqual(1, len(resp.splitlines())) + number_of_pods = len(api.list_pod_for_all_namespaces().items) self.assertTrue(number_of_pods > 0) resp = api.delete_namespaced_pod(name=name, body={}, namespace='default') - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_service_apis(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = core_v1_api.CoreV1Api(client) name = 'frontend-' + str(uuid.uuid4()) @@ -126,10 +129,8 @@ class TestClient(unittest.TestCase): resp = api.delete_namespaced_service(name=name, namespace='default') - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_replication_controller_apis(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = core_v1_api.CoreV1Api(client) name = 'frontend-' + str(uuid.uuid4()) @@ -161,10 +162,8 @@ class TestClient(unittest.TestCase): resp = api.delete_namespaced_replication_controller( name=name, body={}, namespace='default') - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_configmap_apis(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = core_v1_api.CoreV1Api(client) name = 'test-configmap-' + str(uuid.uuid4()) @@ -199,21 +198,11 @@ class TestClient(unittest.TestCase): resp = api.list_namespaced_config_map('kube-system', pretty=True) self.assertEqual([], resp.items) - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_node_apis(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = core_v1_api.CoreV1Api(client) for item in api.list_node().items: node = api.read_node(name=item.metadata.name) self.assertTrue(len(node.metadata.labels) > 0) - self.assertTrue(isinstance(node.metadata.labels, dict)) - - -class TestClientSSL(TestClient): - - @classmethod - def setUpClass(cls): - cls.API_URL = 'https://127.0.0.1:8443/' - cls.config = base.setSSLConfiguration() + self.assertTrue(isinstance(node.metadata.labels, dict)) \ No newline at end of file diff --git a/kubernetes/e2e_test/test_extensions.py b/kubernetes/e2e_test/test_extensions.py index 69da8b8cf..d079410be 100644 --- a/kubernetes/e2e_test/test_extensions.py +++ b/kubernetes/e2e_test/test_extensions.py @@ -27,13 +27,10 @@ class TestClientExtensions(unittest.TestCase): @classmethod def setUpClass(cls): - cls.API_URL = 'http://127.0.0.1:8080/' - cls.config = configuration + cls.config = base.get_e2e_configuration() - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_create_deployment(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = extensions_v1beta1_api.ExtensionsV1beta1Api(client) name = 'nginx-deployment-' + str(uuid.uuid4()) deployment = '''apiVersion: extensions/v1beta1 @@ -62,10 +59,8 @@ spec: options = v1_delete_options.V1DeleteOptions() resp = api.delete_namespaced_deployment(name, 'default', body=options) - @unittest.skipUnless( - base.is_k8s_running(), "Kubernetes is not available") def test_create_daemonset(self): - client = api_client.ApiClient(self.API_URL, config=self.config) + client = api_client.ApiClient(config=self.config) api = extensions_v1beta1_api.ExtensionsV1beta1Api(client) name = 'nginx-app-' + str(uuid.uuid4()) daemonset = { @@ -97,12 +92,4 @@ spec: self.assertIsNotNone(resp) options = v1_delete_options.V1DeleteOptions() - resp = api.delete_namespaced_daemon_set(name, 'default', body=options) - - -class TestClientExtensionsSSL(TestClientExtensions): - - @classmethod - def setUpClass(cls): - cls.API_URL = 'https://127.0.0.1:8443/' - cls.config = base.setSSLConfiguration() + resp = api.delete_namespaced_daemon_set(name, 'default', body=options) \ No newline at end of file diff --git a/scripts/example.pem b/scripts/example.pem deleted file mode 100755 index 5031637b8..000000000 --- a/scripts/example.pem +++ /dev/null @@ -1,45 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC322Zo7ETx0bAw -0kJytMDPa76VT+TRgZj6AzS8xm+kRXeqLDJ+6ZmDvZkNKwbwIKAmccWvY/OJNv/0 -c5f1Hd6Y+vK9Qxi4f62ZbavKJpcxIFepa/hmrkRN0Iw9ZahzRZy07jw9SFxZTKEK -GTj/sb+SCUMwaJFZN0D6zhtqR70NjdHp14JWJsUtarBBtoGzEtINJgRkTS9ej6Fj -bh2RGz6HKiWQgX9W7v5P7zFek9IUDEczBr/aQlFXwE0tNUMjbZyMM4TfgITcx+mj -FbR3+hoZLJg0NMKT2wSiKvp1DU0KR5xF8S4q4OUC5yyvV2ylHPdvWldh+6LXcrx/ -oSxhpYDhAgMBAAECggEAUNZfhbx0Z9ppXF3mJ2b/63MVHbM+CTuxFiP4uROKnLCK -d8DtBs4Q2FKxi4+igkvl/mFBqOcKegc7rLByXKygZaTYu4xXvy8sFeyZfs1O5qOw -x2YYlpUCpTAPqSMcWGqABzFEPTGmoQDHQZhrbkkp0LzP1OX1GkPoBx4+AZG/Nsin -aWrTgfPNOtK2RGyLuS3rNn+NWh1jlm/37AVayKxSTirL5XXZUOW3Yye5ROZDWddr -rKzkhIsF/zcUxsQvFtMtjFPRFhKlasAx6MgPB2ptzj5Ykq29jumVfBd9O6voqDMW -ZFnN7G/wjLz8RM9hyW6hBLwIJV4ybJ1DagwqhGNzUQKBgQDxVQOsIWrHkxwZXA8a -iVJDpGlYc6jPlam2T2m3yXPqXfXlZ7Qx+RcmYY94QdEgeF1DGI8xNc1PSiSKjWH0 -+c3jbabB6kk82Qi2RzbApnjQdzlnWv29jiRgPVgPZcoSiMQFmtG8pUFgI8zOCsQK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Ud3pj68r1DGLh/rZltq8omlzEgV6lr+GauRE3QjD1l -qHNFnLTuPD1IXFlMoQoZOP+xv5IJQzBokVk3QPrOG2pHvQ2N0enXglYmxS1qsEG2 -gbMS0g0mBGRNL16PoWNuHZEbPocqJZCBf1bu/k/vMV6T0hQMRzMGv9pCUVfATS01 -QyNtnIwzhN+AhNzH6aMVtHf6GhksmDQ0wpPbBKIq+nUNTQpHnEXxLirg5QLnLK9X -bKUc929aV2H7otdyvH+hLGGlgOECAwEAAaMNMAswCQYDVR0TBAIwADANBgkqhkiG -9w0BAQsFAAOCAQEABblz/REaCmzZq/wlRN3NdwRuLvSz1peAVQNmuEfpIsYDxHIU -ognnm+afEo6O18PjBXFSP4r1vsc/TTGk1T3xP4FgPJ9xLsUNQk9Kch05vQIwJtcQ -iIdMRhGVdxSg8V29KTFImfcbS/VkV9Ev/FKHifs+PL9rJMBpE/r6xe6D6p+d9jw5 -cpCw+kgGHZVWA+8GEjyCGZIHyMAL6YwC246N6uTPuDHyvQZZHqh9r602bp5zpMbw -ZW4+YD7+PEAhFmTRYiqUPTyBPRBKcIZdkKtND/CQ4IwtHJ+ApjwQuXBjKUpPJroh -s5cwhxeaimBe9C9axIuuUd8LAVTXLFVwL0wEYw== ------END CERTIFICATE----- diff --git a/scripts/kube-init.sh b/scripts/kube-init.sh index 1348fa02b..66c7f3c0f 100755 --- a/scripts/kube-init.sh +++ b/scripts/kube-init.sh @@ -20,7 +20,7 @@ function clean_exit(){ local error_code="$?" local spawned=$(jobs -p) if [ -n "$spawned" ]; then - kill $(jobs -p) + sudo kill $(jobs -p) fi return $error_code } @@ -49,75 +49,48 @@ sudo systemctl start docker.service --ignore-dependencies echo "Checking docker service" sudo docker ps -# Run the docker containers for kubernetes -echo "Starting Kubernetes containers" -sudo docker run \ - --volume=/:/rootfs:ro \ - --volume=/sys:/sys:ro \ - --volume=/var/lib/docker/:/var/lib/docker:rw \ - --volume=/var/lib/kubelet/:/var/lib/kubelet:rw \ - --volume=/var/run:/var/run:rw \ - --net=host \ - --pid=host \ - --privileged=true \ - --name=kubelet \ - -d \ - gcr.io/google_containers/hyperkube-amd64:${K8S_VERSION} \ - /hyperkube kubelet \ - --containerized \ - --hostname-override="127.0.0.1" \ - --address="0.0.0.0" \ - --api-servers=http://localhost:8080 \ - --config=/etc/kubernetes/manifests \ - --allow-privileged=true --v=2 - - echo "Download Kubernetes CLI" wget -O kubectl "http://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl" -chmod 755 kubectl -./kubectl get nodes +sudo chmod +x kubectl +sudo mv kubectl /usr/local/bin/ -set +x -echo "Waiting for master components to start..." -for i in {1..300} -do - running_count=$(./kubectl -s=http://127.0.0.1:8080 get pods --no-headers 2>/dev/null | grep "Running" | wc -l) - # We expect to have 3 running pods - etcd, master and kube-proxy. - if [ "$running_count" -ge 3 ]; then - break - fi - echo -n "." - sleep 1 -done -set -x +echo "Download localkube from minikube project" +wget -O localkube "https://storage.googleapis.com/minikube/k8sReleases/v1.6.0-alpha.0/localkube-linux-amd64" +sudo chmod +x localkube +sudo mv localkube /usr/local/bin/ -echo "SUCCESS" -echo "Cluster created!" -echo "" +echo "Starting localkube" +sudo nohup localkube --logtostderr=true --enable-dns=false > localkube.log 2>&1 & + +echo "Waiting for localkube to start..." +if ! timeout 120 sh -c "while ! curl -ks https://127.0.0.1:8443/ >/dev/null; do sleep 1; done"; then + sudo cat localkube.log + die $LINENO "localkube did not start" +fi echo "Dump Kubernetes Objects..." -./kubectl -s=http://127.0.0.1:8080 get componentstatuses -./kubectl -s=http://127.0.0.1:8080 get configmaps -./kubectl -s=http://127.0.0.1:8080 get daemonsets -./kubectl -s=http://127.0.0.1:8080 get deployments -./kubectl -s=http://127.0.0.1:8080 get events -./kubectl -s=http://127.0.0.1:8080 get endpoints -./kubectl -s=http://127.0.0.1:8080 get horizontalpodautoscalers -./kubectl -s=http://127.0.0.1:8080 get ingress -./kubectl -s=http://127.0.0.1:8080 get jobs -./kubectl -s=http://127.0.0.1:8080 get limitranges -./kubectl -s=http://127.0.0.1:8080 get nodes -./kubectl -s=http://127.0.0.1:8080 get namespaces -./kubectl -s=http://127.0.0.1:8080 get pods -./kubectl -s=http://127.0.0.1:8080 get persistentvolumes -./kubectl -s=http://127.0.0.1:8080 get persistentvolumeclaims -./kubectl -s=http://127.0.0.1:8080 get quota -./kubectl -s=http://127.0.0.1:8080 get resourcequotas -./kubectl -s=http://127.0.0.1:8080 get replicasets -./kubectl -s=http://127.0.0.1:8080 get replicationcontrollers -./kubectl -s=http://127.0.0.1:8080 get secrets -./kubectl -s=http://127.0.0.1:8080 get serviceaccounts -./kubectl -s=http://127.0.0.1:8080 get services +kubectl get componentstatuses +kubectl get configmaps +kubectl get daemonsets +kubectl get deployments +kubectl get events +kubectl get endpoints +kubectl get horizontalpodautoscalers +kubectl get ingress +kubectl get jobs +kubectl get limitranges +kubectl get nodes +kubectl get namespaces +kubectl get pods +kubectl get persistentvolumes +kubectl get persistentvolumeclaims +kubectl get quota +kubectl get resourcequotas +kubectl get replicasets +kubectl get replicationcontrollers +kubectl get secrets +kubectl get serviceaccounts +kubectl get services echo "Running tests..."