Pawel Wieczorek | 2d13ea8 | 2019-07-29 13:17:51 +0200 | [diff] [blame] | 1 | #!/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 Wieczorek | e466145 | 2019-07-31 15:38:15 +0200 | [diff] [blame] | 20 | BASHRC='.bashrc' |
Pawel Wieczorek | 2d13ea8 | 2019-07-29 13:17:51 +0200 | [diff] [blame] | 21 | BASH_ALIASES='.bash_aliases' |
Pawel Wieczorek | e466145 | 2019-07-31 15:38:15 +0200 | [diff] [blame] | 22 | USE_ONAP_ALIAS='useonap' |
Pawel Wieczorek | 2d13ea8 | 2019-07-29 13:17:51 +0200 | [diff] [blame] | 23 | |
| 24 | DEFAULT_RKE_CONFIG='kube_config_cluster.yml' |
| 25 | DEFAULT_KUBE_DIR='.kube' |
| 26 | DEFAULT_KUBE_CONFIG='config.onap' |
| 27 | DEFAULT_KUBE_CONTEXT='onap' |
| 28 | |
| 29 | # Variables |
| 30 | RKE_CONFIG="${1:-$DEFAULT_RKE_CONFIG}" |
| 31 | KUBE_DIR="${2:-${HOME}/${DEFAULT_KUBE_DIR}}" |
| 32 | KUBE_CONFIG="${3:-$DEFAULT_KUBE_CONFIG}" |
| 33 | KUBE_CONTEXT="${4:-$DEFAULT_KUBE_CONTEXT}" |
| 34 | |
| 35 | USE_ONAP="f() { export KUBECONFIG=${KUBE_DIR}/${KUBE_CONFIG}; kubectl config use-context ${KUBE_CONTEXT}; }; f" |
Pawel Wieczorek | e466145 | 2019-07-31 15:38:15 +0200 | [diff] [blame] | 36 | USE_ONAP_CONFIG="$(cat<<CONFIG |
| 37 | |
| 38 | # Use ONAP context for kubectl utility (defined in ${HOME}/${BASH_ALIASES}) |
| 39 | ${USE_ONAP_ALIAS} |
| 40 | CONFIG |
| 41 | )" |
Pawel Wieczorek | 2d13ea8 | 2019-07-29 13:17:51 +0200 | [diff] [blame] | 42 | |
| 43 | |
| 44 | # Prerequistes |
| 45 | mkdir -p "$KUBE_DIR" |
Pawel Wieczorek | e466145 | 2019-07-31 15:38:15 +0200 | [diff] [blame] | 46 | echo "alias ${USE_ONAP_ALIAS}='${USE_ONAP}'" >> "${HOME}/${BASH_ALIASES}" |
Pawel Wieczorek | 2d13ea8 | 2019-07-29 13:17:51 +0200 | [diff] [blame] | 47 | |
| 48 | # Setup |
| 49 | cp "$RKE_CONFIG" "${KUBE_DIR}/${KUBE_CONFIG}" |
Pawel Wieczorek | e466145 | 2019-07-31 15:38:15 +0200 | [diff] [blame] | 50 | |
| 51 | # Post-setup |
| 52 | echo "$USE_ONAP_CONFIG" >> "${HOME}/${BASHRC}" |