Skip to content

Commit

Permalink
pod template inplace operations (#2899)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Sola <[email protected]>
Signed-off-by: Katrina Rogan <[email protected]>
  • Loading branch information
dansola authored and katrogan committed Nov 15, 2024
1 parent 6127b98 commit b0bd909
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flytekit/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import datetime
import inspect
import os
Expand Down Expand Up @@ -147,6 +148,9 @@ def _serialize_pod_spec(

if pod_template.pod_spec is None:
return {}

pod_template = copy.deepcopy(pod_template)

containers = cast(V1PodSpec, pod_template.pod_spec).containers
primary_exists = False

Expand Down
28 changes: 28 additions & 0 deletions tests/flytekit/unit/core/test_pod_template_mutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from flytekit import PodTemplate, task
from flytekit.configuration import SerializationSettings, ImageConfig, Image


def test_mutation():
pod_template_before = PodTemplate(
labels={"lKeyA": "lValA", "lKeyB": "lValB"},
)

pod_template_after = PodTemplate(
labels={"lKeyA": "lValA", "lKeyB": "lValB"},
)

settings = SerializationSettings(image_config=ImageConfig(default_image=Image(
name='default',
fqn='cr.flyte.org/flyteorg/flytekit',
tag='latest',
digest=None
)))

@task(pod_template=pod_template_before)
def my_task():
pass

my_task.get_k8s_pod(settings=settings)


assert pod_template_before == pod_template_after

0 comments on commit b0bd909

Please sign in to comment.