Skip to content

Commit

Permalink
Some environment variables are now optional in nextmn-srv6
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Feb 1, 2024
1 parent 482ab35 commit 90f1e43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
39 changes: 20 additions & 19 deletions srv6/template-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ if [ -z "$HOOKS" ]; then
echo "Missing mandatory environment variable (HOOKS)." > /dev/stderr
exit 1
fi
if [ -z "$HEADENDS" ]; then
echo "Missing mandatory environment variable (HEADENDS)." > /dev/stderr
exit 1
fi
if [ -z "$ENDPOINTS" ]; then
echo "Missing mandatory environment variable (ENDPOINTS)." > /dev/stderr
exit 1
Expand All @@ -23,14 +19,6 @@ if [ -z "$LOCATOR" ]; then
echo "Missing mandatory environment variable (LOCATOR)." > /dev/stderr
exit 1
fi
if [ -z "$LINUX_HEADEND_SET_SOURCE_ADDRESS" ]; then
echo "Missing mandatory environment variable (LINUX_HEADEND_SET_SOURCE_ADDRESS)." > /dev/stderr
exit 1
fi
if [ -z "$IPV4_HEADEND_PREFIX" ]; then
echo "Missing mandatory environment variable (IPV4_HEADEND_PREFIX)." > /dev/stderr
exit 1
fi

IFS=$'\n'
HOOKS_SUB=""
Expand All @@ -39,25 +27,38 @@ for HOOKS in ${HOOKS}; do
HOOKS_SUB="${HOOKS_SUB}\n ${HOOK}"
fi
done
for HEADENDS in ${HEADENDS}; do
if [ -n "${HEADEND}" ]; then
HEADENDS_SUB="${HEADENDS_SUB}\n ${HEADEND}"
fi
done

if [ -n "${HEADENDS}" ]; then
HEADENDS_SUB="headends: "
for HEADENDS in ${HEADENDS}; do
if [ -n "${HEADEND}" ]; then
HEADENDS_SUB="${HEADENDS_SUB}\n ${HEADEND}"
fi
done
fi

ENDPOINTS_SUB=""
for ENDPOINTS in ${ENDPOINTS}; do
if [ -n "${ENDPOINT}" ]; then
ENDPOINTS_SUB="${ENDPOINTS_SUB}\n ${ENDPOINT}"
fi
done

if [ -n "$LINUX_HEADEND_SET_SOURCE_ADDRESS" ]; then
LINUX_HEADEND_SET_SOURCE_ADDRESS_SUB="linux-headend-set-source-address: ${LINUX_HEADEND_SET_SOURCE_ADDRESS}"
fi
if [ -n "$IPV4_HEADEND_PREFIX" ]; then
IPV4_HEADEND_PREFIX_SUB="ipv4-headend-prefix: ${IPV4_HEADEND_PREFIX}"
fi

awk \
-v DEBUG="${DEBUG:-false}" \
-v HOOKS="${HOOKS_SUB}" \
-v HEADENDS="${HEADENDS_SUB}" \
-v ENDPOINTS="${ENDPOINTS_SUB}" \
-v LOCATOR="${LOCATOR}" \
-v IPV4_HEADEND_PREFIX="${IPV4_HEADEND_PREFIX}" \
-v LINUX_HEADEND_SET_SOURCE_ADDRESS="${LINUX_HEADEND_SET_SOURCE_ADDRESS}" \
-v IPV4_HEADEND_PREFIX="${IPV4_HEADEND_PREFIX_SUB}" \
-v LINUX_HEADEND_SET_SOURCE_ADDRESS="${LINUX_HEADEND_SET_SOURCE_ADDRESS_SUB}" \
'{
sub(/%DEBUG/, DEBUG);
sub(/%HOOKS/, HOOKS);
Expand Down
6 changes: 3 additions & 3 deletions srv6/template-srv6.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
debug: %DEBUG
hooks: %HOOKS

linux-headend-set-source-address: %LINUX_HEADEND_SET_SOURCE_ADDRESS
ipv4-headend-prefix: %IPV4_HEADEND_PREFIX
headends: %HEADENDS
%LINUX_HEADEND_SET_SOURCE_ADDRESS
%IPV4_HEADEND_PREFIX
%HEADENDS

locator: %LOCATOR
endpoints: %ENDPOINTS

0 comments on commit 90f1e43

Please sign in to comment.