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
polyaxon/_k8s/manager/manager.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Optional
|
1
|
+
from typing import List, Optional
|
2
2
|
|
3
3
|
from kubernetes import client, config
|
4
4
|
from kubernetes.client import Configuration
|
@@ -36,7 +36,7 @@ class K8sManager(BaseK8sManager):
|
|
36
36
|
await config.load_kube_config()
|
37
37
|
return Configuration.get_default_copy()
|
38
38
|
|
39
|
-
def get_version(self, reraise=False):
|
39
|
+
def get_version(self, reraise: bool = False):
|
40
40
|
try:
|
41
41
|
return self.k8s_version_api.get_code().to_dict()
|
42
42
|
except ApiException as e:
|
@@ -44,9 +44,11 @@ class K8sManager(BaseK8sManager):
|
|
44
44
|
if reraise:
|
45
45
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
46
46
|
|
47
|
-
def _list_namespace_resource(
|
47
|
+
def _list_namespace_resource(
|
48
|
+
self, resource_api, reraise: bool = False, namespace: str = None, **kwargs
|
49
|
+
):
|
48
50
|
try:
|
49
|
-
res = resource_api(namespace=self.namespace, **kwargs)
|
51
|
+
res = resource_api(namespace=namespace or self.namespace, **kwargs)
|
50
52
|
if isinstance(res, dict):
|
51
53
|
items = res["items"]
|
52
54
|
else:
|
@@ -58,7 +60,7 @@ class K8sManager(BaseK8sManager):
|
|
58
60
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
59
61
|
return []
|
60
62
|
|
61
|
-
def list_nodes(self, reraise=False):
|
63
|
+
def list_nodes(self, reraise: bool = False):
|
62
64
|
try:
|
63
65
|
res = self.k8s_api.list_node()
|
64
66
|
return [p for p in res.items]
|
@@ -68,53 +70,84 @@ class K8sManager(BaseK8sManager):
|
|
68
70
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
69
71
|
return []
|
70
72
|
|
71
|
-
def list_pods(
|
73
|
+
def list_pods(
|
74
|
+
self,
|
75
|
+
include_uninitialized=True,
|
76
|
+
reraise: bool = False,
|
77
|
+
namespace: str = None,
|
78
|
+
**kwargs
|
79
|
+
):
|
72
80
|
return self._list_namespace_resource(
|
73
81
|
resource_api=self.k8s_api.list_namespaced_pod,
|
74
82
|
reraise=reraise,
|
83
|
+
namespace=namespace,
|
75
84
|
**kwargs,
|
76
85
|
)
|
77
86
|
|
78
|
-
def list_jobs(
|
87
|
+
def list_jobs(
|
88
|
+
self,
|
89
|
+
include_uninitialized=True,
|
90
|
+
reraise: bool = False,
|
91
|
+
namespace: str = None,
|
92
|
+
**kwargs
|
93
|
+
):
|
79
94
|
return self._list_namespace_resource(
|
80
95
|
resource_api=self.k8s_batch_api.list_namespaced_job,
|
81
96
|
reraise=reraise,
|
97
|
+
namespace=namespace,
|
82
98
|
**kwargs,
|
83
99
|
)
|
84
100
|
|
85
|
-
def list_custom_objects(
|
101
|
+
def list_custom_objects(
|
102
|
+
self,
|
103
|
+
group,
|
104
|
+
version,
|
105
|
+
plural,
|
106
|
+
reraise: bool = False,
|
107
|
+
namespace: str = None,
|
108
|
+
**kwargs
|
109
|
+
):
|
86
110
|
return self._list_namespace_resource(
|
87
111
|
resource_api=self.k8s_custom_object_api.list_namespaced_custom_object,
|
88
112
|
reraise=reraise,
|
89
113
|
group=group,
|
90
114
|
version=version,
|
91
115
|
plural=plural,
|
116
|
+
namespace=namespace,
|
92
117
|
**kwargs,
|
93
118
|
)
|
94
119
|
|
95
|
-
def list_services(self, reraise=False, **kwargs):
|
120
|
+
def list_services(self, reraise: bool = False, namespace: str = None, **kwargs):
|
96
121
|
return self._list_namespace_resource(
|
97
122
|
resource_api=self.k8s_api.list_namespaced_service,
|
98
123
|
reraise=reraise,
|
124
|
+
namespace=namespace,
|
99
125
|
**kwargs,
|
100
126
|
)
|
101
127
|
|
102
|
-
def list_deployments(self, reraise=False, **kwargs):
|
128
|
+
def list_deployments(self, reraise: bool = False, namespace: str = None, **kwargs):
|
103
129
|
return self._list_namespace_resource(
|
104
130
|
resource_api=self.k8s_apps_api.list_namespaced_deployment,
|
105
131
|
reraise=reraise,
|
132
|
+
namespace=namespace,
|
106
133
|
**kwargs,
|
107
134
|
)
|
108
135
|
|
109
|
-
def list_ingresses(self, reraise=False, **kwargs):
|
136
|
+
def list_ingresses(self, reraise: bool = False, namespace: str = None, **kwargs):
|
110
137
|
return self._list_namespace_resource(
|
111
138
|
resource_api=self.networking_v1_beta1_api.list_namespaced_ingress,
|
112
139
|
reraise=reraise,
|
140
|
+
namespace=namespace,
|
113
141
|
**kwargs,
|
114
142
|
)
|
115
143
|
|
116
|
-
def update_node_labels(
|
117
|
-
|
144
|
+
def update_node_labels(
|
145
|
+
self, node, labels, reraise: bool = False, namespace: str = None
|
146
|
+
):
|
147
|
+
body = {
|
148
|
+
"metadata": {"labels": labels},
|
149
|
+
"namespace": namespace or self.namespace,
|
150
|
+
}
|
118
151
|
try:
|
119
152
|
return self.k8s_api.patch_node(name=node, body=body)
|
120
153
|
except ApiException as e:
|
@@ -122,164 +155,198 @@ class K8sManager(BaseK8sManager):
|
|
122
155
|
if reraise:
|
123
156
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
124
157
|
|
125
|
-
def create_config_map(self, name, body):
|
158
|
+
def create_config_map(self, name, body, namespace: str = None):
|
126
159
|
resp = self.k8s_api.create_namespaced_config_map(
|
127
|
-
namespace=self.namespace, body=body
|
160
|
+
namespace=namespace or self.namespace, body=body
|
128
161
|
)
|
129
162
|
logger.debug("Config map `{}` was created".format(name))
|
130
163
|
return resp
|
131
164
|
|
132
|
-
def update_config_map(self, name, body):
|
165
|
+
def update_config_map(self, name, body, namespace: str = None):
|
133
166
|
resp = self.k8s_api.patch_namespaced_config_map(
|
134
|
-
name=name, namespace=self.namespace, body=body
|
167
|
+
name=name, namespace=namespace or self.namespace, body=body
|
135
168
|
)
|
136
169
|
logger.debug("Config map `{}` was patched".format(name))
|
137
170
|
return resp
|
138
171
|
|
139
|
-
def create_or_update_config_map(
|
172
|
+
def create_or_update_config_map(
|
173
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
174
|
+
):
|
140
175
|
try:
|
141
|
-
return self.create_config_map(name=name, body=body)
|
176
|
+
return self.create_config_map(name=name, body=body, namespace=namespace)
|
142
177
|
except ApiException:
|
143
178
|
try:
|
144
|
-
return self.update_config_map(name=name, body=body)
|
179
|
+
return self.update_config_map(name=name, body=body, namespace=namespace)
|
145
180
|
except ApiException as e:
|
146
181
|
if reraise:
|
147
182
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
148
183
|
else:
|
149
184
|
logger.error("K8S error: {}".format(e))
|
150
185
|
|
151
|
-
def create_secret(self, name, body):
|
186
|
+
def create_secret(self, name, body, namespace: str = None):
|
152
187
|
resp = self.k8s_api.create_namespaced_secret(
|
153
|
-
namespace=self.namespace, body=body
|
188
|
+
namespace=namespace or self.namespace, body=body
|
154
189
|
)
|
155
190
|
logger.debug("Secret `{}` was created".format(name))
|
156
191
|
return resp
|
157
192
|
|
158
|
-
def update_secret(self, name, body):
|
193
|
+
def update_secret(self, name, body, namespace: str = None):
|
159
194
|
resp = self.k8s_api.patch_namespaced_secret(
|
160
|
-
name=name, namespace=self.namespace, body=body
|
195
|
+
name=name, namespace=namespace or self.namespace, body=body
|
161
196
|
)
|
162
197
|
logger.debug("Secret `{}` was patched".format(name))
|
163
198
|
return resp
|
164
199
|
|
165
|
-
def create_or_update_secret(
|
200
|
+
def create_or_update_secret(
|
201
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
202
|
+
):
|
166
203
|
try:
|
167
|
-
return self.create_secret(name=name, body=body), True
|
204
|
+
return self.create_secret(name=name, body=body, namespace=namespace), True
|
168
205
|
except ApiException:
|
169
206
|
try:
|
170
|
-
return
|
207
|
+
return (
|
208
|
+
self.update_secret(name=name, body=body, namespace=namespace),
|
209
|
+
False,
|
210
|
+
)
|
171
211
|
except ApiException as e:
|
172
212
|
if reraise:
|
173
213
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
174
214
|
else:
|
175
215
|
logger.error("K8S error: {}".format(e))
|
176
216
|
|
177
|
-
def create_service(self, name, body):
|
217
|
+
def create_service(self, name, body, namespace: str = None):
|
178
218
|
resp = self.k8s_api.create_namespaced_service(
|
179
|
-
namespace=self.namespace, body=body
|
219
|
+
namespace=namespace or self.namespace, body=body
|
180
220
|
)
|
181
221
|
logger.debug("Service `{}` was created".format(name))
|
182
222
|
return resp
|
183
223
|
|
184
|
-
def update_service(self, name, body):
|
224
|
+
def update_service(self, name, body, namespace: str = None):
|
185
225
|
resp = self.k8s_api.patch_namespaced_service(
|
186
|
-
name=name, namespace=self.namespace, body=body
|
226
|
+
name=name, namespace=namespace or self.namespace, body=body
|
187
227
|
)
|
188
228
|
logger.debug("Service `{}` was patched".format(name))
|
189
229
|
return resp
|
190
230
|
|
191
|
-
def create_or_update_service(
|
231
|
+
def create_or_update_service(
|
232
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
233
|
+
):
|
192
234
|
try:
|
193
|
-
return self.create_service(name=name, body=body), True
|
235
|
+
return self.create_service(name=name, body=body, namespace=namespace), True
|
194
236
|
except ApiException:
|
195
237
|
try:
|
196
|
-
return
|
238
|
+
return (
|
239
|
+
self.update_service(name=name, body=body, namespace=namespace),
|
240
|
+
False,
|
241
|
+
)
|
197
242
|
except ApiException as e:
|
198
243
|
if reraise:
|
199
244
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
200
245
|
else:
|
201
246
|
logger.error("K8S error: {}".format(e))
|
202
247
|
|
203
|
-
def create_pod(self, name, body):
|
204
|
-
resp = self.k8s_api.create_namespaced_pod(
|
248
|
+
def create_pod(self, name, body, namespace: str = None):
|
249
|
+
resp = self.k8s_api.create_namespaced_pod(
|
250
|
+
namespace=namespace or self.namespace, body=body
|
251
|
+
)
|
205
252
|
logger.debug("Pod `{}` was created".format(name))
|
206
253
|
return resp
|
207
254
|
|
208
|
-
def update_pod(self, name, body):
|
255
|
+
def update_pod(self, name, body, namespace: str = None):
|
209
256
|
resp = self.k8s_api.patch_namespaced_pod(
|
210
|
-
name=name, namespace=self.namespace, body=body
|
257
|
+
name=name, namespace=namespace or self.namespace, body=body
|
211
258
|
)
|
212
259
|
logger.debug("Pod `{}` was patched".format(name))
|
213
260
|
return resp
|
214
261
|
|
215
|
-
def create_or_update_pod(
|
262
|
+
def create_or_update_pod(
|
263
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
264
|
+
):
|
216
265
|
try:
|
217
|
-
return self.create_pod(name=name, body=body), True
|
266
|
+
return self.create_pod(name=name, body=body, namespace=namespace), True
|
218
267
|
except ApiException:
|
219
268
|
try:
|
220
|
-
return self.update_pod(name=name, body=body), False
|
269
|
+
return self.update_pod(name=name, body=body, namespace=namespace), False
|
221
270
|
except ApiException as e:
|
222
271
|
if reraise:
|
223
272
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
224
273
|
else:
|
225
274
|
logger.error("K8S error: {}".format(e))
|
226
275
|
|
227
|
-
def create_job(self, name, body):
|
276
|
+
def create_job(self, name, body, namespace: str = None):
|
228
277
|
resp = self.k8s_batch_api.create_namespaced_job(
|
229
|
-
namespace=self.namespace, body=body
|
278
|
+
namespace=namespace or self.namespace, body=body
|
230
279
|
)
|
231
280
|
logger.debug("Job `{}` was created".format(name))
|
232
281
|
return resp
|
233
282
|
|
234
|
-
def update_job(self, name, body):
|
283
|
+
def update_job(self, name, body, namespace: str = None):
|
235
284
|
resp = self.k8s_batch_api.patch_namespaced_job(
|
236
|
-
name=name, namespace=self.namespace, body=body
|
285
|
+
name=name, namespace=namespace or self.namespace, body=body
|
237
286
|
)
|
238
287
|
logger.debug("Job `{}` was patched".format(name))
|
239
288
|
return resp
|
240
289
|
|
241
|
-
def create_or_update_job(
|
290
|
+
def create_or_update_job(
|
291
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
292
|
+
):
|
242
293
|
try:
|
243
|
-
return self.create_job(name=name, body=body), True
|
294
|
+
return self.create_job(name=name, body=body, namespace=namespace), True
|
244
295
|
except ApiException:
|
245
296
|
try:
|
246
|
-
return self.update_job(name=name, body=body), False
|
297
|
+
return self.update_job(name=name, body=body, namespace=namespace), False
|
247
298
|
except ApiException as e:
|
248
299
|
if reraise:
|
249
300
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
250
301
|
else:
|
251
302
|
logger.error("K8S error: {}".format(e))
|
252
303
|
|
253
|
-
def create_custom_object(
|
304
|
+
def create_custom_object(
|
305
|
+
self, name, group, version, plural, body, namespace: str = None
|
306
|
+
):
|
254
307
|
resp = self.k8s_custom_object_api.create_namespaced_custom_object(
|
255
308
|
group=group,
|
256
309
|
version=version,
|
257
310
|
plural=plural,
|
258
|
-
namespace=self.namespace,
|
311
|
+
namespace=namespace or self.namespace,
|
259
312
|
body=body,
|
260
313
|
)
|
261
314
|
logger.debug("Custom object `{}` was created".format(name))
|
262
315
|
return resp
|
263
316
|
|
264
|
-
def update_custom_object(
|
317
|
+
def update_custom_object(
|
318
|
+
self, name, group, version, plural, body, namespace: str = None
|
319
|
+
):
|
265
320
|
resp = self.k8s_custom_object_api.patch_namespaced_custom_object(
|
266
321
|
name=name,
|
267
322
|
group=group,
|
268
323
|
version=version,
|
269
324
|
plural=plural,
|
270
|
-
namespace=self.namespace,
|
325
|
+
namespace=namespace or self.namespace,
|
271
326
|
body=body,
|
272
327
|
)
|
273
328
|
logger.debug("Custom object `{}` was patched".format(name))
|
274
329
|
return resp
|
275
330
|
|
276
331
|
def create_or_update_custom_object(
|
277
|
-
self,
|
332
|
+
self,
|
333
|
+
name,
|
334
|
+
group,
|
335
|
+
version,
|
336
|
+
plural,
|
337
|
+
body,
|
338
|
+
reraise: bool = False,
|
339
|
+
namespace: str = None,
|
278
340
|
):
|
279
341
|
try:
|
280
342
|
return (
|
281
343
|
self.create_custom_object(
|
282
|
-
name=name,
|
344
|
+
name=name,
|
345
|
+
group=group,
|
346
|
+
version=version,
|
347
|
+
plural=plural,
|
348
|
+
body=body,
|
349
|
+
namespace=namespace,
|
283
350
|
),
|
284
351
|
True,
|
285
352
|
)
|
@@ -293,6 +360,7 @@ class K8sManager(BaseK8sManager):
|
|
293
360
|
version=version,
|
294
361
|
plural=plural,
|
295
362
|
body=body,
|
363
|
+
namespace=namespace,
|
296
364
|
),
|
297
365
|
False,
|
298
366
|
)
|
@@ -304,174 +372,206 @@ class K8sManager(BaseK8sManager):
|
|
304
372
|
else:
|
305
373
|
logger.error("K8S error: {}".format(e))
|
306
374
|
|
307
|
-
def create_deployment(self, name, body):
|
375
|
+
def create_deployment(self, name, body, namespace: str = None):
|
308
376
|
resp = self.k8s_apps_api.create_namespaced_deployment(
|
309
|
-
namespace=self.namespace, body=body
|
377
|
+
namespace=namespace or self.namespace, body=body
|
310
378
|
)
|
311
379
|
logger.debug("Deployment `{}` was created".format(name))
|
312
380
|
return resp
|
313
381
|
|
314
|
-
def update_deployment(self, name, body):
|
382
|
+
def update_deployment(self, name, body, namespace: str = None):
|
315
383
|
resp = self.k8s_apps_api.patch_namespaced_deployment(
|
316
|
-
name=name, namespace=self.namespace, body=body
|
384
|
+
name=name, namespace=namespace or self.namespace, body=body
|
317
385
|
)
|
318
386
|
logger.debug("Deployment `{}` was patched".format(name))
|
319
387
|
return resp
|
320
388
|
|
321
|
-
def create_or_update_deployment(
|
389
|
+
def create_or_update_deployment(
|
390
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
391
|
+
):
|
322
392
|
try:
|
323
|
-
return
|
393
|
+
return (
|
394
|
+
self.create_deployment(name=name, body=body, namespace=namespace),
|
395
|
+
True,
|
396
|
+
)
|
324
397
|
except ApiException:
|
325
398
|
try:
|
326
|
-
return
|
399
|
+
return (
|
400
|
+
self.update_deployment(name=name, body=body, namespace=namespace),
|
401
|
+
False,
|
402
|
+
)
|
327
403
|
except ApiException as e:
|
328
404
|
if reraise:
|
329
405
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
330
406
|
else:
|
331
407
|
logger.error("K8S error: {}".format(e))
|
332
408
|
|
333
|
-
def create_volume(self, name, body):
|
334
|
-
resp = self.k8s_api.create_persistent_volume(
|
409
|
+
def create_volume(self, name, body, namespace: str = None):
|
410
|
+
resp = self.k8s_api.create_persistent_volume(
|
411
|
+
body=body, namespace=namespace or self.namespace
|
412
|
+
)
|
335
413
|
logger.debug("Persistent volume `{}` was created".format(name))
|
336
414
|
return resp
|
337
415
|
|
338
|
-
def update_volume(self, name, body):
|
339
|
-
resp = self.k8s_api.patch_persistent_volume(
|
416
|
+
def update_volume(self, name, body, namespace: str = None):
|
417
|
+
resp = self.k8s_api.patch_persistent_volume(
|
418
|
+
name=name, body=body, namespace=namespace or self.namespace
|
419
|
+
)
|
340
420
|
logger.debug("Persistent volume `{}` was patched".format(name))
|
341
421
|
return resp
|
342
422
|
|
343
|
-
def create_or_update_volume(
|
423
|
+
def create_or_update_volume(
|
424
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
425
|
+
):
|
344
426
|
try:
|
345
|
-
return self.create_volume(name=name, body=body), True
|
427
|
+
return self.create_volume(name=name, body=body, namespace=namespace), True
|
346
428
|
except ApiException:
|
347
429
|
try:
|
348
|
-
return
|
430
|
+
return (
|
431
|
+
self.update_service(name=name, body=body, namespace=namespace),
|
432
|
+
False,
|
433
|
+
)
|
349
434
|
except ApiException as e:
|
350
435
|
if reraise:
|
351
436
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
352
437
|
else:
|
353
438
|
logger.error("K8S error: {}".format(e))
|
354
439
|
|
355
|
-
def create_volume_claim(self, name, body):
|
440
|
+
def create_volume_claim(self, name, body, namespace: str = None):
|
356
441
|
resp = self.k8s_api.create_namespaced_persistent_volume_claim(
|
357
|
-
namespace=self.namespace, body=body
|
442
|
+
namespace=namespace or self.namespace, body=body
|
358
443
|
)
|
359
444
|
logger.debug("Volume claim `{}` was created".format(name))
|
360
445
|
return resp
|
361
446
|
|
362
|
-
def update_volume_claim(self, name, body):
|
447
|
+
def update_volume_claim(self, name, body, namespace: str = None):
|
363
448
|
resp = self.k8s_api.patch_namespaced_persistent_volume_claim(
|
364
|
-
name=name, namespace=self.namespace, body=body
|
449
|
+
name=name, namespace=namespace or self.namespace, body=body
|
365
450
|
)
|
366
451
|
logger.debug("Volume claim `{}` was patched".format(name))
|
367
452
|
return resp
|
368
453
|
|
369
|
-
def create_or_update_volume_claim(
|
454
|
+
def create_or_update_volume_claim(
|
455
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
456
|
+
):
|
370
457
|
try:
|
371
|
-
return
|
458
|
+
return (
|
459
|
+
self.create_volume_claim(name=name, body=body, namespace=namespace),
|
460
|
+
True,
|
461
|
+
)
|
372
462
|
except ApiException:
|
373
463
|
try:
|
374
|
-
return
|
464
|
+
return (
|
465
|
+
self.update_volume_claim(name=name, body=body, namespace=namespace),
|
466
|
+
False,
|
467
|
+
)
|
375
468
|
except ApiException as e:
|
376
469
|
if reraise:
|
377
470
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
378
471
|
else:
|
379
472
|
logger.error("K8S error: {}".format(e))
|
380
473
|
|
381
|
-
def create_ingress(self, name, body):
|
474
|
+
def create_ingress(self, name, body, namespace: str = None):
|
382
475
|
resp = self.networking_v1_beta1_api.create_namespaced_ingress(
|
383
|
-
namespace=self.namespace, body=body
|
476
|
+
namespace=namespace or self.namespace, body=body
|
384
477
|
)
|
385
478
|
logger.debug("ingress `{}` was created".format(name))
|
386
479
|
return resp
|
387
480
|
|
388
|
-
def update_ingress(self, name, body):
|
481
|
+
def update_ingress(self, name, body, namespace: str = None):
|
389
482
|
resp = self.networking_v1_beta1_api.patch_namespaced_ingress(
|
390
|
-
name=name, namespace=self.namespace, body=body
|
483
|
+
name=name, namespace=namespace or self.namespace, body=body
|
391
484
|
)
|
392
485
|
logger.debug("Ingress `{}` was patched".format(name))
|
393
486
|
return resp
|
394
487
|
|
395
|
-
def create_or_update_ingress(
|
488
|
+
def create_or_update_ingress(
|
489
|
+
self, name, body, reraise: bool = False, namespace: str = None
|
490
|
+
):
|
396
491
|
try:
|
397
|
-
return self.create_ingress(name=name, body=body), True
|
492
|
+
return self.create_ingress(name=name, body=body, namespace=namespace), True
|
398
493
|
except ApiException:
|
399
494
|
try:
|
400
|
-
return
|
495
|
+
return (
|
496
|
+
self.update_ingress(name=name, body=body, namespace=namespace),
|
497
|
+
False,
|
498
|
+
)
|
401
499
|
except ApiException as e:
|
402
500
|
if reraise:
|
403
501
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
404
502
|
else:
|
405
503
|
logger.error("K8S error: {}".format(e))
|
406
504
|
|
407
|
-
def get_config_map(self, name, reraise=False):
|
505
|
+
def get_config_map(self, name, reraise: bool = False, namespace: str = None):
|
408
506
|
try:
|
409
507
|
return self.k8s_api.read_namespaced_config_map(
|
410
|
-
name=name, namespace=self.namespace
|
508
|
+
name=name, namespace=namespace or self.namespace
|
411
509
|
)
|
412
510
|
except ApiException as e:
|
413
511
|
if reraise:
|
414
512
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
415
513
|
return None
|
416
514
|
|
417
|
-
def get_secret(self, name, reraise=False):
|
515
|
+
def get_secret(self, name, reraise: bool = False, namespace: str = None):
|
418
516
|
try:
|
419
517
|
return self.k8s_api.read_namespaced_secret(
|
420
|
-
name=name, namespace=self.namespace
|
518
|
+
name=name, namespace=namespace or self.namespace
|
421
519
|
)
|
422
520
|
except ApiException as e:
|
423
521
|
if reraise:
|
424
522
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
425
523
|
return None
|
426
524
|
|
427
|
-
def get_service(self, name, reraise=False):
|
525
|
+
def get_service(self, name, reraise: bool = False, namespace: str = None):
|
428
526
|
try:
|
429
527
|
return self.k8s_api.read_namespaced_service(
|
430
|
-
name=name, namespace=self.namespace
|
528
|
+
name=name, namespace=namespace or self.namespace
|
431
529
|
)
|
432
530
|
except ApiException as e:
|
433
531
|
if reraise:
|
434
532
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
435
533
|
return None
|
436
534
|
|
437
|
-
def get_pod(self, name, reraise=False):
|
535
|
+
def get_pod(self, name, reraise: bool = False, namespace: str = None):
|
438
536
|
try:
|
439
|
-
return self.k8s_api.read_namespaced_pod(
|
537
|
+
return self.k8s_api.read_namespaced_pod(
|
538
|
+
name=name, namespace=namespace or self.namespace
|
539
|
+
)
|
440
540
|
except ApiException as e:
|
441
541
|
if reraise:
|
442
542
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
443
543
|
return None
|
444
544
|
|
445
|
-
def get_job(self, name, reraise=False):
|
545
|
+
def get_job(self, name, reraise: bool = False, namespace: str = None):
|
446
546
|
try:
|
447
547
|
return self.k8s_batch_api.read_namespaced_job(
|
448
|
-
name=name, namespace=self.namespace
|
548
|
+
name=name, namespace=namespace or self.namespace
|
449
549
|
)
|
450
550
|
except ApiException as e:
|
451
551
|
if reraise:
|
452
552
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
453
553
|
return None
|
454
554
|
|
455
|
-
def get_custom_object(self, name, group, version, plural):
|
555
|
+
def get_custom_object(self, name, group, version, plural, namespace: str = None):
|
456
556
|
return self.k8s_custom_object_api.get_namespaced_custom_object(
|
457
557
|
name=name,
|
458
558
|
group=group,
|
459
559
|
version=version,
|
460
560
|
plural=plural,
|
461
|
-
namespace=self.namespace,
|
561
|
+
namespace=namespace or self.namespace,
|
462
562
|
)
|
463
563
|
|
464
|
-
def get_deployment(self, name, reraise=False):
|
564
|
+
def get_deployment(self, name, reraise: bool = False, namespace: str = None):
|
465
565
|
try:
|
466
566
|
return self.k8s_apps_api.read_namespaced_deployment(
|
467
|
-
name=name, namespace=self.namespace
|
567
|
+
name=name, namespace=namespace or self.namespace
|
468
568
|
)
|
469
569
|
except ApiException as e:
|
470
570
|
if reraise:
|
471
571
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
472
572
|
return None
|
473
573
|
|
474
|
-
def get_volume(self, name, reraise=False):
|
574
|
+
def get_volume(self, name, reraise: bool = False):
|
475
575
|
try:
|
476
576
|
return self.k8s_api.read_persistent_volume(name=name)
|
477
577
|
except ApiException as e:
|
@@ -479,31 +579,31 @@ class K8sManager(BaseK8sManager):
|
|
479
579
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
480
580
|
return None
|
481
581
|
|
482
|
-
def get_volume_claim(self, name, reraise=False):
|
582
|
+
def get_volume_claim(self, name, reraise: bool = False, namespace: str = None):
|
483
583
|
try:
|
484
584
|
return self.k8s_api.read_namespaced_persistent_volume_claim(
|
485
|
-
name=name, namespace=self.namespace
|
585
|
+
name=name, namespace=namespace or self.namespace
|
486
586
|
)
|
487
587
|
except ApiException as e:
|
488
588
|
if reraise:
|
489
589
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
490
590
|
return None
|
491
591
|
|
492
|
-
def get_ingress(self, name, reraise=False):
|
592
|
+
def get_ingress(self, name, reraise: bool = False, namespace: str = None):
|
493
593
|
try:
|
494
594
|
return self.networking_v1_beta1_api.read_namespaced_ingress(
|
495
|
-
name=name, namespace=self.namespace
|
595
|
+
name=name, namespace=namespace or self.namespace
|
496
596
|
)
|
497
597
|
except ApiException as e:
|
498
598
|
if reraise:
|
499
599
|
raise PolyaxonK8sError("Connection error: %s" % e) from e
|
500
600
|
return None
|
501
601
|
|
502
|
-
def delete_config_map(self, name, reraise=False):
|
602
|
+
def delete_config_map(self, name, reraise: bool = False, namespace: str = None):
|
503
603
|
try:
|
504
604
|
self.k8s_api.delete_namespaced_config_map(
|
505
605
|
name=name,
|
506
|
-
namespace=self.namespace,
|
606
|
+
namespace=namespace or self.namespace,
|
507
607
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
508
608
|
)
|
509
609
|
logger.debug("Config map `{}` Deleted".format(name))
|
@@ -513,11 +613,11 @@ class K8sManager(BaseK8sManager):
|
|
513
613
|
else:
|
514
614
|
logger.debug("Config map `{}` was not found".format(name))
|
515
615
|
|
516
|
-
def delete_secret(self, name, reraise=False):
|
616
|
+
def delete_secret(self, name, reraise: bool = False, namespace: str = None):
|
517
617
|
try:
|
518
618
|
self.k8s_api.delete_namespaced_secret(
|
519
619
|
name=name,
|
520
|
-
namespace=self.namespace,
|
620
|
+
namespace=namespace or self.namespace,
|
521
621
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
522
622
|
)
|
523
623
|
logger.debug("secret `{}` Deleted".format(name))
|
@@ -527,11 +627,11 @@ class K8sManager(BaseK8sManager):
|
|
527
627
|
else:
|
528
628
|
logger.debug("secret `{}` was not found".format(name))
|
529
629
|
|
530
|
-
def delete_service(self, name, reraise=False):
|
630
|
+
def delete_service(self, name, reraise: bool = False, namespace: str = None):
|
531
631
|
try:
|
532
632
|
self.k8s_api.delete_namespaced_service(
|
533
633
|
name=name,
|
534
|
-
namespace=self.namespace,
|
634
|
+
namespace=namespace or self.namespace,
|
535
635
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
536
636
|
)
|
537
637
|
logger.debug("Service `{}` deleted".format(name))
|
@@ -541,11 +641,11 @@ class K8sManager(BaseK8sManager):
|
|
541
641
|
else:
|
542
642
|
logger.debug("Service `{}` was not found".format(name))
|
543
643
|
|
544
|
-
def delete_pod(self, name, reraise=False):
|
644
|
+
def delete_pod(self, name, reraise: bool = False, namespace: str = None):
|
545
645
|
try:
|
546
646
|
self.k8s_api.delete_namespaced_pod(
|
547
647
|
name=name,
|
548
|
-
namespace=self.namespace,
|
648
|
+
namespace=namespace or self.namespace,
|
549
649
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
550
650
|
)
|
551
651
|
logger.debug("Pod `{}` deleted".format(name))
|
@@ -555,11 +655,11 @@ class K8sManager(BaseK8sManager):
|
|
555
655
|
else:
|
556
656
|
logger.debug("Pod `{}` was not found".format(name))
|
557
657
|
|
558
|
-
def delete_job(self, name, reraise=False):
|
658
|
+
def delete_job(self, name, reraise: bool = False, namespace: str = None):
|
559
659
|
try:
|
560
660
|
self.k8s_batch_api.delete_namespaced_job(
|
561
661
|
name=name,
|
562
|
-
namespace=self.namespace,
|
662
|
+
namespace=namespace or self.namespace,
|
563
663
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
564
664
|
)
|
565
665
|
logger.debug("Pod `{}` deleted".format(name))
|
@@ -569,22 +669,22 @@ class K8sManager(BaseK8sManager):
|
|
569
669
|
else:
|
570
670
|
logger.debug("Pod `{}` was not found".format(name))
|
571
671
|
|
572
|
-
def delete_custom_object(self, name, group, version, plural):
|
672
|
+
def delete_custom_object(self, name, group, version, plural, namespace: str = None):
|
573
673
|
self.k8s_custom_object_api.delete_namespaced_custom_object(
|
574
674
|
name=name,
|
575
675
|
group=group,
|
576
676
|
version=version,
|
577
677
|
plural=plural,
|
578
|
-
namespace=self.namespace,
|
678
|
+
namespace=namespace or self.namespace,
|
579
679
|
body=client.V1DeleteOptions(),
|
580
680
|
)
|
581
681
|
logger.debug("Custom object `{}` deleted".format(name))
|
582
682
|
|
583
|
-
def delete_deployment(self, name, reraise=False):
|
683
|
+
def delete_deployment(self, name, reraise: bool = False, namespace: str = None):
|
584
684
|
try:
|
585
685
|
self.k8s_apps_api.delete_namespaced_deployment(
|
586
686
|
name=name,
|
587
|
-
namespace=self.namespace,
|
687
|
+
namespace=namespace or self.namespace,
|
588
688
|
body=client.V1DeleteOptions(
|
589
689
|
api_version=constants.K8S_API_VERSION_APPS_V1,
|
590
690
|
propagation_policy="Foreground",
|
@@ -597,11 +697,12 @@ class K8sManager(BaseK8sManager):
|
|
597
697
|
else:
|
598
698
|
logger.debug("Deployment `{}` was not found".format(name))
|
599
699
|
|
600
|
-
def delete_volume(self, name, reraise=False):
|
700
|
+
def delete_volume(self, name, reraise: bool = False, namespace: str = None):
|
601
701
|
try:
|
602
702
|
self.k8s_api.delete_persistent_volume(
|
603
703
|
name=name,
|
604
704
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
705
|
+
namespace=namespace or self.namespace,
|
605
706
|
)
|
606
707
|
logger.debug("Volume `{}` Deleted".format(name))
|
607
708
|
except ApiException as e:
|
@@ -610,11 +711,11 @@ class K8sManager(BaseK8sManager):
|
|
610
711
|
else:
|
611
712
|
logger.debug("Volume `{}` was not found".format(name))
|
612
713
|
|
613
|
-
def delete_volume_claim(self, name, reraise=False):
|
714
|
+
def delete_volume_claim(self, name, reraise: bool = False, namespace: str = None):
|
614
715
|
try:
|
615
716
|
self.k8s_api.delete_namespaced_persistent_volume_claim(
|
616
717
|
name=name,
|
617
|
-
namespace=self.namespace,
|
718
|
+
namespace=namespace or self.namespace,
|
618
719
|
body=client.V1DeleteOptions(api_version=constants.K8S_API_VERSION_V1),
|
619
720
|
)
|
620
721
|
logger.debug("Volume claim `{}` Deleted".format(name))
|
@@ -624,11 +725,11 @@ class K8sManager(BaseK8sManager):
|
|
624
725
|
else:
|
625
726
|
logger.debug("Volume claim `{}` was not found".format(name))
|
626
727
|
|
627
|
-
def delete_ingress(self, name, reraise=False):
|
728
|
+
def delete_ingress(self, name, reraise: bool = False, namespace: str = None):
|
628
729
|
try:
|
629
730
|
self.networking_v1_beta1_api.delete_namespaced_ingress(
|
630
731
|
name=name,
|
631
|
-
namespace=self.namespace,
|
732
|
+
namespace=namespace or self.namespace,
|
632
733
|
body=client.V1DeleteOptions(
|
633
734
|
api_version=constants.K8S_API_VERSION_NETWORKING_V1_BETA1,
|
634
735
|
propagation_policy="Foreground",
|
@@ -641,35 +742,82 @@ class K8sManager(BaseK8sManager):
|
|
641
742
|
else:
|
642
743
|
logger.debug("Ingress `{}` was not found".format(name))
|
643
744
|
|
644
|
-
def delete_pods(
|
745
|
+
def delete_pods(
|
746
|
+
self,
|
747
|
+
include_uninitialized=True,
|
748
|
+
reraise: bool = False,
|
749
|
+
namespace: str = None,
|
750
|
+
**kwargs
|
751
|
+
):
|
645
752
|
objs = self.list_pods(
|
646
|
-
include_uninitialized=include_uninitialized,
|
753
|
+
include_uninitialized=include_uninitialized,
|
754
|
+
reraise=reraise,
|
755
|
+
namespace=namespace,
|
756
|
+
**kwargs,
|
647
757
|
)
|
648
758
|
for obj in objs:
|
649
|
-
self.delete_pod(
|
759
|
+
self.delete_pod(
|
760
|
+
name=obj.metadata.name, reraise=reraise, namespace=namespace
|
761
|
+
)
|
650
762
|
|
651
|
-
def delete_jobs(
|
763
|
+
def delete_jobs(
|
764
|
+
self,
|
765
|
+
include_uninitialized=True,
|
766
|
+
reraise: bool = False,
|
767
|
+
namespace: str = None,
|
768
|
+
**kwargs
|
769
|
+
):
|
652
770
|
objs = self.list_jobs(
|
653
|
-
include_uninitialized=include_uninitialized,
|
771
|
+
include_uninitialized=include_uninitialized,
|
772
|
+
reraise=reraise,
|
773
|
+
namespace=namespace,
|
774
|
+
**kwargs,
|
654
775
|
)
|
655
776
|
for obj in objs:
|
656
|
-
self.delete_job(
|
777
|
+
self.delete_job(
|
778
|
+
name=obj.metadata.name, reraise=reraise, namespace=namespace
|
779
|
+
)
|
657
780
|
|
658
|
-
def delete_services(self, reraise=False, **kwargs):
|
781
|
+
def delete_services(self, reraise: bool = False, namespace: str = None, **kwargs):
|
659
782
|
objs = self.list_services(reraise=reraise, **kwargs)
|
660
783
|
for obj in objs:
|
661
|
-
self.delete_service(
|
784
|
+
self.delete_service(
|
785
|
+
name=obj.metadata.name, reraise=reraise, namespace=namespace
|
786
|
+
)
|
662
787
|
|
663
|
-
def delete_deployments(
|
788
|
+
def delete_deployments(
|
789
|
+
self, reraise: bool = False, namespace: str = None, **kwargs
|
790
|
+
):
|
664
791
|
objs = self.list_deployments(reraise=reraise, **kwargs)
|
665
792
|
for obj in objs:
|
666
|
-
self.delete_deployment(
|
793
|
+
self.delete_deployment(
|
794
|
+
name=obj.metadata.name, reraise=reraise, namespace=namespace
|
795
|
+
)
|
667
796
|
|
668
|
-
def delete_ingresses(self, reraise=False, **kwargs):
|
797
|
+
def delete_ingresses(self, reraise: bool = False, namespace: str = None, **kwargs):
|
669
798
|
objs = self.list_services(reraise=reraise, **kwargs)
|
670
799
|
for obj in objs:
|
671
|
-
self.delete_ingress(
|
800
|
+
self.delete_ingress(
|
801
|
+
name=obj.metadata.name, reraise=reraise, namespace=namespace
|
802
|
+
)
|
672
803
|
|
673
|
-
def is_pod_running(self, pod_id: str, container_id: str):
|
674
|
-
event = self.k8s_api.read_namespaced_pod_status(
|
804
|
+
def is_pod_running(self, pod_id: str, container_id: str, namespace: str = None):
|
805
|
+
event = self.k8s_api.read_namespaced_pod_status(
|
806
|
+
pod_id, namespace=namespace or self.namespace
|
807
|
+
)
|
675
808
|
return is_pod_running(event, container_id)
|
809
|
+
|
810
|
+
def list_namespaced_events(
|
811
|
+
self,
|
812
|
+
field_selector: str = None,
|
813
|
+
namespace: str = None,
|
814
|
+
reraise: bool = False,
|
815
|
+
**kwargs
|
816
|
+
) -> List[client.CoreV1EventList]:
|
817
|
+
return self._list_namespace_resource(
|
818
|
+
resource_api=self.k8s_api.list_namespaced_event, # type: ignore[attr-defined]
|
819
|
+
reraise=reraise,
|
820
|
+
namespace=namespace,
|
821
|
+
field_selector=field_selector,
|
822
|
+
**kwargs,
|
823
|
+
)
|