aboutsummaryrefslogtreecommitdiffstats
path: root/test/security
diff options
context:
space:
mode:
authorPawel Wieczorek <p.wieczorek2@samsung.com>2019-07-29 13:17:51 +0200
committerPawel Wieczorek <p.wieczorek2@samsung.com>2019-07-31 15:47:41 +0200
commit2d13ea81519bacdd7f17ce91ec06bc7ac26a6cac (patch)
treeda01087d5e59d6dc6d2816fc52eae7f22bbb3404 /test/security
parent595116580615502e0a0e70a9e1b906c6c41477af (diff)
k8s: Add kubectl provisioners (downloading and setting up)
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>
Diffstat (limited to 'test/security')
-rwxr-xr-xtest/security/k8s/tools/dublin/get_kubectl.sh41
-rwxr-xr-xtest/security/k8s/tools/dublin/get_rke.sh4
-rwxr-xr-xtest/security/k8s/tools/dublin/setup_kubectl.sh41
-rw-r--r--test/security/k8s/vagrant/dublin/Vagrantfile8
4 files changed, 91 insertions, 3 deletions
diff --git a/test/security/k8s/tools/dublin/get_kubectl.sh b/test/security/k8s/tools/dublin/get_kubectl.sh
new file mode 100755
index 000000000..752c286c2
--- /dev/null
+++ b/test/security/k8s/tools/dublin/get_kubectl.sh
@@ -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"
diff --git a/test/security/k8s/tools/dublin/get_rke.sh b/test/security/k8s/tools/dublin/get_rke.sh
index 63ef8c77e..01dd20a96 100755
--- a/test/security/k8s/tools/dublin/get_rke.sh
+++ b/test/security/k8s/tools/dublin/get_rke.sh
@@ -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
index 000000000..a50c23656
--- /dev/null
+++ b/test/security/k8s/tools/dublin/setup_kubectl.sh
@@ -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}"
diff --git a/test/security/k8s/vagrant/dublin/Vagrantfile b/test/security/k8s/vagrant/dublin/Vagrantfile
index 148903773..ce442eb98 100644
--- a/test/security/k8s/vagrant/dublin/Vagrantfile
+++ b/test/security/k8s/vagrant/dublin/Vagrantfile
@@ -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