k8s: Add kubectl provisioners (downloading and setting up) 90/92290/2
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Mon, 29 Jul 2019 11:17:51 +0000 (13:17 +0200)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 31 Jul 2019 13:47:41 +0000 (15:47 +0200)
Setting up kubectl depends on presence of K8s cluster post-deployment
artifacts, hence it's disabled by default. Relevant information added to
post-up message.

This patch also removes unneeded curly braces from
"tools/dublin/get_rke.sh" script.

Issue-ID: SECCOM-235
Change-Id: I917ebbda588639f0941e16c65759430a7a1e64ff
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
test/security/k8s/tools/dublin/get_kubectl.sh [new file with mode: 0755]
test/security/k8s/tools/dublin/get_rke.sh
test/security/k8s/tools/dublin/setup_kubectl.sh [new file with mode: 0755]
test/security/k8s/vagrant/dublin/Vagrantfile

diff --git a/test/security/k8s/tools/dublin/get_kubectl.sh b/test/security/k8s/tools/dublin/get_kubectl.sh
new file mode 100755 (executable)
index 0000000..752c286
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+#
+# @file        test/security/k8s/tools/dublin/get_kubectl.sh
+# @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
+# @brief       Utility for obtaining kubectl tool
+#
+
+# Dependencies:
+#     wget
+#     coreutils
+#
+# Privileges:
+# Script expects to be run with administrative privileges for accessing /usr/local/bin
+#
+# Usage:
+# # ./get_kubectl.sh [VERSION [ARCH [SYSTEM]]]
+#
+
+# Constants
+BINARY='kubectl'
+INSTALL_DIR='/usr/local/bin/'
+
+DEFAULT_VERSION='v1.13.5'
+DEFAULT_ARCH='amd64'
+DEFAULT_SYSTEM='linux'
+
+# Variables
+VERSION="${1:-$DEFAULT_VERSION}"
+ARCH="${2:-$DEFAULT_ARCH}"
+SYSTEM="${3:-$DEFAULT_SYSTEM}"
+
+URL="https://storage.googleapis.com/kubernetes-release/release/${VERSION}/bin/${SYSTEM}/${ARCH}/${BINARY}"
+
+
+# Prerequistes
+wget "$URL"
+chmod +x "$BINARY"
+
+# Installation
+mv "$BINARY" "$INSTALL_DIR"
index 63ef8c7..01dd20a 100755 (executable)
@@ -33,7 +33,7 @@ URL="https://github.com/rancher/rke/releases/download/${VERSION}/${BINARY}"
 
 # Prerequistes
 wget "$URL"
-chmod +x "${BINARY}"
+chmod +x "$BINARY"
 
 # Installation
-mv "${BINARY}" "/usr/local/bin/${BINARY%%_*}" # this also renames binary to "rke"
+mv "$BINARY" "/usr/local/bin/${BINARY%%_*}" # this also renames binary to "rke"
diff --git a/test/security/k8s/tools/dublin/setup_kubectl.sh b/test/security/k8s/tools/dublin/setup_kubectl.sh
new file mode 100755 (executable)
index 0000000..a50c236
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+#
+# @file        test/security/k8s/tools/dublin/setup_kubectl.sh
+# @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
+# @brief       Utility for setting up kubectl tool for Dublin cluster
+#
+
+# Dependencies:
+#     coreutils
+#
+# Privileges:
+# Script expects to be run with administrative privileges for accessing /usr/local/bin
+#
+# Usage:
+# # ./setup_kubectl.sh [RKE_CONFIG [KUBE_DIR [KUBE_CONFIG [KUBE_CONTEXT]]]]
+#
+
+# Constants
+BASH_ALIASES='.bash_aliases'
+
+DEFAULT_RKE_CONFIG='kube_config_cluster.yml'
+DEFAULT_KUBE_DIR='.kube'
+DEFAULT_KUBE_CONFIG='config.onap'
+DEFAULT_KUBE_CONTEXT='onap'
+
+# Variables
+RKE_CONFIG="${1:-$DEFAULT_RKE_CONFIG}"
+KUBE_DIR="${2:-${HOME}/${DEFAULT_KUBE_DIR}}"
+KUBE_CONFIG="${3:-$DEFAULT_KUBE_CONFIG}"
+KUBE_CONTEXT="${4:-$DEFAULT_KUBE_CONTEXT}"
+
+USE_ONAP="f() { export KUBECONFIG=${KUBE_DIR}/${KUBE_CONFIG}; kubectl config use-context ${KUBE_CONTEXT}; }; f"
+
+
+# Prerequistes
+mkdir -p "$KUBE_DIR"
+echo "alias useonap='${USE_ONAP}'" >> "${HOME}/${BASH_ALIASES}"
+
+# Setup
+cp "$RKE_CONFIG" "${KUBE_DIR}/${KUBE_CONFIG}"
index 1489037..ce442eb 100644 (file)
@@ -21,7 +21,7 @@ cluster = [
 
 all = cluster.dup << operation
 
-operation_post_msg = "Run: \"vagrant provision #{operation[:name]} --provision-with=rke_up\" to complete cluster creation"
+operation_post_msg = "Run: \"vagrant provision #{operation[:name]} --provision-with=rke_up,setup_kubectl\" to complete cluster creation"
 
 $replace_dns = <<-SCRIPT
   HOST_IP="$1"
@@ -150,6 +150,12 @@ Vagrant.configure('2') do |config|
           trigger.warn = "Removing cluster"
           trigger.run_remote = {privileged: false, inline: $rke_down}
         end
+
+        config.vm.provision "get_kubectl", type: :shell, path: "../../tools/dublin/get_kubectl.sh"
+        config.vm.provision "setup_kubectl", type: :shell, run: "never" do |s|
+          s.privileged = false
+          s.path = "../../tools/dublin/setup_kubectl.sh"
+        end
       end
     end
   end