Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix for generateName bug (#76)
Browse files Browse the repository at this point in the history
* Adds fix for generate name bug

* Updates test

* Adds changelog entry
  • Loading branch information
desertaxle authored Jun 20, 2023
1 parent 8c33171 commit 5e6918c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## 0.2.9

Released June 20th, 2023.

### Fixed

- Fixed issue where `generateName` was not populating correctly for some flow runs submitted by `KubernetesWorker` - [#76](https://github.com/PrefectHQ/prefect-kubernetes/pull/76)

## 0.2.8

Released May 25th, 2023.
Expand Down
11 changes: 10 additions & 1 deletion prefect_kubernetes/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,16 @@ def _populate_generate_name_if_not_present(self):
"""Ensures that the generateName is present in the job manifest."""
manifest_generate_name = self.job_manifest["metadata"].get("generateName", "")
has_placeholder = len(find_placeholders(manifest_generate_name)) > 0
if not manifest_generate_name or has_placeholder:
# if name wasn't present during template rendering, generateName will be
# just a hyphen
manifest_generate_name_templated_with_empty_string = (
manifest_generate_name == "-"
)
if (
not manifest_generate_name
or has_placeholder
or manifest_generate_name_templated_with_empty_string
):
generate_name = None
if self.name:
generate_name = _slugify_name(self.name)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import uuid
from contextlib import contextmanager
from time import monotonic, sleep
from unittest import mock
Expand Down Expand Up @@ -154,7 +155,7 @@ def _mock_pods_stream_that_returns_running_pod(*args, **kwargs):
"kind": "Job",
"metadata": {
"namespace": "default",
"generateName": "{{ name }}-",
"generateName": "-",
"labels": {},
},
"spec": {
Expand Down Expand Up @@ -685,7 +686,7 @@ def _mock_pods_stream_that_returns_running_pod(*args, **kwargs):
class TestKubernetesWorkerJobConfiguration:
@pytest.fixture
def flow_run(self):
return FlowRun(name="my-flow-run-name")
return FlowRun(flow_id=uuid.uuid4(), name="my-flow-run-name")

@pytest.fixture
def deployment(self):
Expand Down Expand Up @@ -918,7 +919,7 @@ async def default_configuration(self):

@pytest.fixture
def flow_run(self):
return FlowRun(name="my-flow-run-name")
return FlowRun(flow_id=uuid.uuid4(), name="my-flow-run-name")

async def test_creates_job_by_building_a_manifest(
self,
Expand Down

0 comments on commit 5e6918c

Please sign in to comment.