mlrun 1.8.0rc1__py3-none-any.whl → 1.8.0rc3__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.

Potentially problematic release.


This version of mlrun might be problematic. Click here for more details.

Files changed (83) hide show
  1. mlrun/__init__.py +5 -7
  2. mlrun/__main__.py +1 -1
  3. mlrun/artifacts/__init__.py +1 -0
  4. mlrun/artifacts/document.py +313 -0
  5. mlrun/artifacts/manager.py +2 -0
  6. mlrun/common/formatters/project.py +9 -0
  7. mlrun/common/schemas/__init__.py +4 -0
  8. mlrun/common/schemas/alert.py +31 -18
  9. mlrun/common/schemas/api_gateway.py +3 -3
  10. mlrun/common/schemas/artifact.py +7 -7
  11. mlrun/common/schemas/auth.py +6 -4
  12. mlrun/common/schemas/background_task.py +7 -7
  13. mlrun/common/schemas/client_spec.py +2 -2
  14. mlrun/common/schemas/clusterization_spec.py +2 -2
  15. mlrun/common/schemas/common.py +5 -5
  16. mlrun/common/schemas/constants.py +15 -0
  17. mlrun/common/schemas/datastore_profile.py +1 -1
  18. mlrun/common/schemas/feature_store.py +9 -9
  19. mlrun/common/schemas/frontend_spec.py +4 -4
  20. mlrun/common/schemas/function.py +10 -10
  21. mlrun/common/schemas/hub.py +1 -1
  22. mlrun/common/schemas/k8s.py +3 -3
  23. mlrun/common/schemas/memory_reports.py +3 -3
  24. mlrun/common/schemas/model_monitoring/grafana.py +1 -1
  25. mlrun/common/schemas/model_monitoring/model_endpoint_v2.py +1 -1
  26. mlrun/common/schemas/model_monitoring/model_endpoints.py +1 -1
  27. mlrun/common/schemas/notification.py +18 -3
  28. mlrun/common/schemas/object.py +1 -1
  29. mlrun/common/schemas/pagination.py +4 -4
  30. mlrun/common/schemas/partition.py +16 -1
  31. mlrun/common/schemas/pipeline.py +2 -2
  32. mlrun/common/schemas/project.py +22 -17
  33. mlrun/common/schemas/runs.py +2 -2
  34. mlrun/common/schemas/runtime_resource.py +5 -5
  35. mlrun/common/schemas/schedule.py +1 -1
  36. mlrun/common/schemas/secret.py +1 -1
  37. mlrun/common/schemas/tag.py +3 -3
  38. mlrun/common/schemas/workflow.py +5 -5
  39. mlrun/config.py +23 -1
  40. mlrun/datastore/datastore_profile.py +38 -19
  41. mlrun/datastore/vectorstore.py +186 -0
  42. mlrun/db/base.py +58 -6
  43. mlrun/db/httpdb.py +267 -15
  44. mlrun/db/nopdb.py +44 -5
  45. mlrun/execution.py +47 -1
  46. mlrun/model.py +2 -2
  47. mlrun/model_monitoring/applications/results.py +2 -2
  48. mlrun/model_monitoring/db/tsdb/base.py +2 -2
  49. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +37 -13
  50. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +32 -40
  51. mlrun/model_monitoring/helpers.py +4 -10
  52. mlrun/model_monitoring/stream_processing.py +14 -11
  53. mlrun/platforms/__init__.py +44 -13
  54. mlrun/projects/__init__.py +6 -1
  55. mlrun/projects/pipelines.py +184 -55
  56. mlrun/projects/project.py +309 -33
  57. mlrun/run.py +4 -1
  58. mlrun/runtimes/base.py +2 -1
  59. mlrun/runtimes/mounts.py +572 -0
  60. mlrun/runtimes/nuclio/function.py +1 -2
  61. mlrun/runtimes/pod.py +82 -18
  62. mlrun/runtimes/remotesparkjob.py +1 -1
  63. mlrun/runtimes/sparkjob/spark3job.py +1 -1
  64. mlrun/utils/clones.py +1 -1
  65. mlrun/utils/helpers.py +12 -2
  66. mlrun/utils/logger.py +2 -2
  67. mlrun/utils/notifications/notification/__init__.py +22 -19
  68. mlrun/utils/notifications/notification/base.py +12 -12
  69. mlrun/utils/notifications/notification/console.py +6 -6
  70. mlrun/utils/notifications/notification/git.py +6 -6
  71. mlrun/utils/notifications/notification/ipython.py +6 -6
  72. mlrun/utils/notifications/notification/mail.py +149 -0
  73. mlrun/utils/notifications/notification/slack.py +6 -6
  74. mlrun/utils/notifications/notification/webhook.py +6 -6
  75. mlrun/utils/notifications/notification_pusher.py +20 -12
  76. mlrun/utils/regex.py +2 -0
  77. mlrun/utils/version/version.json +2 -2
  78. {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/METADATA +190 -186
  79. {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/RECORD +83 -79
  80. {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/WHEEL +1 -1
  81. {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/LICENSE +0 -0
  82. {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/entry_points.txt +0 -0
  83. {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,572 @@
1
+ # Copyright 2023 Iguazio
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import os
16
+ import typing
17
+ from collections import namedtuple
18
+
19
+ from mlrun.config import config
20
+ from mlrun.config import config as mlconf
21
+ from mlrun.errors import MLRunInvalidArgumentError
22
+ from mlrun.platforms.iguazio import v3io_to_vol
23
+ from mlrun.utils import logger
24
+
25
+ if typing.TYPE_CHECKING:
26
+ from mlrun.runtimes import KubeResource
27
+
28
+
29
+ VolumeMount = namedtuple("Mount", ["path", "sub_path"])
30
+
31
+
32
+ def v3io_cred(
33
+ api: str = "",
34
+ user: str = "",
35
+ access_key: str = "",
36
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
37
+ """
38
+ Modifier function to copy local v3io env vars to container
39
+
40
+ Usage::
41
+
42
+ train = train_op(...)
43
+ train.apply(use_v3io_cred())
44
+ """
45
+
46
+ def _use_v3io_cred(runtime: "KubeResource"):
47
+ web_api = api or os.environ.get("V3IO_API") or mlconf.v3io_api
48
+ _user = user or os.environ.get("V3IO_USERNAME")
49
+ _access_key = access_key or os.environ.get("V3IO_ACCESS_KEY")
50
+ v3io_framesd = mlconf.v3io_framesd or os.environ.get("V3IO_FRAMESD")
51
+
52
+ runtime.set_envs(
53
+ {
54
+ "V3IO_API": web_api,
55
+ "V3IO_USERNAME": _user,
56
+ "V3IO_ACCESS_KEY": _access_key,
57
+ "V3IO_FRAMESD": v3io_framesd,
58
+ },
59
+ )
60
+
61
+ return runtime
62
+
63
+ return _use_v3io_cred
64
+
65
+
66
+ def mount_v3io(
67
+ name: str = "v3io",
68
+ remote: str = "",
69
+ access_key: str = "",
70
+ user: str = "",
71
+ secret: typing.Optional[str] = None,
72
+ volume_mounts: typing.Optional[list[VolumeMount]] = None,
73
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
74
+ """Modifier function to apply to a Container Op to volume mount a v3io path
75
+
76
+ :param name: the volume name
77
+ :param remote: the v3io path to use for the volume (~/ prefix will be replaced with /users/<username>/)
78
+ :param access_key: the access key used to auth against v3io (default: V3IO_ACCESS_KEY env var)
79
+ :param user: the username used to auth against v3io (default: V3IO_USERNAME env var)
80
+ :param secret: k8s secret name for the username and access key
81
+ :param volume_mounts: list of VolumeMount; if empty, defaults to mounting /v3io and /User
82
+ """
83
+ volume_mounts, user = _enrich_and_validate_v3io_mounts(
84
+ remote=remote,
85
+ volume_mounts=volume_mounts,
86
+ user=user,
87
+ )
88
+
89
+ def _attach_volume_mounts_and_creds(runtime: "KubeResource"):
90
+ vol = v3io_to_vol(name, remote, access_key, user, secret=secret)
91
+ runtime.spec.with_volumes(vol)
92
+
93
+ for volume_mount in volume_mounts:
94
+ runtime.spec.with_volume_mounts(
95
+ {
96
+ "mountPath": volume_mount.path,
97
+ "name": name,
98
+ "subPath": volume_mount.sub_path,
99
+ }
100
+ )
101
+
102
+ if not secret:
103
+ runtime = v3io_cred(access_key=access_key, user=user)(runtime)
104
+ return runtime
105
+
106
+ return _attach_volume_mounts_and_creds
107
+
108
+
109
+ def mount_spark_conf() -> typing.Callable[["KubeResource"], "KubeResource"]:
110
+ """Modifier function to mount Spark configuration."""
111
+
112
+ def _mount_spark(runtime: "KubeResource"):
113
+ runtime.spec.with_volume_mounts(
114
+ {
115
+ "mountPath": "/etc/config/spark",
116
+ "name": "spark-master-config",
117
+ }
118
+ )
119
+ return runtime
120
+
121
+ return _mount_spark
122
+
123
+
124
+ def mount_v3iod(
125
+ namespace: str, v3io_config_configmap: str
126
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
127
+ """Modifier function to mount v3iod configuration."""
128
+
129
+ def _mount_v3iod(runtime: "KubeResource"):
130
+ def add_vol(name, mount_path, host_path):
131
+ runtime.spec.with_volumes(
132
+ {
133
+ "name": name,
134
+ "hostPath": {
135
+ "path": host_path,
136
+ "type": "",
137
+ },
138
+ }
139
+ )
140
+ runtime.spec.with_volume_mounts(
141
+ {
142
+ "mountPath": mount_path,
143
+ "name": name,
144
+ }
145
+ )
146
+
147
+ add_vol(
148
+ name="shm",
149
+ mount_path="/dev/shm",
150
+ host_path=f"/var/run/iguazio/dayman-shm/{namespace}",
151
+ )
152
+ add_vol(
153
+ name="v3iod-comm",
154
+ mount_path="/var/run/iguazio/dayman",
155
+ host_path="/var/run/iguazio/dayman/" + namespace,
156
+ )
157
+
158
+ # Add daemon-health and v3io-config volumes
159
+ runtime.spec.with_volumes(
160
+ [
161
+ {
162
+ "name": "daemon-health",
163
+ "emptyDir": {},
164
+ },
165
+ {
166
+ "name": "v3io-config",
167
+ "configMap": {
168
+ "name": v3io_config_configmap,
169
+ "defaultMode": 420,
170
+ },
171
+ },
172
+ ]
173
+ )
174
+
175
+ # Add volume mounts
176
+ runtime.spec.with_volume_mounts(
177
+ [
178
+ {
179
+ "mountPath": "/var/run/iguazio/daemon_health",
180
+ "name": "daemon-health",
181
+ },
182
+ {
183
+ "mountPath": "/etc/config/v3io",
184
+ "name": "v3io-config",
185
+ },
186
+ ]
187
+ )
188
+
189
+ # Add environment variables
190
+ runtime.set_envs(
191
+ {
192
+ "CURRENT_NODE_IP": {
193
+ "valueFrom": {
194
+ "fieldRef": {
195
+ "apiVersion": "v1",
196
+ "fieldPath": "status.hostIP",
197
+ }
198
+ },
199
+ },
200
+ "IGZ_DATA_CONFIG_FILE": "/igz/java/conf/v3io.conf",
201
+ }
202
+ )
203
+
204
+ return runtime
205
+
206
+ return _mount_v3iod
207
+
208
+
209
+ def mount_s3(
210
+ secret_name: typing.Optional[str] = None,
211
+ aws_access_key: str = "",
212
+ aws_secret_key: str = "",
213
+ endpoint_url: typing.Optional[str] = None,
214
+ prefix: str = "",
215
+ aws_region: typing.Optional[str] = None,
216
+ non_anonymous: bool = False,
217
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
218
+ """Modifier function to add s3 env vars or secrets to container
219
+
220
+ :param secret_name: Kubernetes secret name for credentials
221
+ :param aws_access_key: AWS_ACCESS_KEY_ID value (default: env variable)
222
+ :param aws_secret_key: AWS_SECRET_ACCESS_KEY value (default: env variable)
223
+ :param endpoint_url: s3 endpoint address (for non-AWS s3)
224
+ :param prefix: prefix to add before the env var name (for multiple s3 data stores)
225
+ :param aws_region: Amazon region
226
+ :param non_anonymous: use non-anonymous connection even if no credentials are provided
227
+ (for authenticating externally, such as through IAM instance-roles)
228
+
229
+ """
230
+
231
+ if secret_name and (aws_access_key or aws_secret_key):
232
+ raise MLRunInvalidArgumentError(
233
+ "Can use k8s_secret for credentials or specify them (aws_access_key, aws_secret_key) not both."
234
+ )
235
+
236
+ if not secret_name and (
237
+ aws_access_key
238
+ or os.environ.get(prefix + "AWS_ACCESS_KEY_ID")
239
+ or aws_secret_key
240
+ or os.environ.get(prefix + "AWS_SECRET_ACCESS_KEY")
241
+ ):
242
+ logger.warning(
243
+ "It is recommended to use k8s secret (specify secret_name), "
244
+ "specifying aws_access_key/aws_secret_key directly is unsafe."
245
+ )
246
+
247
+ def _use_s3_cred(runtime: "KubeResource"):
248
+ _access_key = aws_access_key or os.environ.get(prefix + "AWS_ACCESS_KEY_ID")
249
+ _secret_key = aws_secret_key or os.environ.get(prefix + "AWS_SECRET_ACCESS_KEY")
250
+ _endpoint_url = endpoint_url or os.environ.get(prefix + "S3_ENDPOINT_URL")
251
+
252
+ if _endpoint_url:
253
+ runtime.set_env(prefix + "S3_ENDPOINT_URL", _endpoint_url)
254
+ if aws_region:
255
+ runtime.set_env(prefix + "AWS_REGION", aws_region)
256
+ if non_anonymous:
257
+ runtime.set_env(prefix + "S3_NON_ANONYMOUS", "true")
258
+
259
+ if secret_name:
260
+ runtime.set_envs(
261
+ {
262
+ f"{prefix}AWS_ACCESS_KEY_ID": {
263
+ "valueFrom": {
264
+ "secretKeyRef": {
265
+ "name": secret_name,
266
+ "key": "AWS_ACCESS_KEY_ID",
267
+ }
268
+ }
269
+ },
270
+ f"{prefix}AWS_SECRET_ACCESS_KEY": {
271
+ "valueFrom": {
272
+ "secretKeyRef": {
273
+ "name": secret_name,
274
+ "key": "AWS_SECRET_ACCESS_KEY",
275
+ }
276
+ },
277
+ },
278
+ }
279
+ )
280
+ else:
281
+ runtime.set_envs(
282
+ {
283
+ f"{prefix}AWS_ACCESS_KEY_ID": _access_key,
284
+ f"{prefix}AWS_SECRET_ACCESS_KEY": _secret_key,
285
+ },
286
+ )
287
+
288
+ return runtime
289
+
290
+ return _use_s3_cred
291
+
292
+
293
+ def mount_pvc(
294
+ pvc_name: typing.Optional[str] = None,
295
+ volume_name: str = "pipeline",
296
+ volume_mount_path: str = "/mnt/pipeline",
297
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
298
+ """
299
+ Modifier function to mount a PVC volume in the container, simplifying volume and volume mount addition.
300
+
301
+ Usage::
302
+
303
+ train = train_op(...)
304
+ train.apply(mount_pvc("claim-name", "pipeline", "/mnt/pipeline"))
305
+ """
306
+ if not pvc_name:
307
+ # Try to get the PVC mount configuration from the environment variable
308
+ if "MLRUN_PVC_MOUNT" in os.environ:
309
+ mount = os.environ.get("MLRUN_PVC_MOUNT")
310
+ items = mount.split(":")
311
+ if len(items) != 2:
312
+ raise MLRunInvalidArgumentError(
313
+ "MLRUN_PVC_MOUNT should include <pvc-name>:<mount-path>"
314
+ )
315
+ pvc_name = items[0]
316
+ volume_mount_path = items[1]
317
+
318
+ if not pvc_name:
319
+ # The PVC name is still not set, raise an error
320
+ raise MLRunInvalidArgumentError(
321
+ "No PVC name: use the pvc_name parameter or configure the MLRUN_PVC_MOUNT environment variable"
322
+ )
323
+
324
+ def _mount_pvc(runtime: "KubeResource"):
325
+ local_pvc = {"claimName": pvc_name}
326
+
327
+ runtime.spec.with_volumes(
328
+ [
329
+ {
330
+ "name": volume_name,
331
+ "persistentVolumeClaim": local_pvc,
332
+ }
333
+ ]
334
+ )
335
+ runtime.spec.with_volume_mounts(
336
+ {
337
+ "mountPath": volume_mount_path,
338
+ "name": volume_name,
339
+ }
340
+ )
341
+
342
+ return runtime
343
+
344
+ return _mount_pvc
345
+
346
+
347
+ def auto_mount(
348
+ pvc_name: str = "",
349
+ volume_mount_path: str = "",
350
+ volume_name: typing.Optional[str] = None,
351
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
352
+ """Choose the mount based on env variables and params
353
+
354
+ Volume will be selected by the following order:
355
+ - k8s PVC volume when both pvc_name and volume_mount_path are set
356
+ - k8s PVC volume when env var is set: MLRUN_PVC_MOUNT=<pvc-name>:<mount-path>
357
+ - k8s PVC volume if it's configured as the auto mount type
358
+ - iguazio v3io volume when V3IO_ACCESS_KEY and V3IO_USERNAME env vars are set
359
+ """
360
+ if pvc_name and volume_mount_path:
361
+ return mount_pvc(
362
+ pvc_name=pvc_name,
363
+ volume_mount_path=volume_mount_path,
364
+ volume_name=volume_name or "shared-persistency",
365
+ )
366
+ if "MLRUN_PVC_MOUNT" in os.environ:
367
+ return mount_pvc(
368
+ volume_name=volume_name or "shared-persistency",
369
+ )
370
+ # In the case of CE when working remotely, no env variables will be defined but auto-mount
371
+ # parameters may still be declared - use them in that case.
372
+ if config.storage.auto_mount_type == "pvc":
373
+ return mount_pvc(**config.get_storage_auto_mount_params())
374
+ if "V3IO_ACCESS_KEY" in os.environ:
375
+ return mount_v3io(name=volume_name or "v3io")
376
+
377
+ raise ValueError("Failed to auto mount, need to set env vars")
378
+
379
+
380
+ def mount_secret(
381
+ secret_name: str,
382
+ mount_path: str,
383
+ volume_name: str = "secret",
384
+ items: typing.Optional[list[dict]] = None,
385
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
386
+ """
387
+ Modifier function to mount a Kubernetes secret as file(s).
388
+
389
+ :param secret_name: Kubernetes secret name
390
+ :param mount_path: Path inside the container to mount
391
+ :param volume_name: Unique volume name
392
+ :param items: If unspecified, each key-value pair in the Data field
393
+ of the referenced Secret will be projected into the
394
+ volume as a file whose name is the key and content is
395
+ the value.
396
+ If specified, the listed keys will be projected into
397
+ the specified paths, and unlisted keys will not be
398
+ present."""
399
+
400
+ def _mount_secret(runtime: "KubeResource"):
401
+ # Define the secret volume source
402
+ secret_volume_source = {
403
+ "secretName": secret_name,
404
+ "items": items,
405
+ }
406
+
407
+ # Add the secret volume
408
+ runtime.spec.with_volumes(
409
+ {
410
+ "name": volume_name,
411
+ "secret": secret_volume_source,
412
+ }
413
+ )
414
+
415
+ # Add the volume mount
416
+ runtime.spec.with_volume_mounts(
417
+ {
418
+ "mountPath": mount_path,
419
+ "name": volume_name,
420
+ }
421
+ )
422
+
423
+ return runtime
424
+
425
+ return _mount_secret
426
+
427
+
428
+ def mount_configmap(
429
+ configmap_name: str,
430
+ mount_path: str,
431
+ volume_name: str = "configmap",
432
+ items: typing.Optional[list[dict]] = None,
433
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
434
+ """
435
+ Modifier function to mount a Kubernetes ConfigMap as file(s).
436
+
437
+ :param configmap_name: Kubernetes ConfigMap name
438
+ :param mount_path: Path inside the container to mount
439
+ :param volume_name: Unique volume name
440
+ :param items: If unspecified, each key-value pair in the Data field
441
+ of the referenced Configmap will be projected into the
442
+ volume as a file whose name is the key and content is
443
+ the value.
444
+ If specified, the listed keys will be projected into
445
+ the specified paths, and unlisted keys will not be
446
+ present."""
447
+
448
+ def _mount_configmap(runtime: "KubeResource"):
449
+ # Construct the configMap dictionary
450
+ config_map_dict = {
451
+ "name": configmap_name,
452
+ }
453
+ if items is not None:
454
+ config_map_dict["items"] = items
455
+
456
+ vol = {
457
+ "name": volume_name,
458
+ "configMap": config_map_dict,
459
+ }
460
+
461
+ runtime.spec.with_volumes(vol)
462
+ runtime.spec.with_volume_mounts(
463
+ {
464
+ "mountPath": mount_path,
465
+ "name": volume_name,
466
+ }
467
+ )
468
+
469
+ return runtime
470
+
471
+ return _mount_configmap
472
+
473
+
474
+ def mount_hostpath(
475
+ host_path: str,
476
+ mount_path: str,
477
+ volume_name: str = "hostpath",
478
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
479
+ """
480
+ Modifier function to mount a host path inside a Kubernetes container.
481
+
482
+ :param host_path: Host path on the node to be mounted.
483
+ :param mount_path: Path inside the container where the volume will be mounted.
484
+ :param volume_name: Unique name for the volume.
485
+ """
486
+
487
+ def _mount_hostpath(runtime: "KubeResource") -> "KubeResource":
488
+ runtime.spec.with_volumes(
489
+ {
490
+ "name": volume_name,
491
+ "hostPath": {
492
+ "path": host_path,
493
+ "type": "",
494
+ },
495
+ }
496
+ )
497
+ runtime.spec.with_volume_mounts(
498
+ {
499
+ "mountPath": mount_path,
500
+ "name": volume_name,
501
+ }
502
+ )
503
+
504
+ return runtime
505
+
506
+ return _mount_hostpath
507
+
508
+
509
+ def set_env_variables(
510
+ env_vars_dict: typing.Optional[dict[str, str]] = None, **kwargs
511
+ ) -> typing.Callable[["KubeResource"], "KubeResource"]:
512
+ """
513
+ Modifier function to apply a set of environment variables to a runtime. Variables may be passed
514
+ as either a dictionary of name-value pairs, or as arguments to the function.
515
+ See `KubeResource.apply` for more information on modifiers.
516
+
517
+ Usage::
518
+
519
+ function.apply(set_env_variables({"ENV1": "value1", "ENV2": "value2"}))
520
+ or
521
+ function.apply(set_env_variables(ENV1=value1, ENV2=value2))
522
+
523
+ :param env_vars_dict: dictionary of environment variables
524
+ :param kwargs: environment variables passed as arguments
525
+ """
526
+
527
+ env_data = env_vars_dict.copy() if env_vars_dict else {}
528
+ for key, value in kwargs.items():
529
+ env_data[key] = value
530
+
531
+ def _set_env_variables(runtime: "KubeResource"):
532
+ runtime.set_envs(env_data)
533
+
534
+ return runtime
535
+
536
+ return _set_env_variables
537
+
538
+
539
+ def _enrich_and_validate_v3io_mounts(
540
+ remote: str = "",
541
+ volume_mounts: typing.Optional[list[VolumeMount]] = None,
542
+ user: str = "",
543
+ ) -> tuple[list[VolumeMount], str]:
544
+ if volume_mounts is None:
545
+ volume_mounts = []
546
+ if remote and not volume_mounts:
547
+ raise MLRunInvalidArgumentError(
548
+ "volume_mounts must be specified when remote is given"
549
+ )
550
+
551
+ # Empty remote & volume_mounts defaults are volume mounts of /v3io and /User
552
+ if not remote and not volume_mounts:
553
+ user = _resolve_mount_user(user)
554
+ if not user:
555
+ raise MLRunInvalidArgumentError(
556
+ "user name/env must be specified when using empty remote and volume_mounts"
557
+ )
558
+ volume_mounts = [
559
+ VolumeMount(path="/v3io", sub_path=""),
560
+ VolumeMount(path="/User", sub_path="users/" + user),
561
+ ]
562
+
563
+ if not isinstance(volume_mounts, list) and any(
564
+ [not isinstance(x, VolumeMount) for x in volume_mounts]
565
+ ):
566
+ raise TypeError("mounts should be a list of Mount")
567
+
568
+ return volume_mounts, user
569
+
570
+
571
+ def _resolve_mount_user(user: typing.Optional[str] = None):
572
+ return user or os.environ.get("V3IO_USERNAME")
@@ -44,12 +44,11 @@ from mlrun.platforms.iguazio import (
44
44
  split_path,
45
45
  )
46
46
  from mlrun.runtimes.base import FunctionStatus, RunError
47
+ from mlrun.runtimes.mounts import VolumeMount, mount_v3io, v3io_cred
47
48
  from mlrun.runtimes.pod import KubeResource, KubeResourceSpec
48
49
  from mlrun.runtimes.utils import get_item_name, log_std
49
50
  from mlrun.utils import get_in, logger, update_in
50
- from mlrun_pipelines.common.mounts import VolumeMount
51
51
  from mlrun_pipelines.common.ops import deploy_op
52
- from mlrun_pipelines.mounts import mount_v3io, v3io_cred
53
52
 
54
53
 
55
54
  def validate_nuclio_version_compatibility(*min_versions):