Skip to content

Instantly share code, notes, and snippets.

@sebnyberg
Created September 14, 2020 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebnyberg/7a471d0850c495e90fa3c31c49af6f79 to your computer and use it in GitHub Desktop.
Save sebnyberg/7a471d0850c495e90fa3c31c49af6f79 to your computer and use it in GitHub Desktop.
Fluxctl release script
#!/bin/bash
#
# release.sh: wait for an image to become available before issuing a flux release
#
set -o errexit
set -o xtrace
# complain to STDERR and exit with error
die() { echo "$*" >&2; exit 2; }
set_tag() {
image=${1}
tag=$(echo $image | awk -v FS=: '{ print $2 }')
}
set_namespace() {
namespace=${1}
if [[ -z "${namespace}" ]]; then
current_context=`kubectl config current-context`
namespace=`kubectl config get-contexts ${current_context} --no-headers | awk '{ print $5 }'`
fi
}
image=
workload=
namespace=
# Assuming flux namespace is "flux" if none is set (this should be weave if you are following the default guide)
fluxns=flux
while [[ $# -gt 0 ]]; do
case "$1" in
-i|--image ) image="${2}"; shift; shift; ;;
-w|--workload ) workload="${2}"; shift; shift; ;;
-n|--namespace ) namespace="${2}"; shift; shift ;;
--fluxns ) fluxns="${2}"; shift; shift ;;
*) die "unrecognized option" ;;
esac
done
[[ -z "${image}" ]] && die "image is required, set via --image|-i"
set_tag $image
[[ -z "${tag}" ]] && die "could not find tag in image ${image}"
set_namespace $namespace
[[ -z "${namespace}" ]] && die "namespace not set and couldn't set namespace from kubeconfig, please provide via --namespace|-n"
[[ -z "${workload}" ]] && die "flux workload not set, please provide via --workload|-w"
[[ -z "${fluxns}" ]] && die "fluxns passed but no value was registered"
echo "image: ${image}"
echo "tag: ${tag}"
echo "namespace: ${namespace}"
echo "k8s-fwd-ns: ${fluxns}"
# add support for not supplying namespace to workload name
workload_without_ns=$(echo "${workload}" | sed 's/.*:\(.*\)/\1/')
workload="${namespace}:${workload_without_ns}"
echo "workload: ${workload}"
until fluxctl --k8s-fwd-ns=${fluxns} --namespace ${namespace} list-images -w ${workload} | grep -q "${tag}" ; do
sleep 2 && echo "waiting another 2s for image to appear..."
done
fluxctl --k8s-fwd-ns=${fluxns} \
release \
--namespace "${namespace}" \
--workload "${workload}" \
--update-image "${image}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment