Skip to content

Commit

Permalink
Added options to set annotations and a service account in the Kuberne…
Browse files Browse the repository at this point in the history
…tes worker pod configuration (#3476)

Added options for pod annotations and a service account to be used by the pod, which are passed through to the Kubernetes client. These options are needed when using the provider on Google Kubernetes Engine for pods to mount Google Cloud Storage persistent volumes.
  • Loading branch information
shishichen authored Jun 10, 2024
1 parent bc086f7 commit 2200f62
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions parsl/providers/kubernetes/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class KubernetesProvider(ExecutionProvider, RepresentationMixin):
persistent_volumes: list[(str, str)]
List of tuples describing persistent volumes to be mounted in the pod.
The tuples consist of (PVC Name, Mount Directory).
service_account_name: str
Name of the service account to run the pod as.
annotations: Dict[str, str]
Annotations to set on the pod.
"""
@typeguard.typechecked
def __init__(self,
Expand All @@ -103,7 +107,9 @@ def __init__(self,
group_id: Optional[str] = None,
run_as_non_root: bool = False,
secret: Optional[str] = None,
persistent_volumes: List[Tuple[str, str]] = []) -> None:
persistent_volumes: List[Tuple[str, str]] = [],
service_account_name: Optional[str] = None,
annotations: Optional[Dict[str, str]] = None) -> None:
if not _kubernetes_enabled:
raise OptionalModuleMissing(['kubernetes'],
"Kubernetes provider requires kubernetes module and config.")
Expand Down Expand Up @@ -146,6 +152,8 @@ def __init__(self,
self.group_id = group_id
self.run_as_non_root = run_as_non_root
self.persistent_volumes = persistent_volumes
self.service_account_name = service_account_name
self.annotations = annotations

self.kube_client = client.CoreV1Api()

Expand Down Expand Up @@ -184,7 +192,9 @@ def submit(self, cmd_string, tasks_per_node, job_name="parsl"):
pod_name=pod_name,
job_name=job_name,
cmd_string=formatted_cmd,
volumes=self.persistent_volumes)
volumes=self.persistent_volumes,
service_account_name=self.service_account_name,
annotations=self.annotations)
self.resources[pod_name] = {'status': JobStatus(JobState.RUNNING)}

return pod_name
Expand Down Expand Up @@ -253,7 +263,9 @@ def _create_pod(self,
job_name,
port=80,
cmd_string=None,
volumes=[]):
volumes=[],
service_account_name=None,
annotations=None):
""" Create a kubernetes pod for the job.
Args:
- image (string) : Docker image to launch
Expand Down Expand Up @@ -311,11 +323,12 @@ def _create_pod(self,
claim_name=volume[0])))

metadata = client.V1ObjectMeta(name=pod_name,
labels={"app": job_name})
labels={"app": job_name},
annotations=annotations)
spec = client.V1PodSpec(containers=[container],
image_pull_secrets=[secret],
volumes=volume_defs
)
volumes=volume_defs,
service_account_name=service_account_name)

pod = client.V1Pod(spec=spec, metadata=metadata)
api_response = self.kube_client.create_namespaced_pod(namespace=self.namespace,
Expand Down

0 comments on commit 2200f62

Please sign in to comment.