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 |
| 20 | BASH_ALIASES='.bash_aliases' |
| 21 | |
| 22 | DEFAULT_RKE_CONFIG='kube_config_cluster.yml' |
| 23 | DEFAULT_KUBE_DIR='.kube' |
| 24 | DEFAULT_KUBE_CONFIG='config.onap' |
| 25 | DEFAULT_KUBE_CONTEXT='onap' |
| 26 | |
| 27 | # Variables |
| 28 | RKE_CONFIG="${1:-$DEFAULT_RKE_CONFIG}" |
| 29 | KUBE_DIR="${2:-${HOME}/${DEFAULT_KUBE_DIR}}" |
| 30 | KUBE_CONFIG="${3:-$DEFAULT_KUBE_CONFIG}" |
| 31 | KUBE_CONTEXT="${4:-$DEFAULT_KUBE_CONTEXT}" |
| 32 | |
| 33 | USE_ONAP="f() { export KUBECONFIG=${KUBE_DIR}/${KUBE_CONFIG}; kubectl config use-context ${KUBE_CONTEXT}; }; f" |
| 34 | |
| 35 | |
| 36 | # Prerequistes |
| 37 | mkdir -p "$KUBE_DIR" |
| 38 | echo "alias useonap='${USE_ONAP}'" >> "${HOME}/${BASH_ALIASES}" |
| 39 | |
| 40 | # Setup |
| 41 | cp "$RKE_CONFIG" "${KUBE_DIR}/${KUBE_CONFIG}" |