From 2b77fa87f686a4556a54ffeffa2631badce3d3d1 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 16 Jan 2025 14:36:02 +0000 Subject: [PATCH] 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 --- k8s/lib.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/k8s/lib.sh b/k8s/lib.sh index 8421c1c11..456cd95de 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 + declare -a env_vars="$(cat "${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