Allow xxx-bundle-conf to override conf of bundle
This commit is contained in:
parent
b1cdfdb85e
commit
a798cf53c7
28
ctctl
28
ctctl
|
@ -530,7 +530,7 @@ ctctl_render_templates(){
|
|||
if [ -e "bundles.yml" ]; then
|
||||
mkdir -p bundles
|
||||
|
||||
CONFIG=$(mktemp -t tmp.XXXXXXXXX.yml)
|
||||
export CTCTL_BUNDLE_CONFIG=$(mktemp -t tmp.XXXXXXXXX.yml)
|
||||
# First, cleanup any previously rendered files
|
||||
rm -rf output ./*.nomad ./*.nomad.hcl
|
||||
|
||||
|
@ -587,6 +587,9 @@ ctctl_render_templates(){
|
|||
|
||||
# Build a list of configuration file to merge
|
||||
# Files are in order of precedence (firsts win)
|
||||
# Note : if we have a bundle named foobar, and another named anything-foobar-conf
|
||||
# Then consider anything-foobar-conf just provides config to override the foobar one. So put those first in the list
|
||||
# so they will take precedence
|
||||
I=0
|
||||
local VAR_FILES=""
|
||||
for FILE in ${NOMAD_NAMESPACE}.yml \
|
||||
|
@ -597,6 +600,8 @@ ctctl_render_templates(){
|
|||
../${NOMAD_NAMESPACE}.yaml \
|
||||
../variables.yml \
|
||||
../variables.yaml \
|
||||
bundles/*-${NAME}-conf/variables.yml \
|
||||
bundles/*-${NAME}-conf/variables.yaml \
|
||||
bundles/${NAME}/variables.yml \
|
||||
bundles/${NAME}/variables.yaml \
|
||||
bundles/*/variables.yml \
|
||||
|
@ -611,13 +616,13 @@ ctctl_render_templates(){
|
|||
I=$((I+1))
|
||||
fi
|
||||
done
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context "${VAR_FILES[@]}" -i "[[ . | toYAML ]]" > ${CONFIG}
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context "${VAR_FILES[@]}" -i "[[ . | toYAML ]]" -o ${CTCTL_BUNDLE_CONFIG}
|
||||
# And render it again so we can replace any templated values in the config itself
|
||||
# Render it as many time as needed until no [[ ]] are found
|
||||
while grep -q '\[\[' ${CONFIG}; do
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
|
||||
while grep -q '\[\[' ${CTCTL_BUNDLE_CONFIG}; do
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CTCTL_BUNDLE_CONFIG} -o ${CTCTL_BUNDLE_CONFIG}
|
||||
done
|
||||
GOMPLATE_COMMON_ARGS+=(--context .=file://${CONFIG})
|
||||
GOMPLATE_COMMON_ARGS+=(--context .=file://${CTCTL_BUNDLE_CONFIG})
|
||||
|
||||
# This is used for two things
|
||||
# - Add the consul.suffix to every files (except job files). This allows ctctl to simply infer the policy name from the file name
|
||||
|
@ -647,11 +652,11 @@ ctctl_render_templates(){
|
|||
echo "Formating job files"
|
||||
find ./ -maxdepth 1 -type f \( -name \*nomad.hcl -o -name \*.nomad \) -exec nomad fmt {} \;
|
||||
|
||||
# Run prep.d scripts
|
||||
# Run render.d scripts
|
||||
ctctl_handle_render_scripts
|
||||
|
||||
# And now delete the merged config
|
||||
rm -f ${CONFIG}
|
||||
rm -f ${CTCTL_BUNDLE_CONFIG}
|
||||
|
||||
if [ -n "${CTCTL_RENDER_EXAMPLE}" -a "${CTCTL_RENDER_EXAMPLE}" = "true" ]; then
|
||||
echo "Rendering example job with bundle variables only"
|
||||
|
@ -672,10 +677,10 @@ ctctl_render_templates(){
|
|||
I=$((I+1))
|
||||
fi
|
||||
done
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context "${VAR_FILES[@]}" -i "[[ . | toYAML ]]" > ${CONFIG}
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context "${VAR_FILES[@]}" -i "[[ . | toYAML ]]" -o ${CTCTL_BUNDLE_CONFIG}
|
||||
# And render it again so we can replace any templated values in the config itself
|
||||
while grep -q '\[\[' ${CONFIG}; do
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
|
||||
while grep -q '\[\[' ${CTCTL_BUNDLE_CONFIG}; do
|
||||
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CTCTL_BUNDLE_CONFIG} -o ${CTCTL_BUNDLE_CONFIG}
|
||||
done
|
||||
|
||||
# First, cleanup any previously rendered files
|
||||
|
@ -699,8 +704,9 @@ ctctl_render_templates(){
|
|||
find ./bundles/${NAME}/example -maxdepth 1 -type f \( -name \*nomad.hcl -o -name \*.nomad \) -exec nomad fmt {} \;
|
||||
fi
|
||||
|
||||
rm -f ${CONFIG}
|
||||
done
|
||||
rm -f ${CTCTL_BUNDLE_CONFIG}
|
||||
unset CTCTL_BUNDLE_CONFIG
|
||||
else
|
||||
# backward compatible, levant based rendering
|
||||
MERGED_CONF=$(mktemp tmp.XXXXXXXX.yml)
|
||||
|
|
Loading…
Reference in New Issue