Last active
February 6, 2019 17:01
-
-
Save stefanotorresi/f3e6c2cb220dcf38237893ef9213af2e to your computer and use it in GitHub Desktop.
bash script to shorten helm release names
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
RELEASE_NAME=$1 | |
MAX_LENGTH=${2-53} | |
HASH_SIZE=${3-8} | |
if [[ $MAX_LENGTH -le $(($HASH_SIZE+1)) ]]; then | |
echo "max length must be bigger than hash size + 1" | |
exit 1 | |
fi | |
if [[ ${#RELEASE_NAME} -le $MAX_LENGTH ]]; then | |
echo -n $RELEASE_NAME | |
exit | |
fi | |
TRUNCATION_SIZE=$(($MAX_LENGTH-$HASH_SIZE-1)) | |
TRUNCATION=${RELEASE_NAME:0:$TRUNCATION_SIZE} | |
RELEASE_NAME_HASH=$(echo -n $RELEASE_NAME | sha1sum | awk '{print $1}') | |
echo -n $TRUNCATION-${RELEASE_NAME_HASH:0:$HASH_SIZE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment