Skip to content

Instantly share code, notes, and snippets.

@whazor
Created June 16, 2022 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whazor/3fd9f45c07dc1efc9667ba935ff0217d to your computer and use it in GitHub Desktop.
Save whazor/3fd9f45c07dc1efc9667ba935ff0217d to your computer and use it in GitHub Desktop.
Manual flux helm upgrade
#!/bin/bash
if [ ! -f $1 ]; then
echo "Error: $1 is not existing file path."
exit 1
fi
lines=$(cat cluster/config/cluster-settings.yaml | yq '.data | ... comments=""';\
sops --decrypt cluster/config/cluster-secrets.enc.yaml | yq '.stringData | ... comments=""')
subst=""
while read -r line; do
name=${line%: *}
value=${line#*: }
export $name=$value
subst+="\${$name} "
done <<< "$lines"
NAMESPACE=$(cat $1 | yq '.metadata.namespace')
NAME=$(cat $1 | yq '.metadata.name')
REPO_NAME=$(cat $1 | yq '.spec.chart.spec.sourceRef.name')
CHART=$(cat $1 | yq '.spec.chart.spec.chart')
VERSION=$(cat $1 | yq '.spec.chart.spec.version')
EXISTS=$(helm repo list -o yaml | yq '.[] | select(.name == "'$REPO_NAME'") | .name')
if [ -z "$EXISTS" ]; then
URL=$(cat $1 | grep '# renovate: registryUrl=' | sed 's/ *# renovate: registryUrl=//')
if [ -z "$URL" ]; then
URL="https://..."
fi
echo "add repo via: "
echo " helm repo add $REPO_NAME $URL"
echo "url above might not be correct"
exit 1
fi
TMPFILE=$(mktemp)
cat $1 | yq '.spec.values' | envsubst "$subst" > "$TMPFILE.yaml"
helm upgrade $NAME $REPO_NAME/$CHART --version $VERSION --namespace $NAMESPACE --values $TMPFILE.yaml
rm "$TMPFILE.yaml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment