polyaxon 2.0.0rc49__py3-none-any.whl → 2.4.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polyaxon/_auxiliaries/cleaner.py +8 -3
- polyaxon/_auxiliaries/init.py +7 -2
- polyaxon/_auxiliaries/notifier.py +8 -2
- polyaxon/_auxiliaries/sidecar.py +30 -2
- polyaxon/_cli/artifacts.py +96 -11
- polyaxon/_cli/components.py +96 -11
- polyaxon/_cli/config.py +118 -22
- polyaxon/_cli/dashboard.py +15 -2
- polyaxon/_cli/init.py +1 -1
- polyaxon/_cli/models.py +96 -11
- polyaxon/_cli/operations.py +267 -90
- polyaxon/_cli/project_versions.py +139 -6
- polyaxon/_cli/projects.py +23 -9
- polyaxon/_cli/run.py +37 -9
- polyaxon/_cli/services/agent.py +2 -2
- polyaxon/_cli/services/clean_artifacts.py +1 -1
- polyaxon/_cli/services/sidecar.py +8 -1
- polyaxon/_client/client.py +17 -0
- polyaxon/_client/mixin.py +39 -0
- polyaxon/_client/project.py +218 -23
- polyaxon/_client/run.py +131 -33
- polyaxon/_compiler/contexts/contexts.py +2 -2
- polyaxon/_compiler/contexts/ray_job.py +4 -2
- polyaxon/_compiler/resolver/agent.py +12 -2
- polyaxon/_compiler/resolver/runtime.py +2 -2
- polyaxon/_contexts/paths.py +4 -7
- polyaxon/_deploy/operators/compose.py +1 -27
- polyaxon/_deploy/schemas/deployment.py +4 -1
- polyaxon/_deploy/schemas/intervals.py +0 -7
- polyaxon/_deploy/schemas/proxy.py +1 -0
- polyaxon/_deploy/schemas/service.py +11 -1
- polyaxon/_docker/converter/base/base.py +8 -0
- polyaxon/_docker/executor.py +10 -4
- polyaxon/_env_vars/getters/owner_entity.py +4 -2
- polyaxon/_env_vars/getters/project.py +4 -2
- polyaxon/_env_vars/getters/run.py +5 -2
- polyaxon/_env_vars/keys.py +7 -1
- polyaxon/_flow/__init__.py +2 -0
- polyaxon/_flow/builds/__init__.py +19 -6
- polyaxon/_flow/component/base.py +1 -0
- polyaxon/_flow/component/component.py +14 -0
- polyaxon/_flow/environment/__init__.py +8 -8
- polyaxon/_flow/hooks/__init__.py +19 -6
- polyaxon/_flow/init/__init__.py +6 -6
- polyaxon/_flow/matrix/iterative.py +0 -1
- polyaxon/_flow/matrix/tuner.py +18 -6
- polyaxon/_flow/operations/operation.py +44 -17
- polyaxon/_flow/plugins/__init__.py +6 -0
- polyaxon/_flow/run/__init__.py +2 -2
- polyaxon/_flow/run/dag.py +2 -2
- polyaxon/_flow/run/dask/dask.py +0 -1
- polyaxon/_flow/run/dask/replica.py +3 -3
- polyaxon/_flow/run/enums.py +5 -0
- polyaxon/_flow/run/job.py +4 -4
- polyaxon/_flow/run/kubeflow/mpi_job.py +1 -2
- polyaxon/_flow/run/kubeflow/mx_job.py +1 -2
- polyaxon/_flow/run/kubeflow/paddle_job.py +35 -4
- polyaxon/_flow/run/kubeflow/pytorch_job.py +51 -5
- polyaxon/_flow/run/kubeflow/replica.py +4 -4
- polyaxon/_flow/run/kubeflow/scheduling_policy.py +12 -0
- polyaxon/_flow/run/kubeflow/tf_job.py +3 -3
- polyaxon/_flow/run/kubeflow/xgboost_job.py +1 -2
- polyaxon/_flow/run/ray/ray.py +2 -3
- polyaxon/_flow/run/ray/replica.py +3 -3
- polyaxon/_flow/run/service.py +4 -4
- polyaxon/_fs/fs.py +7 -2
- polyaxon/_fs/utils.py +3 -2
- polyaxon/_k8s/converter/base/base.py +2 -1
- polyaxon/_k8s/converter/base/main.py +1 -0
- polyaxon/_k8s/converter/base/sidecar.py +16 -1
- polyaxon/_k8s/converter/common/accelerators.py +7 -4
- polyaxon/_k8s/converter/converters/job.py +1 -1
- polyaxon/_k8s/converter/converters/kubeflow/paddle_job.py +1 -0
- polyaxon/_k8s/converter/converters/kubeflow/pytroch_job.py +2 -0
- polyaxon/_k8s/converter/converters/kubeflow/tf_job.py +1 -0
- polyaxon/_k8s/converter/converters/ray_job.py +4 -2
- polyaxon/_k8s/custom_resources/dask_job.py +3 -0
- polyaxon/_k8s/custom_resources/kubeflow/common.py +4 -1
- polyaxon/_k8s/custom_resources/kubeflow/paddle_job.py +10 -1
- polyaxon/_k8s/custom_resources/kubeflow/pytorch_job.py +14 -1
- polyaxon/_k8s/custom_resources/kubeflow/tf_job.py +4 -0
- polyaxon/_k8s/custom_resources/ray_job.py +3 -0
- polyaxon/_k8s/custom_resources/setter.py +1 -1
- polyaxon/_k8s/executor/async_executor.py +2 -0
- polyaxon/_k8s/executor/base.py +23 -6
- polyaxon/_k8s/logging/async_monitor.py +150 -5
- polyaxon/_k8s/manager/async_manager.py +96 -23
- polyaxon/_k8s/manager/base.py +4 -0
- polyaxon/_k8s/manager/manager.py +282 -134
- polyaxon/_local_process/__init__.py +0 -0
- polyaxon/_local_process/agent.py +6 -0
- polyaxon/_local_process/converter/__init__.py +1 -0
- polyaxon/_local_process/converter/base/__init__.py +1 -0
- polyaxon/_local_process/converter/base/base.py +140 -0
- polyaxon/_local_process/converter/base/containers.py +69 -0
- polyaxon/_local_process/converter/base/env_vars.py +253 -0
- polyaxon/_local_process/converter/base/init.py +414 -0
- polyaxon/_local_process/converter/base/main.py +74 -0
- polyaxon/_local_process/converter/base/mounts.py +82 -0
- polyaxon/_local_process/converter/converters/__init__.py +8 -0
- polyaxon/_local_process/converter/converters/job.py +40 -0
- polyaxon/_local_process/converter/converters/service.py +41 -0
- polyaxon/_local_process/converter/mixins.py +38 -0
- polyaxon/_local_process/executor.py +132 -0
- polyaxon/_local_process/process_types.py +39 -0
- polyaxon/_managers/agent.py +2 -0
- polyaxon/_managers/home.py +2 -1
- polyaxon/_operations/tuner.py +1 -0
- polyaxon/_polyaxonfile/check.py +2 -0
- polyaxon/_polyaxonfile/manager/operations.py +3 -0
- polyaxon/_polyaxonfile/manager/workflows.py +2 -0
- polyaxon/_polyaxonfile/specs/compiled_operation.py +1 -0
- polyaxon/_polyaxonfile/specs/operation.py +1 -0
- polyaxon/_polyaxonfile/specs/sections.py +3 -0
- polyaxon/_pql/manager.py +1 -1
- polyaxon/_runner/agent/async_agent.py +97 -21
- polyaxon/_runner/agent/base_agent.py +27 -9
- polyaxon/_runner/agent/client.py +15 -1
- polyaxon/_runner/agent/sync_agent.py +85 -20
- polyaxon/_runner/converter/converter.py +6 -2
- polyaxon/_runner/executor.py +13 -7
- polyaxon/_schemas/agent.py +27 -1
- polyaxon/_schemas/client.py +30 -3
- polyaxon/_schemas/installation.py +4 -3
- polyaxon/_schemas/lifecycle.py +10 -5
- polyaxon/_schemas/log_handler.py +2 -3
- polyaxon/_schemas/types/artifacts.py +3 -3
- polyaxon/_schemas/types/dockerfile.py +3 -3
- polyaxon/_schemas/types/file.py +3 -3
- polyaxon/_schemas/types/git.py +3 -3
- polyaxon/_schemas/types/tensorboard.py +3 -3
- polyaxon/_sdk/api/agents_v1_api.py +1076 -73
- polyaxon/_sdk/api/organizations_v1_api.py +371 -10
- polyaxon/_sdk/api/project_dashboards_v1_api.py +12 -12
- polyaxon/_sdk/api/project_searches_v1_api.py +12 -12
- polyaxon/_sdk/api/projects_v1_api.py +221 -44
- polyaxon/_sdk/api/runs_v1_api.py +917 -445
- polyaxon/_sdk/api/service_accounts_v1_api.py +16 -16
- polyaxon/_sdk/api/teams_v1_api.py +2827 -375
- polyaxon/_sdk/api/users_v1_api.py +231 -55
- polyaxon/_sdk/async_client/api_client.py +4 -0
- polyaxon/_sdk/schemas/__init__.py +10 -2
- polyaxon/_sdk/schemas/v1_agent.py +2 -1
- polyaxon/_sdk/schemas/v1_agent_reconcile_body_request.py +14 -0
- polyaxon/_sdk/schemas/v1_artifact_tree.py +1 -1
- polyaxon/_sdk/schemas/v1_dashboard_spec.py +4 -0
- polyaxon/_sdk/schemas/v1_events_response.py +4 -0
- polyaxon/_sdk/schemas/v1_organization.py +1 -0
- polyaxon/_sdk/schemas/v1_preset.py +8 -0
- polyaxon/_sdk/schemas/v1_project.py +1 -0
- polyaxon/_sdk/schemas/v1_project_settings.py +4 -2
- polyaxon/_sdk/schemas/v1_run.py +2 -2
- polyaxon/_sdk/schemas/v1_run_edge_lineage.py +14 -0
- polyaxon/_sdk/schemas/v1_run_edges_graph.py +9 -0
- polyaxon/_sdk/schemas/v1_section_spec.py +7 -2
- polyaxon/_sdk/schemas/v1_settings_catalog.py +1 -0
- polyaxon/_sdk/schemas/v1_team.py +3 -0
- polyaxon/_sdk/schemas/v1_user.py +1 -2
- polyaxon/_sdk/schemas/v1_user_access.py +17 -0
- polyaxon/_services/values.py +1 -0
- polyaxon/_sidecar/container/__init__.py +39 -18
- polyaxon/_sidecar/container/monitors/__init__.py +1 -0
- polyaxon/_sidecar/container/monitors/logs.py +10 -13
- polyaxon/_sidecar/container/monitors/spec.py +24 -0
- polyaxon/_sidecar/ignore.py +0 -1
- polyaxon/_utils/fqn_utils.py +25 -2
- polyaxon/client.py +1 -1
- polyaxon/pkg.py +1 -1
- polyaxon/schemas.py +8 -1
- polyaxon/settings.py +6 -0
- {polyaxon-2.0.0rc49.dist-info → polyaxon-2.4.0rc1.dist-info}/METADATA +43 -43
- {polyaxon-2.0.0rc49.dist-info → polyaxon-2.4.0rc1.dist-info}/RECORD +176 -155
- {polyaxon-2.0.0rc49.dist-info → polyaxon-2.4.0rc1.dist-info}/WHEEL +1 -1
- polyaxon/_sdk/schemas/v1_project_user_access.py +0 -10
- {polyaxon-2.0.0rc49.dist-info → polyaxon-2.4.0rc1.dist-info}/LICENSE +0 -0
- {polyaxon-2.0.0rc49.dist-info → polyaxon-2.4.0rc1.dist-info}/entry_points.txt +0 -0
- {polyaxon-2.0.0rc49.dist-info → polyaxon-2.4.0rc1.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
from polyaxon._local_process.converter.base.base import BaseConverter
|
@@ -0,0 +1,140 @@
|
|
1
|
+
from typing import Dict, Iterable, List, Optional, Union
|
2
|
+
|
3
|
+
from polyaxon import settings
|
4
|
+
from polyaxon._auxiliaries import V1PolyaxonSidecarContainer
|
5
|
+
from polyaxon._connections import V1Connection, V1ConnectionResource
|
6
|
+
from polyaxon._flow import V1Environment, V1Init, V1Plugins
|
7
|
+
from polyaxon._k8s import k8s_schemas
|
8
|
+
from polyaxon._local_process import process_types
|
9
|
+
from polyaxon._local_process.converter.base.containers import ContainerMixin
|
10
|
+
from polyaxon._local_process.converter.base.env_vars import EnvMixin
|
11
|
+
from polyaxon._local_process.converter.base.init import InitConverter
|
12
|
+
from polyaxon._local_process.converter.base.main import MainConverter
|
13
|
+
from polyaxon._local_process.converter.base.mounts import MountsMixin
|
14
|
+
from polyaxon._runner.converter import BaseConverter as _BaseConverter
|
15
|
+
from polyaxon._runner.kinds import RunnerKind
|
16
|
+
from polyaxon.exceptions import PolyaxonConverterError
|
17
|
+
|
18
|
+
|
19
|
+
class BaseConverter(
|
20
|
+
MainConverter, InitConverter, ContainerMixin, EnvMixin, MountsMixin, _BaseConverter
|
21
|
+
):
|
22
|
+
RUNNER_KIND = RunnerKind.PROCESS
|
23
|
+
|
24
|
+
@classmethod
|
25
|
+
def _get_sidecar_container(
|
26
|
+
cls,
|
27
|
+
container_id: str,
|
28
|
+
polyaxon_sidecar: V1PolyaxonSidecarContainer,
|
29
|
+
env: List[process_types.V1EnvVar],
|
30
|
+
artifacts_store: V1Connection,
|
31
|
+
plugins: V1Plugins,
|
32
|
+
run_path: Optional[str],
|
33
|
+
) -> Optional[process_types.V1Container]:
|
34
|
+
return None
|
35
|
+
|
36
|
+
@classmethod
|
37
|
+
def _k8s_to_process_env_var(
|
38
|
+
cls,
|
39
|
+
env_var: List[k8s_schemas.V1EnvVar],
|
40
|
+
) -> List[process_types.V1EnvVar]:
|
41
|
+
if not env_var:
|
42
|
+
return []
|
43
|
+
|
44
|
+
process_env_var = []
|
45
|
+
for item in env_var:
|
46
|
+
if isinstance(item, dict):
|
47
|
+
try:
|
48
|
+
item = k8s_schemas.V1EnvVar(**item)
|
49
|
+
except (ValueError, TypeError) as e:
|
50
|
+
raise PolyaxonConverterError(
|
51
|
+
f"Could not parse env var value `{item}` from the K8S schema in container section"
|
52
|
+
) from e
|
53
|
+
process_env_var.append(cls._get_env_var(name=item.name, value=item.value))
|
54
|
+
|
55
|
+
return process_env_var
|
56
|
+
|
57
|
+
@staticmethod
|
58
|
+
def _new_container(name: str) -> process_types.V1Container:
|
59
|
+
return process_types.V1Container(name=name)
|
60
|
+
|
61
|
+
@classmethod
|
62
|
+
def _ensure_container(
|
63
|
+
cls,
|
64
|
+
container: Union[k8s_schemas.V1Container, process_types.V1Container],
|
65
|
+
volumes: List[k8s_schemas.V1Volume],
|
66
|
+
) -> process_types.V1Container:
|
67
|
+
if not isinstance(container, k8s_schemas.V1Container):
|
68
|
+
return container
|
69
|
+
return process_types.V1Container(
|
70
|
+
name=container.name,
|
71
|
+
command=container.command,
|
72
|
+
args=container.args,
|
73
|
+
env=cls._k8s_to_process_env_var(container.env),
|
74
|
+
working_dir=container.working_dir,
|
75
|
+
)
|
76
|
+
|
77
|
+
def get_replica_resource(
|
78
|
+
self,
|
79
|
+
environment: V1Environment,
|
80
|
+
plugins: V1Plugins,
|
81
|
+
volumes: List[k8s_schemas.V1Volume],
|
82
|
+
init: List[V1Init],
|
83
|
+
sidecars: List[k8s_schemas.V1Container],
|
84
|
+
container: k8s_schemas.V1Container,
|
85
|
+
artifacts_store: V1Connection,
|
86
|
+
connections: List[str],
|
87
|
+
connection_by_names: Dict[str, V1Connection],
|
88
|
+
secrets: Optional[Iterable[V1ConnectionResource]],
|
89
|
+
config_maps: Optional[Iterable[V1ConnectionResource]],
|
90
|
+
kv_env_vars: List[List],
|
91
|
+
default_sa: Optional[str] = None,
|
92
|
+
ports: List[int] = None,
|
93
|
+
) -> List[process_types.V1Container]:
|
94
|
+
volumes = volumes or []
|
95
|
+
init = init or []
|
96
|
+
sidecars = sidecars or []
|
97
|
+
connections = connections or []
|
98
|
+
environment = environment or V1Environment()
|
99
|
+
environment.service_account_name = (
|
100
|
+
environment.service_account_name
|
101
|
+
or default_sa
|
102
|
+
or settings.AGENT_CONFIG.runs_sa
|
103
|
+
)
|
104
|
+
|
105
|
+
init_connections = self.filter_connections_from_init(init=init)
|
106
|
+
|
107
|
+
init_containers = self.get_init_containers(
|
108
|
+
polyaxon_init=self.polyaxon_init,
|
109
|
+
plugins=plugins,
|
110
|
+
artifacts_store=artifacts_store,
|
111
|
+
init_connections=init_connections,
|
112
|
+
init_containers=self.filter_containers_from_init(init=init),
|
113
|
+
connection_by_names=connection_by_names,
|
114
|
+
log_level=plugins.log_level,
|
115
|
+
volumes=volumes,
|
116
|
+
)
|
117
|
+
|
118
|
+
sidecar_containers = self.get_sidecar_containers(
|
119
|
+
polyaxon_sidecar=self.polyaxon_sidecar,
|
120
|
+
plugins=plugins,
|
121
|
+
artifacts_store=artifacts_store,
|
122
|
+
sidecar_containers=sidecars,
|
123
|
+
log_level=plugins.log_level,
|
124
|
+
volumes=volumes,
|
125
|
+
)
|
126
|
+
|
127
|
+
main_container = self.get_main_container(
|
128
|
+
main_container=self._ensure_container(container, volumes=volumes),
|
129
|
+
plugins=plugins,
|
130
|
+
artifacts_store=artifacts_store,
|
131
|
+
connections=connections,
|
132
|
+
init_connections=init_connections,
|
133
|
+
connection_by_names=connection_by_names,
|
134
|
+
secrets=secrets,
|
135
|
+
config_maps=config_maps,
|
136
|
+
ports=ports,
|
137
|
+
kv_env_vars=kv_env_vars,
|
138
|
+
)
|
139
|
+
|
140
|
+
return init_containers + sidecar_containers + [main_container]
|
@@ -0,0 +1,69 @@
|
|
1
|
+
from typing import Any, Dict, List, Optional
|
2
|
+
|
3
|
+
from clipped.utils.lists import to_list
|
4
|
+
from clipped.utils.sanitizers import sanitize_value
|
5
|
+
|
6
|
+
from polyaxon._containers.names import sanitize_container_name
|
7
|
+
from polyaxon._local_process import process_types
|
8
|
+
from polyaxon._runner.converter import BaseConverter
|
9
|
+
from polyaxon._runner.converter.common.containers import sanitize_container_command_args
|
10
|
+
|
11
|
+
|
12
|
+
class ContainerMixin(BaseConverter):
|
13
|
+
@classmethod
|
14
|
+
def _patch_container(
|
15
|
+
cls,
|
16
|
+
container: process_types.V1Container,
|
17
|
+
name: Optional[str] = None,
|
18
|
+
command: Optional[List[str]] = None,
|
19
|
+
args: Optional[List[str]] = None,
|
20
|
+
env: Optional[List[process_types.V1EnvVar]] = None,
|
21
|
+
env_from: Optional[List[Any]] = None,
|
22
|
+
**kwargs,
|
23
|
+
) -> process_types.V1Container:
|
24
|
+
container.name = sanitize_container_name(name or container.name)
|
25
|
+
container.env = to_list(container.env, check_none=True) + to_list(
|
26
|
+
env, check_none=True
|
27
|
+
)
|
28
|
+
if not any([container.command, container.args]):
|
29
|
+
container.command = command
|
30
|
+
container.args = args
|
31
|
+
|
32
|
+
return cls._sanitize_container(container)
|
33
|
+
|
34
|
+
@staticmethod
|
35
|
+
def _sanitize_container_env(
|
36
|
+
env: List[process_types.V1EnvVar],
|
37
|
+
) -> List[process_types.V1EnvVar]:
|
38
|
+
def sanitize_env_dict(d: Dict):
|
39
|
+
return process_types.V1EnvVar(
|
40
|
+
__root__={
|
41
|
+
d_k: sanitize_value(d_v, handle_dict=False)
|
42
|
+
for d_k, d_v in d.items()
|
43
|
+
}
|
44
|
+
)
|
45
|
+
|
46
|
+
results = []
|
47
|
+
for e in env or []:
|
48
|
+
if isinstance(e, dict):
|
49
|
+
e = sanitize_env_dict(e)
|
50
|
+
results.append(e)
|
51
|
+
elif isinstance(e, tuple):
|
52
|
+
if e[1] is not None:
|
53
|
+
e = process_types.V1EnvVar(
|
54
|
+
__root__=(e[0], sanitize_value(e[1], handle_dict=False))
|
55
|
+
)
|
56
|
+
results.append(e)
|
57
|
+
elif isinstance(e, process_types.V1EnvVar):
|
58
|
+
results.append(e)
|
59
|
+
|
60
|
+
return results
|
61
|
+
|
62
|
+
@classmethod
|
63
|
+
def _sanitize_container(
|
64
|
+
cls,
|
65
|
+
container: process_types.V1Container,
|
66
|
+
) -> process_types.V1Container:
|
67
|
+
container = sanitize_container_command_args(container)
|
68
|
+
container.env = cls._sanitize_container_env(container.env)
|
69
|
+
return container
|
@@ -0,0 +1,253 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from typing import Any, Iterable, List, Optional
|
4
|
+
|
5
|
+
import orjson
|
6
|
+
|
7
|
+
from clipped.utils.enums import get_enum_value
|
8
|
+
from clipped.utils.json import orjson_dumps, orjson_loads
|
9
|
+
from clipped.utils.lists import to_list
|
10
|
+
|
11
|
+
from polyaxon import settings
|
12
|
+
from polyaxon._connections import V1ConnectionResource
|
13
|
+
from polyaxon._env_vars.keys import (
|
14
|
+
ENV_KEYS_API_VERSION,
|
15
|
+
ENV_KEYS_AUTH_TOKEN,
|
16
|
+
ENV_KEYS_AUTHENTICATION_TYPE,
|
17
|
+
ENV_KEYS_HAS_PROCESS_SIDECAR,
|
18
|
+
ENV_KEYS_HEADER,
|
19
|
+
ENV_KEYS_HEADER_SERVICE,
|
20
|
+
ENV_KEYS_HOST,
|
21
|
+
ENV_KEYS_IS_MANAGED,
|
22
|
+
ENV_KEYS_K8S_NAMESPACE,
|
23
|
+
ENV_KEYS_K8S_NODE_NAME,
|
24
|
+
ENV_KEYS_K8S_POD_ID,
|
25
|
+
ENV_KEYS_LOG_LEVEL,
|
26
|
+
ENV_KEYS_SECRET_INTERNAL_TOKEN,
|
27
|
+
ENV_KEYS_SECRET_KEY,
|
28
|
+
)
|
29
|
+
from polyaxon._local_process import process_types
|
30
|
+
from polyaxon._runner.converter import BaseConverter
|
31
|
+
from polyaxon._services.headers import PolyaxonServiceHeaders
|
32
|
+
from polyaxon.api import VERSION_V1
|
33
|
+
from polyaxon.exceptions import PolyaxonConverterError
|
34
|
+
|
35
|
+
|
36
|
+
class EnvMixin(BaseConverter):
|
37
|
+
@staticmethod
|
38
|
+
def _get_env_var(name: str, value: Any) -> process_types.V1EnvVar:
|
39
|
+
if not isinstance(value, str):
|
40
|
+
try:
|
41
|
+
value = orjson_dumps(value)
|
42
|
+
except (ValueError, TypeError) as e:
|
43
|
+
raise PolyaxonConverterError(e)
|
44
|
+
|
45
|
+
return process_types.V1EnvVar(__root__=(name, value))
|
46
|
+
|
47
|
+
@staticmethod
|
48
|
+
def _get_from_json_resource(
|
49
|
+
resource: V1ConnectionResource,
|
50
|
+
) -> List[process_types.V1EnvVar]:
|
51
|
+
if not resource or resource.items or resource.mount_path:
|
52
|
+
return []
|
53
|
+
|
54
|
+
secret = os.environ.get(resource.name)
|
55
|
+
if not secret:
|
56
|
+
return []
|
57
|
+
try:
|
58
|
+
secret_value = orjson_loads(secret)
|
59
|
+
except Exception as e:
|
60
|
+
raise PolyaxonConverterError from e
|
61
|
+
|
62
|
+
return [process_types.V1EnvVar(__root__=k) for k in (secret_value.items())]
|
63
|
+
|
64
|
+
@classmethod
|
65
|
+
def _get_env_from_json_resources(
|
66
|
+
cls,
|
67
|
+
resources: Iterable[V1ConnectionResource],
|
68
|
+
) -> List[process_types.V1EnvVar]:
|
69
|
+
resources = resources or []
|
70
|
+
results = []
|
71
|
+
for resource in resources:
|
72
|
+
results += cls._get_from_json_resource(resource=resource)
|
73
|
+
return [r for r in results if r]
|
74
|
+
|
75
|
+
@staticmethod
|
76
|
+
def _get_item_from_json_resource(
|
77
|
+
key: str, resource_ref_name: str
|
78
|
+
) -> Optional[process_types.V1EnvVar]:
|
79
|
+
secret = os.environ.get(resource_ref_name)
|
80
|
+
if not secret:
|
81
|
+
return None
|
82
|
+
try:
|
83
|
+
secret_value = orjson_loads(secret)
|
84
|
+
except orjson.JSONDecodeError:
|
85
|
+
return process_types.V1EnvVar(__root__=(key, secret))
|
86
|
+
|
87
|
+
value = secret_value.get(key)
|
88
|
+
return process_types.V1EnvVar(__root__=(key, value))
|
89
|
+
|
90
|
+
@classmethod
|
91
|
+
def _get_items_from_json_resource(
|
92
|
+
cls,
|
93
|
+
resource: V1ConnectionResource,
|
94
|
+
) -> List[process_types.V1EnvVar]:
|
95
|
+
items_from = []
|
96
|
+
if not resource or not resource.items:
|
97
|
+
return items_from
|
98
|
+
|
99
|
+
try:
|
100
|
+
secret_value = orjson_loads(resource.name)
|
101
|
+
except orjson.JSONDecodeError as e:
|
102
|
+
return items_from
|
103
|
+
|
104
|
+
for item in resource.items:
|
105
|
+
value = secret_value.get(item)
|
106
|
+
if value:
|
107
|
+
items_from.append(process_types.V1EnvVar(__root__=(item, value)))
|
108
|
+
return items_from
|
109
|
+
|
110
|
+
@classmethod
|
111
|
+
def _get_env_vars_from_resources(
|
112
|
+
cls,
|
113
|
+
resources: Iterable[V1ConnectionResource],
|
114
|
+
) -> List[process_types.V1EnvVar]:
|
115
|
+
resources = resources or []
|
116
|
+
env_vars = []
|
117
|
+
for secret in resources:
|
118
|
+
env_vars += cls._get_items_from_json_resource(resource=secret)
|
119
|
+
return env_vars
|
120
|
+
|
121
|
+
@classmethod
|
122
|
+
def _get_env_vars_from_k8s_resources(
|
123
|
+
cls,
|
124
|
+
secrets: Iterable[V1ConnectionResource],
|
125
|
+
config_maps: Iterable[V1ConnectionResource],
|
126
|
+
) -> List[process_types.V1EnvVar]:
|
127
|
+
resources = to_list(secrets, check_none=True) + to_list(
|
128
|
+
config_maps, check_none=True
|
129
|
+
)
|
130
|
+
return cls._get_env_vars_from_resources(resources=resources)
|
131
|
+
|
132
|
+
@classmethod
|
133
|
+
def _get_additional_env_vars(cls) -> List[process_types.V1EnvVar]:
|
134
|
+
return [cls._get_env_var(name=ENV_KEYS_HAS_PROCESS_SIDECAR, value=True)]
|
135
|
+
|
136
|
+
@classmethod
|
137
|
+
def _get_base_env_vars(
|
138
|
+
cls,
|
139
|
+
namespace: str,
|
140
|
+
resource_name: str,
|
141
|
+
use_proxy_env_vars_use_in_ops: bool,
|
142
|
+
log_level: Optional[str] = None,
|
143
|
+
) -> List[process_types.V1EnvVar]:
|
144
|
+
env = [
|
145
|
+
cls._get_env_var(name=ENV_KEYS_K8S_NODE_NAME, value="process-agent"),
|
146
|
+
cls._get_env_var(name=ENV_KEYS_K8S_NAMESPACE, value=namespace),
|
147
|
+
cls._get_env_var(name=ENV_KEYS_K8S_POD_ID, value=resource_name),
|
148
|
+
]
|
149
|
+
if log_level:
|
150
|
+
env.append(cls._get_env_var(name=ENV_KEYS_LOG_LEVEL, value=log_level))
|
151
|
+
env += cls._get_proxy_env_vars(use_proxy_env_vars_use_in_ops)
|
152
|
+
return env
|
153
|
+
|
154
|
+
def _get_service_env_vars(
|
155
|
+
self,
|
156
|
+
service_header: str,
|
157
|
+
header: Optional[str] = PolyaxonServiceHeaders.SERVICE,
|
158
|
+
include_secret_key: bool = False,
|
159
|
+
include_internal_token: bool = False,
|
160
|
+
include_agent_token: bool = False,
|
161
|
+
authentication_type: Optional[str] = None,
|
162
|
+
external_host: bool = False,
|
163
|
+
log_level: Optional[str] = None,
|
164
|
+
polyaxon_default_secret_ref: Optional[str] = None,
|
165
|
+
polyaxon_agent_secret_ref: Optional[str] = None,
|
166
|
+
api_version: Optional[str] = None,
|
167
|
+
use_proxy_env_vars_use_in_ops: Optional[bool] = None,
|
168
|
+
) -> List[process_types.V1EnvVar]:
|
169
|
+
api_host = self.get_api_host(external_host)
|
170
|
+
polyaxon_default_secret_ref = (
|
171
|
+
polyaxon_default_secret_ref or settings.AGENT_CONFIG.app_secret_name
|
172
|
+
)
|
173
|
+
polyaxon_agent_secret_ref = (
|
174
|
+
polyaxon_agent_secret_ref or settings.AGENT_CONFIG.agent_secret_name
|
175
|
+
)
|
176
|
+
# TODO: Add support for local CLI auth
|
177
|
+
use_proxy_env_vars_use_in_ops = (
|
178
|
+
use_proxy_env_vars_use_in_ops
|
179
|
+
if use_proxy_env_vars_use_in_ops is not None
|
180
|
+
else settings.AGENT_CONFIG.use_proxy_env_vars_use_in_ops
|
181
|
+
)
|
182
|
+
api_version = api_version or VERSION_V1
|
183
|
+
env_vars = self._get_base_env_vars(
|
184
|
+
namespace=self.namespace,
|
185
|
+
resource_name=self.resource_name,
|
186
|
+
use_proxy_env_vars_use_in_ops=use_proxy_env_vars_use_in_ops,
|
187
|
+
) + [
|
188
|
+
self._get_env_var(name=ENV_KEYS_HOST, value=api_host),
|
189
|
+
self._get_env_var(name=ENV_KEYS_IS_MANAGED, value=True),
|
190
|
+
self._get_env_var(name=ENV_KEYS_API_VERSION, value=api_version),
|
191
|
+
self._get_run_instance_env_var(self.run_instance),
|
192
|
+
]
|
193
|
+
if log_level:
|
194
|
+
env_vars.append(self._get_env_var(name=ENV_KEYS_LOG_LEVEL, value=log_level))
|
195
|
+
if header:
|
196
|
+
env_vars.append(
|
197
|
+
self._get_env_var(
|
198
|
+
name=ENV_KEYS_HEADER,
|
199
|
+
value=PolyaxonServiceHeaders.get_header(header),
|
200
|
+
)
|
201
|
+
)
|
202
|
+
if service_header:
|
203
|
+
env_vars += to_list(
|
204
|
+
self._get_env_var(
|
205
|
+
name=ENV_KEYS_HEADER_SERVICE, value=get_enum_value(service_header)
|
206
|
+
),
|
207
|
+
)
|
208
|
+
if include_secret_key:
|
209
|
+
env_vars += to_list(
|
210
|
+
self._get_item_from_json_resource(
|
211
|
+
key=ENV_KEYS_SECRET_KEY,
|
212
|
+
resource_ref_name=polyaxon_default_secret_ref,
|
213
|
+
),
|
214
|
+
check_none=True,
|
215
|
+
)
|
216
|
+
internal = False
|
217
|
+
if include_internal_token and polyaxon_default_secret_ref:
|
218
|
+
internal = True
|
219
|
+
env_vars += to_list(
|
220
|
+
self._get_item_from_json_resource(
|
221
|
+
key=ENV_KEYS_SECRET_INTERNAL_TOKEN,
|
222
|
+
resource_ref_name=polyaxon_default_secret_ref,
|
223
|
+
),
|
224
|
+
check_none=True,
|
225
|
+
)
|
226
|
+
if include_agent_token:
|
227
|
+
if internal:
|
228
|
+
raise PolyaxonConverterError(
|
229
|
+
"A service cannot have internal token and agent token."
|
230
|
+
)
|
231
|
+
if polyaxon_agent_secret_ref:
|
232
|
+
env_vars += to_list(
|
233
|
+
self._get_item_from_json_resource(
|
234
|
+
key=ENV_KEYS_AUTH_TOKEN,
|
235
|
+
resource_ref_name=polyaxon_agent_secret_ref,
|
236
|
+
),
|
237
|
+
check_none=True,
|
238
|
+
)
|
239
|
+
elif settings.CLIENT_CONFIG.token:
|
240
|
+
env_vars += to_list(
|
241
|
+
self._get_env_var(
|
242
|
+
name=ENV_KEYS_AUTH_TOKEN, value=settings.CLIENT_CONFIG.token
|
243
|
+
),
|
244
|
+
check_none=True,
|
245
|
+
)
|
246
|
+
if authentication_type:
|
247
|
+
env_vars += to_list(
|
248
|
+
self._get_env_var(
|
249
|
+
name=ENV_KEYS_AUTHENTICATION_TYPE, value=authentication_type
|
250
|
+
),
|
251
|
+
check_none=True,
|
252
|
+
)
|
253
|
+
return env_vars
|