From 13fd26c9dfdfbe70eba3da738cc932814b072b92 Mon Sep 17 00:00:00 2001 From: "Yang (Gabriel) Yu" Date: Thu, 9 Aug 2018 13:07:31 +0800 Subject: add k8s test configs preparation JIRA: BOTTLENECK-243 Change-Id: I994c71f03c4c2429d62618920cfc92fc1ed16abe Signed-off-by: Yang (Gabriel) Yu --- requirements/requirements.txt | 1 + utils/k8s_setup/__init__.py | 0 utils/k8s_setup/golang_install.sh | 100 ++++++++++++++++++++++++++++++++++++ utils/k8s_setup/k8s_config_pre.sh | 66 ++++++++++++++++++++++++ utils/k8s_setup/k8s_env.sh | 13 +++++ utils/k8s_setup/k8s_utils.py | 28 ++++++++++ utils/k8s_setup/kubectl_install.sh | 33 ++++++++++++ utils/kube_setup/__init__.py | 0 utils/kube_setup/install_golang.sh | 100 ------------------------------------ utils/kube_setup/install_kubectl.sh | 33 ------------ utils/kube_setup/kube_env.sh | 13 ----- 11 files changed, 241 insertions(+), 146 deletions(-) create mode 100644 utils/k8s_setup/__init__.py create mode 100644 utils/k8s_setup/golang_install.sh create mode 100644 utils/k8s_setup/k8s_config_pre.sh create mode 100644 utils/k8s_setup/k8s_env.sh create mode 100644 utils/k8s_setup/k8s_utils.py create mode 100644 utils/k8s_setup/kubectl_install.sh delete mode 100644 utils/kube_setup/__init__.py delete mode 100644 utils/kube_setup/install_golang.sh delete mode 100644 utils/kube_setup/install_kubectl.sh delete mode 100644 utils/kube_setup/kube_env.sh diff --git a/requirements/requirements.txt b/requirements/requirements.txt index dacffcea..381cb5cd 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -18,3 +18,4 @@ nose==1.3.7 pyroute2==0.4.10 elasticsearch==5.0.1 docker==2.0.2 +kubernetes==6.0.0 diff --git a/utils/k8s_setup/__init__.py b/utils/k8s_setup/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/utils/k8s_setup/golang_install.sh b/utils/k8s_setup/golang_install.sh new file mode 100644 index 00000000..06c54cee --- /dev/null +++ b/utils/k8s_setup/golang_install.sh @@ -0,0 +1,100 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +usage="Script to install and config golang of specific version. + +usage: + bash $(basename "$0") [-h|--help] [-v|--version ] [--debug] + +where: + -h|--help show the help text + -v|--version input the version of golang + --debug debug option switch +examples: + $(basename "$0") -v 1.10.3" + +# Debug option +redirect="/dev/null" + +# Process input variables +while [[ $# > 0 ]] + do + key="$1" + case $key in + -h|--help) + echo "$usage" + exit 0 + shift + ;; + -v|--version) + GOLANG_VERSION="$2" + shift + ;; + --debug) + redirect="/dev/stdout" + shift + ;; + *) + echo "unkown option $1 $2" + exit 1 + ;; + esac + shift +done + +#set -e + +echo "=======Downloading golang of version: ${GOLANG_VERSION}========" + +if [[ -f go${GOLANG_VERSION}.linux-amd64.tar.gz ]]; then + rm go${GOLANG_VERSION}.linux-amd64.tar.gz +fi +curl -O https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect} + +echo "Installing golang of version: ${GOLANG_VERSION}" +if [[ -d /usr/local/go ]]; then + rm -rf /usr/local/go +fi + +tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect} + +if [[ -d $HOME/go ]]; then + rm -rf ${HOME}/go + mkdir ${HOME}/go + mkdir ${HOME}/go/bin + mkdir ${HOME}/go/src +else + mkdir ${HOME}/go + mkdir ${HOME}/go/bin + mkdir ${HOME}/go/src +fi + +echo "Adding golang env to ~/.bashrc" +GOROOT=/usr/local/go +GOPATH=${HOME}/go + +if [[ $(cat ${HOME}/.bashrc | grep GOROOT) ]]; then + echo "golang env alreay in ${HOME}/.bashrc" +else + cat <> ${HOME}/.bashrc + +export GOROOT=/usr/local/go +export GOPATH=${HOME}/go +export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin +EOF +fi + +export GOROOT=/usr/local/go +export GOPATH=${HOME}/go +export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin + +echo "Running go version command:" +go version + +echo "=======Installation of golang-${GOLANG_VERSION} complete=======" + diff --git a/utils/k8s_setup/k8s_config_pre.sh b/utils/k8s_setup/k8s_config_pre.sh new file mode 100644 index 00000000..f41ba78d --- /dev/null +++ b/utils/k8s_setup/k8s_config_pre.sh @@ -0,0 +1,66 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +K8S_CONFIG="/tmp/k8s_conig" + +usage="Script to prepare kubenetes test configurations. + +usage: + bash $(basename "$0") [-h|--help] [-i|--installer ] [-c|--config ] + +where: + -h|--help show the help text + -i|--installer specify the installer for the system to be monitored + + one of the following: + (compass) +examples: + $(basename "$0") -i compass" + + +info () { + logger -s -t "BOTTLENECKS INFO" "$*" +} + +error () { + logger -s -t "BOTTLENECKS ERROR" "$*" + exit 1 +} + +# Process input variables +while [[ $# > 0 ]] + do + key="$1" + case $key in + -h|--help) + echo "$usage" + exit 0 + shift + ;; + -i|--installer) + INSTALLER_TYPE="$2" + shift + ;; + -c|--config) + K8S_CONFIG="$2" + shift + ;; + *) + error "unkown input options $1 $2" + exit 1 + ;; + esac + shift +done + +if [[ ${INSTALLER_TYPE} == 'compass' ]]; then + sshpass -p root scp root@192.16.1.222:~/.kube/config ${K8S_CONFIG} +else + echo "BOTTLENECKS EROOR: unrecognized installer" +fi diff --git a/utils/k8s_setup/k8s_env.sh b/utils/k8s_setup/k8s_env.sh new file mode 100644 index 00000000..855dea2f --- /dev/null +++ b/utils/k8s_setup/k8s_env.sh @@ -0,0 +1,13 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +export GOROOT=/usr/local/go +export GOPATH=${HOME}/go +export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin + diff --git a/utils/k8s_setup/k8s_utils.py b/utils/k8s_setup/k8s_utils.py new file mode 100644 index 00000000..afcdb307 --- /dev/null +++ b/utils/k8s_setup/k8s_utils.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import os +import utils.logger as log + +LOG = log.Logger(__name__).getLogger() +INSTALLER_TYPE = os.getenv("INSTALLER_TYPE") + + +def get_config_path(INSTALLER_TYPE=None, CONFIG_PATH="/tmp/k8s_config"): + if INSTALLER_TYPE: + CMD = "bash k8s_config_pre.sh -i " + INSTALLER_TYPE + \ + " -c " + CONFIG_PATH + LOG.info("Executing command: " + CMD) + CONFIG_PATH = os.popen(CMD) + else: + if not os.path.exists(CONFIG_PATH): + raise Exception("Must at least specify the path \ +of k8s config!") + return CONFIG_PATH diff --git a/utils/k8s_setup/kubectl_install.sh b/utils/k8s_setup/kubectl_install.sh new file mode 100644 index 00000000..14f97f2b --- /dev/null +++ b/utils/k8s_setup/kubectl_install.sh @@ -0,0 +1,33 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +OS_TYPE=$(uname -a) +OS_UBUNTU=$(echo $OS_TYPE | grep ubuntu) + +if [[ $OS_UBUNTU ]]; then + apt-get update && apt-get install -y apt-transport-https + curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - + touch /etc/apt/sources.list.d/kubernetes.list + echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list + apt-get update + apt-get install -y kubectl +else + cat < /etc/yum.repos.d/kubernetes.repo +[kubernetes] +name=Kubernetes +baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 +enabled=1 +gpgcheck=1 +repo_gpgcheck=1 +gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg +EOF + yum install -y kubectl +fi + diff --git a/utils/kube_setup/__init__.py b/utils/kube_setup/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/utils/kube_setup/install_golang.sh b/utils/kube_setup/install_golang.sh deleted file mode 100644 index 06c54cee..00000000 --- a/utils/kube_setup/install_golang.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash -############################################################################## -# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## -usage="Script to install and config golang of specific version. - -usage: - bash $(basename "$0") [-h|--help] [-v|--version ] [--debug] - -where: - -h|--help show the help text - -v|--version input the version of golang - --debug debug option switch -examples: - $(basename "$0") -v 1.10.3" - -# Debug option -redirect="/dev/null" - -# Process input variables -while [[ $# > 0 ]] - do - key="$1" - case $key in - -h|--help) - echo "$usage" - exit 0 - shift - ;; - -v|--version) - GOLANG_VERSION="$2" - shift - ;; - --debug) - redirect="/dev/stdout" - shift - ;; - *) - echo "unkown option $1 $2" - exit 1 - ;; - esac - shift -done - -#set -e - -echo "=======Downloading golang of version: ${GOLANG_VERSION}========" - -if [[ -f go${GOLANG_VERSION}.linux-amd64.tar.gz ]]; then - rm go${GOLANG_VERSION}.linux-amd64.tar.gz -fi -curl -O https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect} - -echo "Installing golang of version: ${GOLANG_VERSION}" -if [[ -d /usr/local/go ]]; then - rm -rf /usr/local/go -fi - -tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect} - -if [[ -d $HOME/go ]]; then - rm -rf ${HOME}/go - mkdir ${HOME}/go - mkdir ${HOME}/go/bin - mkdir ${HOME}/go/src -else - mkdir ${HOME}/go - mkdir ${HOME}/go/bin - mkdir ${HOME}/go/src -fi - -echo "Adding golang env to ~/.bashrc" -GOROOT=/usr/local/go -GOPATH=${HOME}/go - -if [[ $(cat ${HOME}/.bashrc | grep GOROOT) ]]; then - echo "golang env alreay in ${HOME}/.bashrc" -else - cat <> ${HOME}/.bashrc - -export GOROOT=/usr/local/go -export GOPATH=${HOME}/go -export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin -EOF -fi - -export GOROOT=/usr/local/go -export GOPATH=${HOME}/go -export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin - -echo "Running go version command:" -go version - -echo "=======Installation of golang-${GOLANG_VERSION} complete=======" - diff --git a/utils/kube_setup/install_kubectl.sh b/utils/kube_setup/install_kubectl.sh deleted file mode 100644 index 14f97f2b..00000000 --- a/utils/kube_setup/install_kubectl.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -############################################################################## -# Copyright (c) 2018 Huawei Tech and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -OS_TYPE=$(uname -a) -OS_UBUNTU=$(echo $OS_TYPE | grep ubuntu) - -if [[ $OS_UBUNTU ]]; then - apt-get update && apt-get install -y apt-transport-https - curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - - touch /etc/apt/sources.list.d/kubernetes.list - echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list - apt-get update - apt-get install -y kubectl -else - cat < /etc/yum.repos.d/kubernetes.repo -[kubernetes] -name=Kubernetes -baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 -enabled=1 -gpgcheck=1 -repo_gpgcheck=1 -gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg -EOF - yum install -y kubectl -fi - diff --git a/utils/kube_setup/kube_env.sh b/utils/kube_setup/kube_env.sh deleted file mode 100644 index 855dea2f..00000000 --- a/utils/kube_setup/kube_env.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -############################################################################## -# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -export GOROOT=/usr/local/go -export GOPATH=${HOME}/go -export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin - -- cgit 1.2.3-korg