-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vagrant: add script to get kubeconfig for vagrant cluster
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
- Loading branch information
1 parent
529c984
commit 242132d
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |