blob: bbd31a93078a4d20671201ec5cb465926fb0c8e0 [file] [log] [blame]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +01001#!/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
20BASHRC='.bashrc'
21BASH_ALIASES='.bash_aliases'
22USE_ONAP_ALIAS='useonap'
23
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"
36USE_ONAP_CONFIG="$(cat<<CONFIG
37
38# Use ONAP context for kubectl utility (defined in ${HOME}/${BASH_ALIASES})
39${USE_ONAP_ALIAS}
40CONFIG
41)"
42
43
44# Prerequistes
45mkdir -p "$KUBE_DIR"
46echo "alias ${USE_ONAP_ALIAS}='${USE_ONAP}'" >> "${HOME}/${BASH_ALIASES}"
47
48# Setup
49cp "$RKE_CONFIG" "${KUBE_DIR}/${KUBE_CONFIG}"
50
51# Post-setup
52echo "$USE_ONAP_CONFIG" >> "${HOME}/${BASHRC}"