class DeploymentApplyError(RuntimeError):
+ | class DeploymentApplyError(RuntimeError):
"""
Raised when an error occurs while applying a deployment.
"""
@@ -7320,12 +7320,7 @@
Source code in prefect/deployments/runner.py
- 630
-631
-632
-633
-634
-635
+ 635
636
637
638
@@ -7373,7 +7368,19 @@
680
681
682
-683 | class DeploymentImage:
+683
+684
+685
+686
+687
+688
+689
+690
+691
+692
+693
+694
+695
| class DeploymentImage:
"""
Configuration used to build and push a Docker image for a deployment.
@@ -7396,7 +7403,14 @@
f"Only one tag can be provided - both {image_tag!r} and {tag!r} were"
" provided as tags."
)
- self.name = image_name
+ namespace, repository = split_repository_path(image_name)
+ # if the provided image name does not include a namespace (registry URL or user/org name),
+ # use the default namespace
+ if not namespace:
+ namespace = PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE.value()
+ # join the namespace and repository to create the full image name
+ # ignore namespace if it is None
+ self.name = "/".join(filter(None, [namespace, repository]))
self.tag = tag or image_tag or slugify(pendulum.now("utc").isoformat())
self.dockerfile = dockerfile
self.build_kwargs = build_kwargs
@@ -7650,12 +7664,7 @@
Source code in prefect/deployments/runner.py
- 88
- 89
- 90
- 91
- 92
- 93
+ 93
94
95
96
@@ -8189,7 +8198,12 @@
624
625
626
-627 | class RunnerDeployment(BaseModel):
+627
+628
+629
+630
+631
+632
| class RunnerDeployment(BaseModel):
"""
A Prefect RunnerDeployment definition, used for specifying and building deployments.
@@ -8837,12 +8851,7 @@
Source code in prefect/deployments/runner.py
- 202
-203
-204
-205
-206
-207
+ 207
208
209
210
@@ -8929,7 +8938,12 @@ 291
292
293
-294 | @sync_compatible
+294
+295
+296
+297
+298
+299
| @sync_compatible
async def apply(
self, work_pool_name: Optional[str] = None, image: Optional[str] = None
) -> UUID:
@@ -9285,12 +9299,7 @@
Source code in prefect/deployments/runner.py
- 455
-456
-457
-458
-459
-460
+ 460
461
462
463
@@ -9364,7 +9373,12 @@ 531
532
533
-534 | @classmethod
+534
+535
+536
+537
+538
+539
| @classmethod
def from_entrypoint(
cls,
entrypoint: str,
@@ -9706,12 +9720,7 @@
Source code in prefect/deployments/runner.py
- 350
-351
-352
-353
-354
-355
+ 355
356
357
358
@@ -9809,7 +9818,12 @@ 450
451
452
-453 | @classmethod
+453
+454
+455
+456
+457
+458
| @classmethod
def from_flow(
cls,
flow: "Flow",
@@ -10193,12 +10207,7 @@
Source code in prefect/deployments/runner.py
- 536
-537
-538
-539
-540
-541
+ 541
542
543
544
@@ -10284,7 +10293,12 @@ 624
625
626
-627 | @classmethod
+627
+628
+629
+630
+631
+632
| @classmethod
@sync_compatible
async def from_storage(
cls,
@@ -10400,14 +10414,14 @@
Source code in prefect/deployments/runner.py
- 193
-194
-195
-196
-197
-198
+ | @validator("triggers", allow_reuse=True)
+200
+201
+202
+203
+204
+205
| @validator("triggers", allow_reuse=True)
def validate_automation_names(cls, field_value, values, field, config):
"""Ensure that each trigger has a name for its automation if none is provided."""
for i, trigger in enumerate(field_value, start=1):
@@ -10611,19 +10625,7 @@
Source code in prefect/deployments/runner.py
- 686
-687
-688
-689
-690
-691
-692
-693
-694
-695
-696
-697
-698
+ 698
699
700
701
@@ -10824,7 +10826,19 @@
896
897
898
-899 | @sync_compatible
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
| @sync_compatible
async def deploy(
*deployments: RunnerDeployment,
work_pool_name: Optional[str] = None,
diff --git a/versions/unreleased/api-ref/prefect/infrastructure/index.html b/versions/unreleased/api-ref/prefect/infrastructure/index.html
index 9c0ce6b665..9ef7b1d607 100644
--- a/versions/unreleased/api-ref/prefect/infrastructure/index.html
+++ b/versions/unreleased/api-ref/prefect/infrastructure/index.html
@@ -10571,8 +10571,7 @@
Source code in prefect/infrastructure/kubernetes.py
- 60
- 61
+ 61
62
63
64
@@ -11396,7 +11395,71 @@
882
883
884
-885 | class KubernetesJob(Infrastructure):
+885
+886
+887
+888
+889
+890
+891
+892
+893
+894
+895
+896
+897
+898
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
+927
+928
+929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
| class KubernetesJob(Infrastructure):
"""
Runs a command as a Kubernetes Job.
@@ -11698,6 +11761,69 @@
def preview(self):
return yaml.dump(self.build_job())
+ def get_corresponding_worker_type(self):
+ return "kubernetes"
+
+ async def generate_work_pool_base_job_template(self):
+ from prefect.workers.utilities import (
+ get_default_base_job_template_for_infrastructure_type,
+ )
+
+ base_job_template = await get_default_base_job_template_for_infrastructure_type(
+ self.get_corresponding_worker_type()
+ )
+ assert (
+ base_job_template is not None
+ ), "Failed to retrieve default base job template."
+ for key, value in self.dict(exclude_unset=True, exclude_defaults=True).items():
+ if key == "command":
+ base_job_template["variables"]["properties"]["command"]["default"] = (
+ shlex.join(value)
+ )
+ elif key in [
+ "type",
+ "block_type_slug",
+ "_block_document_id",
+ "_block_document_name",
+ "_is_anonymous",
+ "job",
+ "customizations",
+ ]:
+ continue
+ elif key == "image_pull_policy":
+ base_job_template["variables"]["properties"]["image_pull_policy"][
+ "default"
+ ] = value.value
+ elif key == "cluster_config":
+ base_job_template["variables"]["properties"]["cluster_config"][
+ "default"
+ ] = {
+ "$ref": {
+ "block_document_id": str(self.cluster_config._block_document_id)
+ }
+ }
+ elif key in base_job_template["variables"]["properties"]:
+ base_job_template["variables"]["properties"][key]["default"] = value
+ else:
+ self.logger.warning(
+ f"Variable {key!r} is not supported by Kubernetes work pools."
+ " Skipping."
+ )
+
+ custom_job_manifest = self.dict(exclude_unset=True, exclude_defaults=True).get(
+ "job"
+ )
+ if custom_job_manifest:
+ job_manifest = self.build_job()
+ else:
+ job_manifest = copy.deepcopy(
+ base_job_template["job_configuration"]["job_manifest"]
+ )
+ job_manifest = self.customizations.apply(job_manifest)
+ base_job_template["job_configuration"]["job_manifest"] = job_manifest
+
+ return base_job_template
+
def build_job(self) -> KubernetesManifest:
"""Builds the Kubernetes Job Manifest"""
job_manifest = copy.copy(self.job)
@@ -12259,8 +12385,7 @@
Source code in prefect/infrastructure/kubernetes.py
- 252
-253
+ 253
254
255
256
@@ -12281,7 +12406,8 @@ 271
272
273
-274 | | @classmethod
def base_job_manifest(cls) -> KubernetesManifest:
"""Produces the bare minimum allowed Job manifest"""
return {
@@ -12328,12 +12454,12 @@
Source code in prefect/infrastructure/kubernetes.py
- 362
-363
-364
-365
-366
-367 | def build_job(self) -> KubernetesManifest:
+ 426
+427
+428
+429
+430
+431 | def build_job(self) -> KubernetesManifest:
"""Builds the Kubernetes Job Manifest"""
job_manifest = copy.copy(self.job)
job_manifest = self._shortcut_customizations().apply(job_manifest)
@@ -12367,11 +12493,11 @@
Source code in prefect/infrastructure/kubernetes.py
- 291
-292
+ | | @classmethod
def customize_from_file(cls, filename: str) -> JsonPatch:
"""Load an RFC 6902 JSON patch from a YAML or JSON file."""
with open(filename, "r", encoding="utf-8") as f:
@@ -12404,11 +12530,11 @@
Source code in prefect/infrastructure/kubernetes.py
- 285
-286
+ | | @classmethod
def job_from_file(cls, filename: str) -> KubernetesManifest:
"""Load a Kubernetes Job manifest from a YAML or JSON file."""
with open(filename, "r", encoding="utf-8") as f:
@@ -12448,8 +12574,8 @@
Source code in prefect/infrastructure/kubernetes.py
- | class KubernetesJobResult(InfrastructureResult):
+ | class KubernetesJobResult(InfrastructureResult):
"""Contains information about the final state of a completed Kubernetes Job"""
|
diff --git a/versions/unreleased/api-ref/prefect/settings/index.html b/versions/unreleased/api-ref/prefect/settings/index.html
index 2a8e81e45e..31d700fd89 100644
--- a/versions/unreleased/api-ref/prefect/settings/index.html
+++ b/versions/unreleased/api-ref/prefect/settings/index.html
@@ -4000,17 +4000,6 @@
-
-
-
-
-
-
- PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
-
-
-
-
@@ -4880,6 +4869,17 @@
+
+
+
+
+
+
+ PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
+
+
+
+
@@ -4891,6 +4891,17 @@
+
+
+
+
+
+
+ PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE
+
+
+
+
@@ -8879,17 +8890,6 @@
-
-
-
-
-
-
- PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
-
-
-
-
@@ -9759,6 +9759,17 @@
+
+
+
+
+
+
+ PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
+
+
+
+
@@ -9770,6 +9781,17 @@
+
+
+
+
+
+
+ PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE
+
+
+
+
@@ -11076,28 +11098,6 @@
-
- PREFECT_DEFAULT_RESULT_STORAGE_BLOCK = Setting(str, default=None)
-
-
- module-attribute
-
-
-
-
-
-
-
- The block-type/block-document slug of a block to use as the default result storage.
-
-
-
-
-
-
-
-
-
PREFECT_MEMO_STORE_PATH = Setting(Path, default=Path('${PREFECT_HOME}') / 'memo_store.toml', value_callback=template_with_settings(PREFECT_HOME))
@@ -12951,6 +12951,28 @@
+ PREFECT_DEFAULT_RESULT_STORAGE_BLOCK = Setting(str, default=None)
+
+
+ module-attribute
+
+
+
+
+
+
+
+ The block-type/block-document slug of a block to use as the default result storage.
+
+
+
+
+
+
+
+
+
PREFECT_DEFAULT_WORK_POOL_NAME = Setting(str, default=None)
@@ -12968,6 +12990,29 @@
+
+
+
+
+
+
+ PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE = Setting(str, default=None)
+
+
+ module-attribute
+
+
+
+
+
+
+
+ The default Docker namespace to use when building images.
+ Can be either an organization/username or a registry URL with an organization/username.
+
+
+
+
@@ -13486,17 +13531,7 @@
Source code in prefect/settings.py
- 1458
-1459
-1460
-1461
-1462
-1463
-1464
-1465
-1466
-1467
-1468
+ 1468
1469
1470
1471
@@ -13631,7 +13666,17 @@
1600
1601
1602
-1603 | @add_cloudpickle_reduction
+1603
+1604
+1605
+1606
+1607
+1608
+1609
+1610
+1611
+1612
+1613
| @add_cloudpickle_reduction
class Settings(SettingsFieldsMixin):
"""
Contains validated Prefect settings.
@@ -13810,14 +13855,14 @@
Source code in prefect/settings.py
- 1477
-1478
-1479
-1480
-1481
-1482
-1483
-1484 | def value_of(self, setting: Setting[T], bypass_callback: bool = False) -> T:
+ 1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494 | def value_of(self, setting: Setting[T], bypass_callback: bool = False) -> T:
"""
Retrieve a setting's value.
"""
@@ -13849,18 +13894,18 @@
Source code in prefect/settings.py
- 1493
-1494
-1495
-1496
-1497
-1498
-1499
-1500
-1501
-1502
-1503
-1504 | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|