From 8371ccd29229c418dd8bb534fda3d28184c4e986 Mon Sep 17 00:00:00 2001 From: wutianwei Date: Wed, 22 Aug 2018 10:49:56 +0800 Subject: Spinnaker as a Service JIRA: CLOVER-52 1. Add mainfest to install the spinnaker in kubernetes cluster 2. after using mainfest to install spinnaker, we can interacte with the halyard daemon with its REST API and we can add/delete/list the dockerRegistry/kubernetes accounts. 3. Add the cloverctl to interate with the halyard daemon Change-Id: I71bc5977f2d65aab88fa55f7d7a53ab75eb6a46b Signed-off-by: wutianwei --- clover/orchestration/kube_client.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'clover/orchestration/kube_client.py') diff --git a/clover/orchestration/kube_client.py b/clover/orchestration/kube_client.py index f7fa708..582447b 100644 --- a/clover/orchestration/kube_client.py +++ b/clover/orchestration/kube_client.py @@ -9,6 +9,7 @@ from os import path import yaml from kubernetes import client, config +from kubernetes.stream import stream class KubeClient(object): @@ -120,3 +121,36 @@ class KubeClient(object): svc_name = body.get('metadata').get('name') return svc_name + + def copy_file_to_pod(self, source, destination, podname, namespace='default'): + # Note: only can copy file to the pod, which only include one container + exec_command = ['/bin/sh'] + resp = stream(self.core_v1.connect_get_namespaced_pod_exec, podname, + namespace, + command=exec_command, + stderr=True, stdin=True, + stdout=True, tty=False, + _preload_content=False) + + buffer = '' + with open(source, "rb") as file: + buffer += file.read() + + commands = [] + commands.append(bytes("cat <<'EOF' >" + destination + "\n")) + commands.append(buffer) + commands.append(bytes("EOF\n")) + + while resp.is_open(): + resp.update(timeout=1) + if resp.peek_stdout(): + print("STDOUT: %s" % resp.read_stdout()) + if resp.peek_stderr(): + print("STDERR: %s" % resp.read_stderr()) + if commands: + c = commands.pop(0) + resp.write_stdin(c) + else: + break + + resp.close() -- cgit 1.2.3-korg