Skip to content

Commit e657d00

Browse files
authored
add secrets to lepton (#383)
* adding secret variable in Lepton Signed-off-by: Zoey Zhang <[email protected]> * added tests for env var Signed-off-by: Zoey Zhang <[email protected]> * linting Signed-off-by: Zoey Zhang <[email protected]> --------- Signed-off-by: Zoey Zhang <[email protected]>
1 parent 83d9a99 commit e657d00

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

nemo_run/core/execution/lepton.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from leptonai.api.v1.types.dedicated_node_group import DedicatedNodeGroup
3333
from leptonai.api.v1.types.deployment import (
3434
EnvVar,
35+
EnvValue,
3536
LeptonContainer,
3637
Mount,
3738
)
@@ -72,6 +73,7 @@ class LeptonExecutor(Executor):
7273
resource_shape: str = ""
7374
node_group: str = ""
7475
node_reservation: str = ""
76+
secret_vars: dict[str, str] = field(default_factory=dict)
7577
mounts: list[dict[str, Any]] = field(default_factory=list)
7678
lepton_job_dir: str = field(init=False, default="")
7779
image_pull_secrets: list[str] = field(
@@ -248,6 +250,8 @@ def create_lepton_job(self, name: str):
248250
client = APIClient()
249251

250252
envs = [EnvVar(name=key, value=value) for key, value in self.env_vars.items()]
253+
for key, value in self.secret_vars.items():
254+
envs.append(EnvVar(name=key, value_from=EnvValue(secret_name_ref=value)))
251255

252256
cmd = ["/bin/bash", "-c", f"bash {self.lepton_job_dir}/launch_script.sh"]
253257

test/core/execution/test_lepton.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
LeptonContainer,
2525
LeptonResourceAffinity,
2626
Mount,
27+
EnvVar,
28+
EnvValue,
2729
)
2830
from leptonai.api.v1.types.job import LeptonJob, LeptonJobUserSpec
2931

@@ -95,6 +97,21 @@ def test_init_without_node_reservation(self):
9597

9698
assert executor.node_reservation == ""
9799

100+
def test_init_with_secret_vars(self):
101+
"""Test initialization with node_reservation parameter."""
102+
executor = LeptonExecutor(
103+
resource_shape="gpu.8xh100-80gb",
104+
node_group="my-node-group",
105+
container_image="test-image",
106+
nodes=2,
107+
gpus_per_node=8,
108+
secret_vars={"WANDB_API_KEY": "WANDB_API_KEY.zozhang"},
109+
nemo_run_dir="/workspace/nemo_run",
110+
mounts=[{"path": "/workspace", "mount_path": "/workspace"}],
111+
)
112+
113+
assert executor.secret_vars == {"WANDB_API_KEY": "WANDB_API_KEY.zozhang"}
114+
98115
@patch("nemo_run.core.execution.lepton.APIClient")
99116
def test_stop_job(self, mock_APIClient):
100117
mock_instance = MagicMock()
@@ -371,6 +388,8 @@ def test_create_lepton_job(self, mock_APIClient_class):
371388
container_image="test-image",
372389
nemo_run_dir="/test/path",
373390
node_group="123456",
391+
env_vars={"TEST_ENV": "test-value"},
392+
secret_vars={"TEST_SECRET": "test-secret"},
374393
mounts=[{"path": "/test", "mount_path": "/test"}],
375394
)
376395
executor._valid_node_ids = MagicMock(return_value=valid_node_ids)
@@ -379,6 +398,11 @@ def test_create_lepton_job(self, mock_APIClient_class):
379398
executor.create_lepton_job("my-lepton-job")
380399

381400
mock_client.job.create.assert_called_once()
401+
created_job = mock_client.job.create.call_args[0][0]
402+
assert created_job.spec.envs == [
403+
EnvVar(name="TEST_ENV", value="test-value"),
404+
EnvVar(name="TEST_SECRET", value_from=EnvValue(secret_name_ref="test-secret")),
405+
]
382406

383407
@patch("nemo_run.core.execution.lepton.APIClient")
384408
def test_create_lepton_job_with_reservation_config(self, mock_APIClient_class):

0 commit comments

Comments
 (0)