Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 3 additions & 5 deletions csub.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
shlex_join,
parse_duration,
add_env_flags,
add_secret_env_flags,
)

def build_parser() -> argparse.ArgumentParser:
Expand Down Expand Up @@ -100,7 +99,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,
Expand Down Expand Up @@ -184,10 +183,9 @@ def build_runai_command(
"--extended-resource", "rdma/rdma=1"
])

add_env_flags(cmd, literal_env)
add_secret_env_flags(
add_env_flags(
cmd,
env,
literal_env,
secret_name,
env.get("EXTRA_SECRET_KEYS", "").split(","),
)
Expand Down
32 changes: 16 additions & 16 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,24 @@ 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())
ignore_keys = {
"LDAP_UID", # set automatically
"LDAP_GID", # set automatically
# csub-only control/config values not meant for the container environment
"EXTRA_SECRET_KEYS",
"GITHUB_SSH_KEY_PATH",
"GITHUB_SSH_PUBLIC_KEY_PATH",
}
for key, value in values.items():
if value == "":
if value == "" or key in ignore_keys:
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}"])


__all__ = [
Expand Down