Skip to content

Commit

Permalink
support envFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
drmorr0 committed Jun 24, 2024
1 parent 7b9ca82 commit 0e9219b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fireconfig/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions fireconfig/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

0 comments on commit 0e9219b

Please sign in to comment.