Skip to content

Commit

Permalink
add run- prefix to resource names before creation
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshh committed Jun 28, 2024
1 parent eb8168f commit 92d492e
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_configmap(
labels: Optional[Dict] = None,
data: Optional[Dict[str, str]] = None,
):
name = f"run-{name}"
meta = k8s_client.V1ObjectMeta(annotations=annotations, labels=labels, name=name)
return k8s_client.V1ConfigMap(metadata=meta, data=data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_deployment_spec(
resource_requests: Optional[Dict[str, int | float | str]] = None,
provisioning_model: Literal["standard", "spot"] = "spot",
) -> k8s_client.V1Deployment:
name = f"run-{name}"
schedule_toleration = k8s_client.V1Toleration(
key="worker-pool", operator="Equal", value="true", effect="NoSchedule"
)
Expand Down Expand Up @@ -128,6 +129,7 @@ def get_deployment(
labels: Optional[Dict[str, str]] = None,
revision_history_limit: Optional[int] = 10,
) -> k8s_client.V1Deployment:
name = f"run-{name}"
labels = labels or {"app": name}
pod_template = k8s_client.V1PodTemplateSpec(
metadata=k8s_client.V1ObjectMeta(labels=labels),
Expand Down
2 changes: 2 additions & 0 deletions zetta_utils/cloud_management/resource_allocation/k8s/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_job_template(
selector: Optional[k8s_client.V1LabelSelector] = None,
suspend: Optional[bool] = False,
) -> k8s_client.V1JobTemplateSpec:
name = f"run-{name}"
meta = k8s_client.V1ObjectMeta(name=name, labels=labels)
job_spec = _get_job_spec(
pod_spec=pod_spec,
Expand All @@ -83,6 +84,7 @@ def get_job(
selector: Optional[k8s_client.V1LabelSelector] = None,
suspend: Optional[bool] = False,
) -> k8s_client.V1Job:
name = f"run-{name}"
meta = k8s_client.V1ObjectMeta(name=name, labels=labels)
job_spec = _get_job_spec(
pod_spec=pod_spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_pod_spec(
volume_mounts: Optional[List[k8s_client.V1VolumeMount]] = None,
resource_requests: Optional[Dict[str, int | float | str]] = None,
) -> k8s_client.V1PodSpec:

name = f"run-{name}"
envs = envs or []
host_aliases = host_aliases or []
tolerations = tolerations or []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_secrets_and_mapping(
raise ValueError(
f"Please set `{env_k}` environment variable in order to create a deployment."
)
secret_name = f"{run_id}-{env_k}".lower().replace("_", "-")
secret_name = f"run-{run_id}-{env_k}".lower().replace("_", "-")
env_secret_mapping[env_k] = secret_name
secrets_kv[secret_name] = env_v

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get_service(
selector: Optional[Dict[str, str]] = None,
service_type: Optional[str] = None,
):
name = f"run-{name}"
meta = k8s_client.V1ObjectMeta(annotations=annotations, labels=labels, name=name)
service_spec = k8s_client.V1ServiceSpec(ports=ports, selector=selector, type=service_type)
return k8s_client.V1Service(metadata=meta, spec=service_spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def get_gcp_with_sqs_config(
semaphores_spec: dict[SemaphoreType, int] | None = None,
provisioning_model: Literal["standard", "spot"] = "spot",
) -> tuple[PushMessageQueue[Task], PullMessageQueue[OutcomeReport], list[AbstractContextManager]]:
work_queue_name = f"zzz-{execution_id}-work"
outcome_queue_name = f"zzz-{execution_id}-outcome"
work_queue_name = f"run-{execution_id}-work"
outcome_queue_name = f"run-{execution_id}-outcome"

task_queue_spec = {
"@type": "SQSQueue",
Expand Down
4 changes: 2 additions & 2 deletions zetta_utils/mazepa_addons/configurations/execute_on_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def get_slurm_contex_managers(
semaphores_spec: dict[SemaphoreType, int] | None,
message_queue: Literal["sqs", "fq"],
) -> tuple[PushMessageQueue[Task], PullMessageQueue[OutcomeReport], list[AbstractContextManager]]:
work_queue_name = f"zzz-{execution_id}-work"
outcome_queue_name = f"zzz-{execution_id}-outcome"
work_queue_name = f"run-{execution_id}-work"
outcome_queue_name = f"run-{execution_id}-outcome"

if message_queue == "fq":
task_queue_spec = {
Expand Down
2 changes: 0 additions & 2 deletions zetta_utils/run/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Resource:

def register_resource(resource: Resource) -> str:
_resource = attrs.asdict(resource)
resource_name = _resource.get("name", "")
_resource["name"] = f"run-{resource_name}"
row_key = str(uuid.uuid4())
col_keys = tuple(_resource.keys())
RESOURCE_DB[(row_key, col_keys)] = _resource
Expand Down

0 comments on commit 92d492e

Please sign in to comment.