Skip to content

Commit af75acc

Browse files
committed
Support configuration env variable replacement
We want to support environment variable replacement in the configuration similarly to how it is done in llama-stack. Example use case / motivation: The config, which since 3f7ed75 can contain a password to a database, requires users to move their entire config to a Kubernetes secret, as it now contains sensitive information, rather than a configmap. If instead we supported environment variable replacement, users could keep their config in a configmap and just set the password in a secret as k8s allows you to load secret values as environment variables in pods. Since users of lightspeed-stack are already familiar with the syntax for environment variable replacement from llama-stack, we can use the same function from llama-stack to handle this.
1 parent a59de96 commit af75acc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/configuration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import logging
44
from typing import Any, Optional
55

6+
# We want to support environment variable replacement in the configuration
7+
# similarly to how it is done in llama-stack, so we use their function directly
8+
from llama_stack.core.stack import replace_env_vars
9+
610
import yaml
711
from models.config import (
812
Configuration,
@@ -16,6 +20,7 @@
1620
DatabaseConfiguration,
1721
)
1822

23+
1924
logger = logging.getLogger(__name__)
2025

2126

@@ -38,6 +43,7 @@ def load_configuration(self, filename: str) -> None:
3843
"""Load configuration from YAML file."""
3944
with open(filename, encoding="utf-8") as fin:
4045
config_dict = yaml.safe_load(fin)
46+
config_dict = replace_env_vars(config_dict)
4147
logger.info("Loaded configuration: %s", config_dict)
4248
self.init_from_dict(config_dict)
4349

0 commit comments

Comments
 (0)