Setup kubernetes for Travis CI
This commit is contained in:
parent
770c6810e8
commit
c86f7ddb0e
|
@ -4,3 +4,26 @@ apt-get update -qq
|
||||||
wget https://github.com/miloyip/rapidjson/archive/v1.1.0.tar.gz -O /tmp/v1.1.0.tar.gz
|
wget https://github.com/miloyip/rapidjson/archive/v1.1.0.tar.gz -O /tmp/v1.1.0.tar.gz
|
||||||
tar -xvf /tmp/v1.1.0.tar.gz
|
tar -xvf /tmp/v1.1.0.tar.gz
|
||||||
cp -r $PWD/rapidjson-1.1.0/include/rapidjson /usr/include/
|
cp -r $PWD/rapidjson-1.1.0/include/rapidjson /usr/include/
|
||||||
|
|
||||||
|
|
||||||
|
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
|
||||||
|
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl && chmod +x kubectl
|
||||||
|
|
||||||
|
export MINIKUBE_WANTUPDATENOTIFICATION=false
|
||||||
|
export MINIKUBE_WANTREPORTERRORPROMPT=false
|
||||||
|
export MINIKUBE_HOME=$HOME
|
||||||
|
export CHANGE_MINIKUBE_NONE_USER=true
|
||||||
|
mkdir $HOME/.kube || true
|
||||||
|
touch $HOME/.kube/config
|
||||||
|
|
||||||
|
export KUBECONFIG=$HOME/.kube/config
|
||||||
|
./minikube start --vm-driver=none
|
||||||
|
|
||||||
|
# this for loop waits until kubectl can access the api server that Minikube has created
|
||||||
|
for i in {1..150}; do # timeout for 5 minutes
|
||||||
|
./kubectl get po &> /dev/null
|
||||||
|
if [ $? -ne 1 ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
|
@ -15,16 +15,15 @@ BDB_POD_SPEC = {}
|
||||||
|
|
||||||
class Node():
|
class Node():
|
||||||
|
|
||||||
def __init__(self, namespace='itest-api', name=None, spec=BDB_POD_SPEC):
|
def __init__(self, namespace='itest-setup', name=None, spec=BDB_POD_SPEC):
|
||||||
config = kubernetes.client.Configuration()
|
config = kubernetes.client.Configuration()
|
||||||
config.host = MINIKUBE_URI
|
config.host = MINIKUBE_URI
|
||||||
config.key_file = os.path.join(MINIKUBE_HOME, '.minikube/client.key')
|
config.key_file = os.path.join(MINIKUBE_HOME, '.minikube/client.key')
|
||||||
config.cert_file = os.path.join(MINIKUBE_HOME, '.minikube/client.crt')
|
config.cert_file = os.path.join(MINIKUBE_HOME, '.minikube/client.crt')
|
||||||
config.verify_ssl = False
|
config.verify_ssl = False
|
||||||
self.api_instance = kubernetes.client.CoreV1Api(kubernetes.client.ApiClient(config))
|
self.api_instance = kubernetes.client.CoreV1Api(kubernetes.client.ApiClient(config))
|
||||||
self.namesapce = namespace
|
self.namespace = namespace
|
||||||
self.name = name or uuid.uuid4().hex
|
self.name = name or uuid.uuid4().hex
|
||||||
self.uri = None
|
|
||||||
|
|
||||||
pod = kubernetes.client.V1Pod()
|
pod = kubernetes.client.V1Pod()
|
||||||
pod.version = 'v1'
|
pod.version = 'v1'
|
||||||
|
@ -38,40 +37,44 @@ class Node():
|
||||||
def start(self, return_after_running=True):
|
def start(self, return_after_running=True):
|
||||||
""" Start node."""
|
""" Start node."""
|
||||||
try:
|
try:
|
||||||
self.api_instance.create_namespaced_pod(self.namesapce, self.pod)
|
self.api_instance.create_namespaced_pod(self.namespace, self.pod)
|
||||||
if return_after_running:
|
if return_after_running:
|
||||||
for i in range(1, 20):
|
for i in range(1, 20):
|
||||||
if self.is_running:
|
if self.is_running:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except ApiException as e:
|
except ApiException as e:
|
||||||
pass
|
raise e
|
||||||
|
|
||||||
def stop(self, return_after_stopping=True):
|
def stop(self, return_after_stopping=True):
|
||||||
""" Stop node."""
|
""" Stop node."""
|
||||||
body = kubernetes.client.V1DeleteOptions()
|
body = kubernetes.client.V1DeleteOptions()
|
||||||
body.api_version = 'v1'
|
body.api_version = 'v1'
|
||||||
|
body.grace_period_seconds = 0
|
||||||
self.api_instance.delete_namespaced_pod(self.name, self.namespace, body)
|
self.api_instance.delete_namespaced_pod(self.name, self.namespace, body)
|
||||||
if return_after_stopping:
|
if return_after_stopping:
|
||||||
for i in range(1, 20):
|
for i in range(1, 20):
|
||||||
if self.is_running:
|
if not self.is_running:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_running(self):
|
def is_running(self):
|
||||||
"""Get the current status of node"""
|
"""Get the current status of node"""
|
||||||
resp = self.api_instance.read_namespaced_pod(self.name, self.namespace, exact=True)
|
try:
|
||||||
if resp['status']['phase'] == 'Running':
|
resp = self.api_instance.read_namespaced_pod(self.name, self.namespace, exact=True)
|
||||||
return True
|
if resp.status.phase == 'Running':
|
||||||
else:
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except ApiException as e:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def uri(self):
|
def uri(self):
|
||||||
if self.is_running:
|
if self.is_running:
|
||||||
resp = self.api_instance.read_namespaced_pod(self.name, self.namespace, exact=True)
|
resp = self.api_instance.read_namespaced_pod(self.name, self.namespace, exact=True)
|
||||||
return resp['status']['pod_ip']
|
return resp.status.pod_ip
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue