|
| 1 | +from typing import Any, Dict, Optional, Union |
| 2 | + |
| 3 | +from clipped.compact.pydantic import Field, StrictStr |
| 4 | +from clipped.types.ref_or_obj import RefField |
| 5 | +from clipped.utils.versions import clean_version_post_suffix |
| 6 | + |
| 7 | +from polyaxon import pkg |
| 8 | +from polyaxon._containers.pull_policy import PullPolicy |
| 9 | +from polyaxon._k8s import k8s_schemas |
| 10 | +from polyaxon._schemas.base import BaseSchemaModel |
| 11 | + |
| 12 | + |
| 13 | +def get_tmux_resources() -> k8s_schemas.V1ResourceRequirements: |
| 14 | + return k8s_schemas.V1ResourceRequirements( |
| 15 | + limits={"cpu": "100m", "memory": "64Mi"}, |
| 16 | + requests={"cpu": "50m", "memory": "32Mi"}, |
| 17 | + ) |
| 18 | + |
| 19 | + |
| 20 | +class V1PolyaxonTmuxContainer(BaseSchemaModel): |
| 21 | + _IDENTIFIER = "tmux" |
| 22 | + |
| 23 | + image: Optional[StrictStr] = None |
| 24 | + image_tag: Optional[StrictStr] = Field(alias="imageTag", default=None) |
| 25 | + image_pull_policy: Optional[PullPolicy] = Field( |
| 26 | + alias="imagePullPolicy", default=None |
| 27 | + ) |
| 28 | + resources: Optional[Union[Dict[str, Any], RefField]] = None |
| 29 | + |
| 30 | + def get_image(self): |
| 31 | + image = self.image or "polyaxon/polyaxon-tmux" |
| 32 | + image_tag = ( |
| 33 | + self.image_tag |
| 34 | + if self.image_tag is not None |
| 35 | + else clean_version_post_suffix(pkg.VERSION) |
| 36 | + ) |
| 37 | + return "{}:{}".format(image, image_tag) if image_tag else image |
| 38 | + |
| 39 | + def get_resources(self): |
| 40 | + return self.resources if self.resources else get_tmux_resources() |
| 41 | + |
| 42 | + |
| 43 | +def get_default_tmux_container( |
| 44 | + schema=True, |
| 45 | +) -> Union[Dict, V1PolyaxonTmuxContainer]: |
| 46 | + default = { |
| 47 | + "image": "polyaxon/polyaxon-tmux", |
| 48 | + "imageTag": clean_version_post_suffix(pkg.VERSION), |
| 49 | + "imagePullPolicy": PullPolicy.IF_NOT_PRESENT.value, |
| 50 | + "resources": { |
| 51 | + "limits": {"cpu": "100m", "memory": "64Mi"}, |
| 52 | + "requests": {"cpu": "50m", "memory": "32Mi"}, |
| 53 | + }, |
| 54 | + } |
| 55 | + if schema: |
| 56 | + return V1PolyaxonTmuxContainer.from_dict(default) |
| 57 | + return default |
0 commit comments