From 2ffc86bc1dfcc28fb5ab1ad76de0e41e0b269d62 Mon Sep 17 00:00:00 2001 From: Elson O Rodriguez Date: Fri, 15 Apr 2016 12:45:57 -0700 Subject: [PATCH] Adding automatic OS image download for Openstack provider. This makes it so that we download the OS image automatically. Also contains other usability improvements: - kubectl context created with heat stack name - Bumped default minions to 3 --- cluster/openstack/config-default.sh | 7 +++++-- cluster/openstack/config-image.sh | 13 ++++++++----- cluster/openstack/kubernetes-heat/kubecluster.yaml | 4 ++-- cluster/openstack/util.sh | 8 ++++++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cluster/openstack/config-default.sh b/cluster/openstack/config-default.sh index d2cc00c0151..034f73ca613 100644 --- a/cluster/openstack/config-default.sh +++ b/cluster/openstack/config-default.sh @@ -25,9 +25,9 @@ KUBERNETES_KEYPAIR_NAME=${KUBERNETES_KEYPAIR_NAME:-kubernetes_keypair} # Kubernetes release tar file KUBERNETES_RELEASE_TAR=${KUBERNETES_RELEASE_TAR:-kubernetes-server-linux-amd64.tar.gz} -NUMBER_OF_MINIONS=${NUMBER_OF_MINIONS-1} +NUMBER_OF_MINIONS=${NUMBER_OF_MINIONS-3} -MAX_NUMBER_OF_MINIONS=${MAX_NUMBER_OF_MINIONS:-1} +MAX_NUMBER_OF_MINIONS=${MAX_NUMBER_OF_MINIONS:-3} MASTER_FLAVOR=${MASTER_FLAVOR:-m1.small} @@ -41,6 +41,9 @@ SWIFT_SERVER_URL=${SWIFT_SERVER_URL:-http://192.168.123.100:8080} # If 'true' then new image will be created from file config-image.sh CREATE_IMAGE=${CREATE_IMAGE:-true} # use "true" for devstack +# Flag indicates if image should be downloaded +DOWNLOAD_IMAGE=${DOWNLOAD_IMAGE:-true} + # Image id which will be used for kubernetes stack IMAGE_ID=${IMAGE_ID:-f0f394b1-5546-4b68-b2bc-8abe8a7e6b8b} diff --git a/cluster/openstack/config-image.sh b/cluster/openstack/config-image.sh index d62e80d75c1..41524bf17bc 100644 --- a/cluster/openstack/config-image.sh +++ b/cluster/openstack/config-image.sh @@ -17,16 +17,19 @@ ## Contains configuration values for new image. It is skip when CREATE_IMAGE=false # Image name which will be displayed in OpenStack -OPENSTACK_IMAGE_NAME="CentOS7" +OPENSTACK_IMAGE_NAME=${OPENSTACK_IMAGE_NAME:-CentOS7} # Downloaded image name for Openstack project -IMAGE_FILE="CentOS-7-x86_64-GenericCloud-1510.qcow2" +IMAGE_FILE=${IMAGE_FILE:-CentOS-7-x86_64-GenericCloud-1510.qcow2} # Absolute path where image file is stored. -IMAGE_PATH="/home/openstack/openstack_temp" +IMAGE_PATH=${IMAGE_PATH:-~/Downloads/openstack} + +# The URL basepath for downloading the image +IMAGE_URL_PATH=${IMAGE_URL_PATH:-http://cloud.centos.org/centos/7/images} # The disk format of the image. Acceptable formats are ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso. -IMAGE_FORMAT="qcow2" +IMAGE_FORMAT=${IMAGE_FORMAT:-qcow2} # The container format of the image. Acceptable formats are ami, ari, aki, bare, docker, and ovf. -CONTAINER_FORMAT="bare" +CONTAINER_FORMAT=${CONTAINER_FORMAT:-bare} diff --git a/cluster/openstack/kubernetes-heat/kubecluster.yaml b/cluster/openstack/kubernetes-heat/kubecluster.yaml index 47497606ed3..e57df482727 100644 --- a/cluster/openstack/kubernetes-heat/kubecluster.yaml +++ b/cluster/openstack/kubernetes-heat/kubecluster.yaml @@ -2,7 +2,7 @@ heat_template_version: 2014-10-16 description: > Kubernetes cluster with one master and one or more worker nodes - (as specified by the number_of_minions parameter, which defaults to 2). + (as specified by the number_of_minions parameter, which defaults to 3). parameters: plugin_version: @@ -44,7 +44,7 @@ parameters: number_of_minions: type: number description: how many kubernetes minions to spawn initially - default: 1 + default: 3 max_number_of_minions: type: number diff --git a/cluster/openstack/util.sh b/cluster/openstack/util.sh index dd8014fd2c1..f689720005a 100644 --- a/cluster/openstack/util.sh +++ b/cluster/openstack/util.sh @@ -144,10 +144,14 @@ function add-keypair() { # IMAGE_PATH # OPENSTACK_IMAGE_NAME function create-glance-image() { - if [ $CREATE_IMAGE = true ]; then + if [[ ${CREATE_IMAGE} == "true" ]]; then local image_status=$(nova image-show ${OPENSTACK_IMAGE_NAME} | awk '$2=="id" {print $4}') if [[ ! $image_status ]]; then + if [[ "${DOWNLOAD_IMAGE}" == "true" ]]; then + mkdir -p ${IMAGE_PATH} + curl -L ${IMAGE_URL_PATH}/${IMAGE_FILE} -o ${IMAGE_PATH}/${IMAGE_FILE} -z ${IMAGE_PATH}/${IMAGE_FILE} + fi echo "[INFO] Create image ${OPENSTACK_IMAGE_NAME}" glance image-create --name ${OPENSTACK_IMAGE_NAME} --disk-format ${IMAGE_FORMAT} \ --container-format ${CONTAINER_FORMAT} --file ${IMAGE_PATH}/${IMAGE_FILE} @@ -227,7 +231,7 @@ function run-heat-script() { function configure-kubectl() { export KUBE_MASTER_IP=$(nova show "${STACK_NAME}"-master | awk '$3=="network" {print $6}') - export CONTEXT="openstack" + export CONTEXT="openstack-${STACK_NAME}" export KUBE_BEARER_TOKEN="TokenKubelet" create-kubeconfig }