Skip to content

Commit

Permalink
Merge pull request #8 from walter-bd/main
Browse files Browse the repository at this point in the history
Add an option to include env vars in kubernetes pod manifest
  • Loading branch information
vndee authored Nov 27, 2024
2 parents 2d5100f + 933a131 commit 5ce5813
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions llm_sandbox/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
keep_template: bool = False,
verbose: bool = False,
kube_namespace: Optional[str] = "default",
env_vars: Optional[dict] = None
):
"""
Create a new sandbox session
Expand Down Expand Up @@ -60,6 +61,7 @@ def __init__(
self.pod_name = f"sandbox-{lang.lower()}-{uuid.uuid4().hex}"
self.keep_template = keep_template
self.container = None
self.env_vars = env_vars

def open(self):
self._create_kubernetes_pod()
Expand All @@ -79,6 +81,11 @@ def _create_kubernetes_pod(self):
]
},
}
# Add environment variables if provided
if self.env_vars:
pod_manifest["spec"]["containers"][0]["env"] = [
{"name": key, "value": value} for key, value in self.env_vars.items()
]
self.client.create_namespaced_pod(
namespace=self.kube_namespace, body=pod_manifest
)
Expand Down

0 comments on commit 5ce5813

Please sign in to comment.