From 439ddf8dee94cd07def645dff5471f840fb0416e Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 16 Jan 2025 20:34:13 +0200 Subject: [PATCH] setup: allow specifying service env variables (#973) * Allow specifying service env variables We're adding a mechanism to specify custom service env variables: /var/snap/k8s/common/args/$name-env Note that this feature is already supported by microk8s[1] and documented by k8s-dqlite[2]. [1] https://github.com/canonical/microk8s/blob/master/microk8s-resources/wrappers/run-k8s-dqlite-with-args#L38-L43 [2] https://github.com/canonical/k8s-snap/blob/4615c0377b85e6708ffa144b4667b2dd0fb252cf/k8s/lib.sh#L184-L194 * use alternative way of declaring env vars array --- k8s/lib.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/k8s/lib.sh b/k8s/lib.sh index 8421c1c11..e5443a614 100755 --- a/k8s/lib.sh +++ b/k8s/lib.sh @@ -190,7 +190,12 @@ k8s::common::execute_service() { declare -a args="($(cat "${SNAP_COMMON}/args/${service_name}"))" set -xe - exec "${SNAP}/bin/${service_name}" "${args[@]}" + if [[ -f "${SNAP_COMMON}/args/${service_name}-env" ]]; then + mapfile -t env_vars < "${SNAP_COMMON}/args/${service_name}-env" + exec env -S "${env_vars[@]}" "${SNAP}/bin/${service_name}" "${args[@]}" + else + exec "${SNAP}/bin/${service_name}" "${args[@]}" + fi } # Initialize a single-node k8sd cluster