diff --git a/fireconfig/container.py b/fireconfig/container.py index 8e4b4b7..3c6db6b 100644 --- a/fireconfig/container.py +++ b/fireconfig/container.py @@ -66,9 +66,10 @@ def build(self) -> k8s.Container: optional["args"] = self._args if self._env: - optional["env"] = self._env.build(self._env_names) - else: - optional["env"] = [] + if env := self._env.build(self._env_names): + optional["env"] = env + if env_from := self._env.build_from(): + optional["env_from"] = env_from if self._ports: optional["ports"] = [k8s.ContainerPort(container_port=p) for p in self._ports] if self._resources is not None: diff --git a/fireconfig/env.py b/fireconfig/env.py index 6015b73..99b86b3 100644 --- a/fireconfig/env.py +++ b/fireconfig/env.py @@ -8,6 +8,7 @@ def __init__(self, env: T.Mapping[str, str] = dict()): self._env: T.MutableMapping[str, T.Tuple[str, T.Union[str, T.Mapping]]] = { k: ("value", v) for (k, v) in env.items() } + self._env_from: T.List[T.Mapping] = [] def with_field_ref(self, name: str, field: DownwardAPIField, key: T.Optional[str] = None) -> T.Self: field_str = str(field) @@ -17,6 +18,10 @@ def with_field_ref(self, name: str, field: DownwardAPIField, key: T.Optional[str self._env[name] = ("valueFrom", {"fieldRef": {"fieldPath": field_str}}) return self + def with_secrets_from(self, secret_name: str) -> T.Self: + self._env_from.append({"secretRef": {"name": secret_name}}) + return self + def with_secret(self, name: str, secret_name: str, secret_key_name: str) -> T.Self: self._env[name] = ("valueFrom", {"secretKeyRef": {"name": secret_name, "key": secret_key_name}}) return self @@ -26,3 +31,6 @@ def build(self, names: T.Optional[T.Union[T.Sequence[str], T.KeysView[str]]] = N names = self._env.keys() return [{"name": name, self._env[name][0]: self._env[name][1]} for name in names] + + def build_from(self) -> T.Sequence[T.Mapping]: + return self._env_from