blob: bbd31a93078a4d20671201ec5cb465926fb0c8e0 [file] [log] [blame]
Pawel Wieczorek2d13ea82019-07-29 13:17:51 +02001#!/usr/bin/env bash
2
3#
4# @file test/security/k8s/tools/dublin/setup_kubectl.sh
5# @author Pawel Wieczorek <p.wieczorek2@samsung.com>
6# @brief Utility for setting up kubectl tool for Dublin cluster
7#
8
9# Dependencies:
10# coreutils
11#
12# Privileges:
13# Script expects to be run with administrative privileges for accessing /usr/local/bin
14#
15# Usage:
16# # ./setup_kubectl.sh [RKE_CONFIG [KUBE_DIR [KUBE_CONFIG [KUBE_CONTEXT]]]]
17#
18
19# Constants
Pawel Wieczoreke4661452019-07-31 15:38:15 +020020BASHRC='.bashrc'
Pawel Wieczorek2d13ea82019-07-29 13:17:51 +020021BASH_ALIASES='.bash_aliases'
Pawel Wieczoreke4661452019-07-31 15:38:15 +020022USE_ONAP_ALIAS='useonap'
Pawel Wieczorek2d13ea82019-07-29 13:17:51 +020023
24DEFAULT_RKE_CONFIG='kube_config_cluster.yml'
25DEFAULT_KUBE_DIR='.kube'
26DEFAULT_KUBE_CONFIG='config.onap'
27DEFAULT_KUBE_CONTEXT='onap'
28
29# Variables
30RKE_CONFIG="${1:-$DEFAULT_RKE_CONFIG}"
31KUBE_DIR="${2:-${HOME}/${DEFAULT_KUBE_DIR}}"
32KUBE_CONFIG="${3:-$DEFAULT_KUBE_CONFIG}"
33KUBE_CONTEXT="${4:-$DEFAULT_KUBE_CONTEXT}"
34
35USE_ONAP="f() { export KUBECONFIG=${KUBE_DIR}/${KUBE_CONFIG}; kubectl config use-context ${KUBE_CONTEXT}; }; f"
Pawel Wieczoreke4661452019-07-31 15:38:15 +020036USE_ONAP_CONFIG="$(cat<<CONFIG
37
38# Use ONAP context for kubectl utility (defined in ${HOME}/${BASH_ALIASES})
39${USE_ONAP_ALIAS}
40CONFIG
41)"
Pawel Wieczorek2d13ea82019-07-29 13:17:51 +020042
43
44# Prerequistes
45mkdir -p "$KUBE_DIR"
Pawel Wieczoreke4661452019-07-31 15:38:15 +020046echo "alias ${USE_ONAP_ALIAS}='${USE_ONAP}'" >> "${HOME}/${BASH_ALIASES}"
Pawel Wieczorek2d13ea82019-07-29 13:17:51 +020047
48# Setup
49cp "$RKE_CONFIG" "${KUBE_DIR}/${KUBE_CONFIG}"
Pawel Wieczoreke4661452019-07-31 15:38:15 +020050
51# Post-setup
52echo "$USE_ONAP_CONFIG" >> "${HOME}/${BASHRC}"