Skip to content

Commit

Permalink
vagrant: add script to get kubeconfig for vagrant cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
  • Loading branch information
sumo-drosiek committed Mar 9, 2021
1 parent 529c984 commit 242132d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions vagrant/scripts/get-kubeconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -euo pipefail

# This script replaces kubeconfig with configuration for vagrant cluster

clean_up() {
rm "${SSH_CONFIG_PATH}" || true
rm "${CONFIG_PATH}" || true
rmdir "${TEMP_DIR}" || true
popd || true
}

err_report() {
echo "Script error on line $1"
clean_up
exit 1
}
trap 'err_report $LINENO' ERR

readonly DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
readonly ROOT_DIR="${DIR}/../../"
readonly TEMP_DIR="$(mktemp -d)"
readonly SSH_CONFIG_PATH="${TEMP_DIR}/ssh-connect.conf"
readonly VAGRANT_IP="192.168.78.66"
readonly CONFIG_PATH="${TEMP_DIR}/config"
readonly KUBECONFIG_PATH=~/.kube/config

pushd "${ROOT_DIR}" > /dev/null
vagrant ssh-config > "${SSH_CONFIG_PATH}"
ssh -o StrictHostKeyChecking=no -F "${SSH_CONFIG_PATH}" default 'kubectl config view --raw' | \
sed "s/127.0.0.1/${VAGRANT_IP}/g" > "${CONFIG_PATH}"

mv "${KUBECONFIG_PATH}" "${KUBECONFIG_PATH}.bkp.$(date +%s)"
cp "${CONFIG_PATH}" "${KUBECONFIG_PATH}"

clean_up

0 comments on commit 242132d

Please sign in to comment.