From 4009761664b1c7bec96005c1d32d3a38f31fa075 Mon Sep 17 00:00:00 2001 From: Trent Shapiro Date: Wed, 11 Oct 2023 17:26:29 +0000 Subject: [PATCH 1/3] cut length from flow_name so ARM deployment doesnt hit 64 char limit --- prefect_azure/workers/container_instance.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prefect_azure/workers/container_instance.py b/prefect_azure/workers/container_instance.py index 5f569e0..e56754a 100644 --- a/prefect_azure/workers/container_instance.py +++ b/prefect_azure/workers/container_instance.py @@ -69,6 +69,8 @@ template to use any features available in Azure Container Instances. """ # noqa import datetime +import random +import string import sys import time from enum import Enum @@ -108,6 +110,8 @@ else: from pydantic import Field, SecretStr +from slugify import slugify + from prefect_azure.container_instance import ACRManagedIdentity from prefect_azure.credentials import AzureContainerInstanceCredentials @@ -566,6 +570,16 @@ async def run( flow = await prefect_client.read_flow(flow_run.flow_id) container_group_name = f"{flow.name}-{flow_run.id}" + # Slugify flow.name if the generated name will be too long for the + # max deployment name length (64) including "prefect-" + if len(container_group_name) > 55: + slugified_flow_name = slugify( + flow.name, + max_length=55 - len(flow_run.id), + regex_pattern=r"[^a-zA-Z0-9-]+", + ) + container_group_name = f"{slugified_flow_name}-{flow_run.id}" + self._logger.info( f"{self._log_prefix}: Preparing to run command {configuration.command} " f"in container {configuration.image})..." From 1f0c9792415b97b469055a389c4e41be59f5b722 Mon Sep 17 00:00:00 2001 From: Trent Shapiro Date: Wed, 11 Oct 2023 17:30:32 +0000 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2aafa8..ab409b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Worker created deployments will cut flow name length to not reach max 64 character deployment name length + ### Deprecated ### Removed From 26fd30dd6d5062b2d7ff7e55be8c14ad6eae99d5 Mon Sep 17 00:00:00 2001 From: Trent Shapiro Date: Wed, 11 Oct 2023 17:35:48 +0000 Subject: [PATCH 3/3] remove unused imports --- prefect_azure/workers/container_instance.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/prefect_azure/workers/container_instance.py b/prefect_azure/workers/container_instance.py index e56754a..414d88a 100644 --- a/prefect_azure/workers/container_instance.py +++ b/prefect_azure/workers/container_instance.py @@ -69,8 +69,6 @@ template to use any features available in Azure Container Instances. """ # noqa import datetime -import random -import string import sys import time from enum import Enum