Skip to content

Instantly share code, notes, and snippets.

@weyert
Last active October 28, 2021 19:19
Show Gist options
  • Save weyert/431fd83862467056c6ff790736e8284c to your computer and use it in GitHub Desktop.
Save weyert/431fd83862467056c6ff790736e8284c to your computer and use it in GitHub Desktop.
Generate config map for Sloth SLO definitions using Customise
sloth_version="0.8.0"
# get the name of the operating system
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
platform='freebsd'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='darwin'
elif [[ "$unamestr" == 'WindowsNT' ]]; then
platform='darwin'
fi
# get the cpu type
arch='unknown'
unamepstr=`uname -m`
if [[ "$unamepstr" == 'armv7l' ]]; then
arch='arm64'
elif [[ "$unamepstr" == 'x86_64' ]]; then
arch='amd64'
elif [[ "$unamepstr" == 'aarch64' ]]; then
arch='amd64'
fi
download_url="https://github.com/slok/sloth/releases/download/v${sloth_version}/sloth-${platform}-${arch}"
# Download the bundled Sloth from Github
if [[ -f ./sloth ]]; then
echo "Sloth binary found."
else
echo "Fetching Sloth from ${download_url}..."
wget -O sloth $download_url
chmod +x ./sloth
fi;
{
printf "generatorOptions:\n"
printf " disableNameSuffixHash: true\n\n"
printf "commonAnnotations:\n"
printf " argocd.argoproj.io/sync-options: Replace=true\n"
printf "configMapgenerator:\n"
printf " - name: thanos-ruler-slos-config-provider\n"
printf " files:\n"
for entry in "./service-level-objectives"/*.yml
do
SLO_FILENAME=`basename $entry`
SLO_FILE_PATH="./service-level-objectives/_generated/$SLO_FILENAME"
./sloth generate -i $entry -o ./service-level-objectives/_generated/$SLO_FILENAME --no-log
SLO_OUTPUT=`./sloth generate -i $entry --no-log`
echo " - ./_generated/$SLO_FILENAME"
done
} >service-level-objectives/kustomization.yaml
kustomize build service-level-objectives --load-restrictor LoadRestrictionsNone > slo-cm.yaml
rm service-level-objectives/kustomization.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment