Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying service env variables #973

Merged
merged 2 commits into from
Jan 16, 2025
Merged

Conversation

petrutlucian94
Copy link
Contributor

@petrutlucian94 petrutlucian94 commented Jan 16, 2025

We're adding a mechanism to specify custom service env variables:
/var/snap/k8s/common/args/${service_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]

k8s-snap/k8s/lib.sh

Lines 184 to 194 in 4615c03

k8s::common::execute_service() {
service_name="$1"
k8s::common::setup_env
# Source arguments and substitute environment variables. Will fail if we cannot read the file.
declare -a args="($(cat "${SNAP_COMMON}/args/${service_name}"))"
set -xe
exec "${SNAP}/bin/${service_name}" "${args[@]}"
}

@petrutlucian94 petrutlucian94 requested a review from a team as a code owner January 16, 2025 14:41
@petrutlucian94 petrutlucian94 marked this pull request as draft January 16, 2025 14:41
k8s/lib.sh Outdated Show resolved Hide resolved
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
@petrutlucian94 petrutlucian94 force-pushed the lpetrut/service-env-vars branch from ca4d0cd to 2b77fa8 Compare January 16, 2025 14:52
k8s/lib.sh Outdated Show resolved Hide resolved
@petrutlucian94 petrutlucian94 marked this pull request as ready for review January 16, 2025 15:26
@eaudetcobello eaudetcobello merged commit 439ddf8 into main Jan 16, 2025
19 checks passed
@eaudetcobello eaudetcobello deleted the lpetrut/service-env-vars branch January 16, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants