Skip to content

Commit

Permalink
Update polypod by converter
Browse files Browse the repository at this point in the history
  • Loading branch information
polyaxon-ci committed May 5, 2023
1 parent ae234b7 commit 7a37dba
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 72 deletions.
6 changes: 3 additions & 3 deletions cli/polyaxon/cli/executor/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from polyaxon.cli.operations import logs as run_logs
from polyaxon.exceptions import (
PolyaxonCompilerError,
PolyaxonConverterError,
PolyaxonK8sError,
PolypodException,
)
from polyaxon.k8s import converter
from polyaxon.k8s.executor.executor import Executor
Expand All @@ -46,7 +46,7 @@ def run(
log: bool,
):
if not settings.SET_AGENT:
Printer.warning("Polypod not configured!")
Printer.warning("Agent not configured!")
return

def create_run():
Expand All @@ -73,7 +73,7 @@ def create_run():
# cache.cache(config_manager=RunConfigManager, response=response)
run_job_uid = get_resource_name(run_name)
Printer.success("A new run `{}` was created".format(run_job_uid))
except (PolyaxonCompilerError, PolyaxonK8sError, PolypodException) as e:
except (PolyaxonCompilerError, PolyaxonK8sError, PolyaxonConverterError) as e:
handle_cli_error(e, message="Could not create a run.")
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion cli/polyaxon/compiler/resolver/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def resolve(
agent_config = settings.AGENT_CONFIG.clone()
if not agent_config:
raise PolyaxonCompilerError(
"Polypod configuration not found or agent not configured."
"Agent configuration not found or agent not configured."
)

self.default_sa = agent_config.runs_sa
Expand Down
12 changes: 6 additions & 6 deletions cli/polyaxon/docker/converter/common/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
EV_KEYS_SECRET_INTERNAL_TOKEN,
EV_KEYS_SECRET_KEY,
)
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.services.headers import PolyaxonServiceHeaders


Expand All @@ -49,7 +49,7 @@ def get_env_var(name: str, value: Any) -> Tuple[str, str]:
try:
value = orjson_dumps(value)
except (ValueError, TypeError) as e:
raise PolypodException(e)
raise PolyaxonConverterError(e)

return name, value

Expand All @@ -61,7 +61,7 @@ def get_kv_env_vars(kv_env_vars: List[List]) -> List[Tuple[str, str]]:

for kv_env_var in kv_env_vars:
if not kv_env_var or not len(kv_env_var) == 2:
raise PolypodException(
raise PolyaxonConverterError(
"Received a wrong a key value env var `{}`".format(kv_env_var)
)
env_vars.append(get_env_var(name=kv_env_var[0], value=kv_env_var[1]))
Expand All @@ -76,7 +76,7 @@ def get_from_json_env_var(resource_ref_name: str) -> Optional[List[Tuple[str, st
try:
secret_value = orjson_loads(secret)
except Exception as e:
raise PolypodException from e
raise PolyaxonConverterError from e

return list(secret_value.items())

Expand All @@ -90,7 +90,7 @@ def get_item_from_json_env_var(
try:
secret_value = orjson_loads(secret)
except Exception as e:
raise PolypodException from e
raise PolyaxonConverterError from e

value = secret_value.get(key)
return key, value
Expand Down Expand Up @@ -275,7 +275,7 @@ def get_service_env_vars(
)
if include_agent_token and polyaxon_agent_secret_ref:
if internal:
raise PolypodException(
raise PolyaxonConverterError(
"A service cannot have internal token and agent token."
)
env_vars.append(
Expand Down
2 changes: 1 addition & 1 deletion cli/polyaxon/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, cmd, args, return_code, stdout, stderr):
super().__init__(message=message)


class PolypodException(PolyaxonException):
class PolyaxonConverterError(PolyaxonException):
pass


Expand Down
8 changes: 4 additions & 4 deletions cli/polyaxon/k8s/converter/common/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
EV_KEYS_SECRET_INTERNAL_TOKEN,
EV_KEYS_SECRET_KEY,
)
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common.accelerators import requests_gpu
from polyaxon.services.headers import PolyaxonServiceHeaders
Expand All @@ -50,7 +50,7 @@ def get_env_var(name: str, value: Any) -> k8s_schemas.V1EnvVar:
try:
value = orjson_dumps(value)
except (ValueError, TypeError) as e:
raise PolypodException(e)
raise PolyaxonConverterError(e)

return k8s_schemas.V1EnvVar(name=name, value=value)

Expand All @@ -62,7 +62,7 @@ def get_kv_env_vars(kv_env_vars: List[List]) -> List[k8s_schemas.V1EnvVar]:

for kv_env_var in kv_env_vars:
if not kv_env_var or not len(kv_env_var) == 2:
raise PolypodException(
raise PolyaxonConverterError(
"Received a wrong a key value env var `{}`".format(kv_env_var)
)
env_vars.append(get_env_var(name=kv_env_var[0], value=kv_env_var[1]))
Expand Down Expand Up @@ -287,7 +287,7 @@ def get_service_env_vars(
)
if include_agent_token and polyaxon_agent_secret_ref:
if internal:
raise PolypodException(
raise PolyaxonConverterError(
"A service cannot have internal token and agent token."
)
env_vars.append(
Expand Down
14 changes: 7 additions & 7 deletions cli/polyaxon/k8s/converter/converters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from polyaxon.connections import V1Connection, V1ConnectionKind, V1ConnectionResource
from polyaxon.containers.names import INIT_PREFIX, SIDECAR_PREFIX
from polyaxon.env_vars.keys import EV_KEYS_NO_API
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common.annotations import get_connection_annotations
from polyaxon.k8s.converter.common.containers import (
Expand Down Expand Up @@ -97,27 +97,27 @@ def __init__(
def is_valid(self):
super().is_valid()
if not self.GROUP:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid GROUP"
)
if not self.API_VERSION:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid API_VERSION"
)
if not self.PLURAL:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid PLURAL"
)
if not self.K8S_ANNOTATIONS_KIND:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid K8S_ANNOTATIONS_KIND"
)
if not self.K8S_LABELS_COMPONENT:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid K8S_LABELS_COMPONENT"
)
if not self.K8S_LABELS_PART_OF:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid K8S_LABELS_PART_OF"
)

Expand Down
4 changes: 2 additions & 2 deletions cli/polyaxon/k8s/converter/init/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
generate_container_name,
)
from polyaxon.contexts import paths as ctx_paths
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common.mounts import get_artifacts_context_mount
from polyaxon.k8s.converter.init.store import get_base_store_container, get_volume_args
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_artifacts_path_container(
env: Optional[List[k8s_schemas.V1EnvVar]] = None,
) -> Optional[k8s_schemas.V1Container]:
if not artifacts_store:
raise PolypodException("Init artifacts container requires a store.")
raise PolyaxonConverterError("Init artifacts container requires a store.")

env = to_list(env, check_none=True)
init_args = init_artifact_context_args(run_path=run_path)
Expand Down
6 changes: 4 additions & 2 deletions cli/polyaxon/k8s/converter/init/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
generate_container_name,
)
from polyaxon.contexts import paths as ctx_paths
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common import constants
from polyaxon.k8s.converter.common.containers import patch_container
Expand Down Expand Up @@ -53,7 +53,9 @@ def get_custom_init_container(
mount_path: Optional[str] = None,
) -> k8s_schemas.V1Container:
if not connection:
raise PolypodException("A connection is required to create a repo context.")
raise PolyaxonConverterError(
"A connection is required to create a repo context."
)

volume_name = (
get_volume_name(mount_path) if mount_path else constants.VOLUME_MOUNT_ARTIFACTS
Expand Down
12 changes: 8 additions & 4 deletions cli/polyaxon/k8s/converter/init/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from polyaxon.containers.names import INIT_GIT_CONTAINER_PREFIX, generate_container_name
from polyaxon.contexts import paths as ctx_paths
from polyaxon.env_vars.keys import EV_KEYS_SSH_PATH
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common import constants
from polyaxon.k8s.converter.common.containers import patch_container
Expand Down Expand Up @@ -56,9 +56,11 @@ def get_repo_context_args(
flags: Optional[List[str]] = None,
) -> List[str]:
if not name:
raise PolypodException("A repo name is required to create a repo context.")
raise PolyaxonConverterError(
"A repo name is required to create a repo context."
)
if not url:
raise PolypodException("A repo url is required to create a repo context.")
raise PolyaxonConverterError("A repo url is required to create a repo context.")

args = [
"--repo-path={}".format(os.path.join(mount_path, name)),
Expand Down Expand Up @@ -87,7 +89,9 @@ def get_git_init_container(
track: bool = False,
) -> k8s_schemas.V1Container:
if not connection:
raise PolypodException("A connection is required to create a repo context.")
raise PolyaxonConverterError(
"A connection is required to create a repo context."
)
container_name = generate_container_name(INIT_GIT_CONTAINER_PREFIX, connection.name)
if not container:
container = k8s_schemas.V1Container(name=container_name)
Expand Down
4 changes: 2 additions & 2 deletions cli/polyaxon/k8s/converter/init/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
generate_container_name,
)
from polyaxon.contexts import paths as ctx_paths
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common import constants
from polyaxon.k8s.converter.common.containers import patch_container
Expand Down Expand Up @@ -225,7 +225,7 @@ def get_base_store_container(

# Artifact store needs to allow init the contexts as well, so the store is not required
if not store:
raise PolypodException("Init store container requires a store")
raise PolyaxonConverterError("Init store container requires a store")
secret = None
if store.is_bucket:
secret = store.secret
Expand Down
4 changes: 2 additions & 2 deletions cli/polyaxon/k8s/converter/main/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from clipped.utils.lists import to_list

from polyaxon.connections import V1Connection, V1ConnectionResource
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common.containers import patch_container
from polyaxon.k8s.converter.common.env_vars import get_env_from_k8s_resources
Expand Down Expand Up @@ -55,7 +55,7 @@ def get_main_container(
config_maps = config_maps or []

if artifacts_store and not run_path:
raise PolypodException("Run path is required for main container.")
raise PolyaxonConverterError("Run path is required for main container.")

if artifacts_store and (
not plugins.collect_artifacts or plugins.mount_artifacts_store
Expand Down
4 changes: 2 additions & 2 deletions cli/polyaxon/k8s/converter/main/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
EV_KEYS_COLLECT_ARTIFACTS,
EV_KEYS_COLLECT_RESOURCES,
)
from polyaxon.exceptions import PolyaxonSchemaError, PolypodException
from polyaxon.exceptions import PolyaxonConverterError, PolyaxonSchemaError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common.env_vars import (
get_connection_env_var,
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_env_vars(
check_none=True,
)
except PolyaxonSchemaError as e:
raise PolypodException("Error resolving secrets: %s" % e) from e
raise PolyaxonConverterError("Error resolving secrets: %s" % e) from e

env_vars += get_kv_env_vars(kv_env_vars)
env_vars += get_env_vars_from_k8s_resources(
Expand Down
4 changes: 2 additions & 2 deletions cli/polyaxon/k8s/converter/pod/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from clipped.utils.lists import to_list
from clipped.utils.sanitizers import sanitize_string_dict

from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.polyflow import V1Environment

Expand All @@ -36,7 +36,7 @@ def get_pod_spec(
volumes: Optional[List[k8s_schemas.V1Volume]],
) -> Tuple[k8s_schemas.V1ObjectMeta, k8s_schemas.V1PodSpec]:
if not main_container:
raise PolypodException("A main container is required")
raise PolyaxonConverterError("A main container is required")
environment = environment or V1Environment()

metadata = k8s_schemas.V1ObjectMeta(
Expand Down
6 changes: 3 additions & 3 deletions cli/polyaxon/k8s/converter/sidecar/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from polyaxon.auxiliaries import V1PolyaxonSidecarContainer
from polyaxon.connections import V1Connection
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.k8s import k8s_schemas
from polyaxon.k8s.converter.common.containers import patch_container
from polyaxon.k8s.converter.common.env_vars import (
Expand Down Expand Up @@ -64,7 +64,7 @@ def get_sidecar_container(
run_path: Optional[str],
) -> Optional[k8s_schemas.V1Container]:
if artifacts_store and not plugins:
raise PolypodException(
raise PolyaxonConverterError(
"Logs/artifacts store was passed and contexts was not passed."
)

Expand All @@ -76,7 +76,7 @@ def get_sidecar_container(
return None

if (has_artifacts or has_logs) and not run_path:
raise PolypodException("Logs store/outputs store must have a run_path.")
raise PolyaxonConverterError("Logs store/outputs store must have a run_path.")

env = get_sidecar_env_vars(
env_vars=env,
Expand Down
6 changes: 3 additions & 3 deletions cli/polyaxon/runner/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from polyaxon import live_state, settings
from polyaxon.client import PolyaxonClient
from polyaxon.env_vars.getters import get_run_info
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.lifecycle import V1StatusCondition, V1Statuses
from polyaxon.logger import logger
from polyaxon.schemas.cli.checks_config import ChecksConfig
Expand Down Expand Up @@ -295,7 +295,7 @@ def make_run_resource(
content=content,
default_auth=default_auth,
)
except PolypodException as e:
except PolyaxonConverterError as e:
logger.info(
"Run could not be cleaned. Agent failed converting run manifest: {}\n{}".format(
repr(e), traceback.format_exc()
Expand Down Expand Up @@ -339,7 +339,7 @@ def prepare_run_resource(
default_auth=True,
agent_content=self.content,
)
except PolypodException as e:
except PolyaxonConverterError as e:
self.log_run_failed(
run_owner=owner_name,
run_project=project_name,
Expand Down
6 changes: 3 additions & 3 deletions cli/polyaxon/runner/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from polyaxon import settings
from polyaxon.env_vars.keys import EV_KEYS_LOG_LEVEL, EV_KEYS_NO_API
from polyaxon.exceptions import PolypodException
from polyaxon.exceptions import PolyaxonConverterError
from polyaxon.polyflow import V1Init
from polyaxon.services.auth import AuthenticationTypes
from polyaxon.services.headers import PolyaxonServiceHeaders
Expand Down Expand Up @@ -66,11 +66,11 @@ def get_resource_name(self):

def is_valid(self):
if not self.SPEC_KIND:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid SPEC_KIND"
)
if not self.MAIN_CONTAINER_ID:
raise PolypodException(
raise PolyaxonConverterError(
"Please make sure that a converter subclass has a valid MAIN_CONTAINER_ID"
)

Expand Down
Loading

0 comments on commit 7a37dba

Please sign in to comment.