aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/vagrant-minimal-onap/tools/setup_kubectl.sh
blob: bbd31a93078a4d20671201ec5cb465926fb0c8e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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
BASHRC='.bashrc'
BASH_ALIASES='.bash_aliases'
USE_ONAP_ALIAS='useonap'

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"
USE_ONAP_CONFIG="$(cat<<CONFIG

# Use ONAP context for kubectl utility (defined in ${HOME}/${BASH_ALIASES})
${USE_ONAP_ALIAS}
CONFIG
)"


# Prerequistes
mkdir -p "$KUBE_DIR"
echo "alias ${USE_ONAP_ALIAS}='${USE_ONAP}'" >> "${HOME}/${BASH_ALIASES}"

# Setup
cp "$RKE_CONFIG" "${KUBE_DIR}/${KUBE_CONFIG}"

# Post-setup
echo "$USE_ONAP_CONFIG" >> "${HOME}/${BASHRC}"