Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions csub.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build_runai_command(
run_uid = str(args.uid) if args.uid is not None else env["LDAP_UID"]
run_gid = str(args.gid) if args.gid is not None else env["LDAP_GID"]

literal_env = {
literal_env = env | {
"HOME": f"/home/{env['LDAP_USERNAME']}",
"NB_USER": env["LDAP_USERNAME"],
"NB_UID": run_uid,
Comment thread
alexdremov marked this conversation as resolved.
Expand Down Expand Up @@ -183,11 +183,10 @@ def build_runai_command(
"--annotation", "k8s.v1.cni.cncf.io/networks=kube-system/roce",
"--extended-resource", "rdma/rdma=1"
])

add_env_flags(cmd, literal_env)
add_secret_env_flags(

add_env_flags(
Comment thread
alexdremov marked this conversation as resolved.
cmd,
env,
literal_env,
Comment thread
alexdremov marked this conversation as resolved.
secret_name,
env.get("EXTRA_SECRET_KEYS", "").split(","),
)
Expand Down
22 changes: 7 additions & 15 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,16 @@ def ensure_secret(env_path: Path, namespace: str, secret_name: str) -> None:
sys.exit(f"kubectl failed to apply the secret:\n{exc.stderr}")


def add_env_flags(cmd: List[str], values: Dict[str, str]) -> None:
def add_env_flags(cmd: List[str], values: Dict[str, str], secret_name: str, extra_secret_keys: Iterable[str]) -> None:
secret_keys = set(SECRET_KEYS).union(k.strip() for k in extra_secret_keys if k.strip())
for key, value in values.items():
if value == "":
continue
cmd.extend(["--environment", f"{key}={value}"])


def add_secret_env_flags(
cmd: List[str],
env: Dict[str, str],
secret_name: str,
extra_secret_keys: Iterable[str],
) -> None:
keys = set(SECRET_KEYS).union(k.strip() for k in extra_secret_keys if k.strip())
for key in sorted(keys):
if key not in env or env[key] == "":
continue
cmd.extend(["--environment", f"{key}=SECRET:{secret_name},{key}"])

if key in secret_keys:
cmd.extend(["--environment", f"{key}=SECRET:{secret_name},{key}"])
else:
cmd.extend(["--environment", f"{key}={value}"])
Comment thread
alexdremov marked this conversation as resolved.


__all__ = [
Expand Down