-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 2.0 migration script wrapper - upgrade-2.0 to Docker image (#93)
- Loading branch information
1 parent
c28d009
commit 2c6045a
Showing
3 changed files
with
69 additions
and
2 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
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
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,63 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
readonly SCRIPT_PATH="/usr/local/bin/upgrade-2.0.0.sh" | ||
|
||
function print_help() { | ||
echo "2.0 k8s migration script." | ||
echo "This script outputs migrated values file on stdout (and saves it in new_values.yaml in current working directory inside the container)." | ||
echo "Logs produced by the migration script are available on stderr." | ||
echo | ||
echo "Usage:" | ||
echo " upgrade-2.0 <VALUES_FILE.yaml>" | ||
} | ||
|
||
function err() { | ||
echo "${1}" >&2 | ||
} | ||
|
||
if [[ ${#} -ge 1 && "${1}" == "--help" ]]; then | ||
print_help | ||
exit 0 | ||
fi | ||
|
||
FILE="" | ||
if [[ ${#} -eq 0 ]]; then | ||
readonly STDIN_WAIT_S="${STDIN_WAIT_S:-10}" | ||
# Take data from stdin if available and put into temporary file | ||
readonly TMPFILE="$(mktemp /tmp/values.yaml.XXXXXX)" | ||
# Kubectl can take some time before stdin is available for reading | ||
# thats why we check if just before it's required | ||
if read -t "${STDIN_WAIT_S}" REPLY; then | ||
# Save first line read from stdin | ||
echo "${REPLY}" > "${TMPFILE}" | ||
# Save rest of the stdin | ||
cat <&0 >> "${TMPFILE}" | ||
fi | ||
|
||
if [[ ! -s "${TMPFILE}" ]]; then | ||
err "Values file was not provided on stdin (or it was provided empty). Aborting." | ||
exit 1 | ||
fi | ||
|
||
FILE="${TMPFILE}" | ||
else | ||
FILE="${1}" | ||
if [[ ! -f "${FILE}" ]]; then | ||
err "Provided file \"${FILE}\" doesn't exist" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# In case migration script fails we want to handle the error ourselves | ||
set +e | ||
"${SCRIPT_PATH}" "${FILE}" >&2 | ||
readonly EXIT_STATUS=$? | ||
if [[ ${EXIT_STATUS} -ne 0 ]]; then | ||
err "Upgrade script failed" | ||
exit 1 | ||
fi | ||
|
||
cat new_values.yaml |