<#1952 Support imagespec in V1Container (pod_templ...
# flyte-github
a
#1952 Support imagespec in V1Container (pod_template) Pull request opened by ByronHsu TL;DR 1. Support ImageSpec in V1Container (pod_template) 2. FIx the issue that where primary container image in pod template can never be picked up Type ☐ Bug Fix ☑︎ Feature ☐ Plugin Are all requirements met? ☐ Code completed ☐ Smoke tested ☑︎ Unit tests added ☐ Code documentation added ☐ Any pending items have an associated Issue Complete description Support ImageSpec in V1Container (pod_template) 1. Resolve and build imagespec when serializing pod spec 2. Users can use image spec in pod_template, so they can build many images in one pod template on the fly.
Copy code
image_spec_1 = ImageSpec(
    name="image-1",
    packages=["numpy"],
    registry="localhost:30000",
)

image_spec_2 = ImageSpec(
    name="image-2",
    packages=["pandas"],
    registry="localhost:30000",
)


ps = V1PodSpec(
    containers=[
        V1Container(
            name="primary",
            image=image_spec_1,
        ),
        V1Container(
            name="secondary",
            image=image_spec_2,
            # use 1 cpu and 1Gi mem
            resources=V1ResourceRequirements(
                requests={"cpu": "1", "memory": "100Mi"},
                limits={"cpu": "1", "memory": "100Mi"},
            )
        )
    ]
)

pt = PodTemplate(pod_spec=ps, primary_container_name="primary")



@task(
    pod_template=pt,
)
def t1():
    ...
Copy code
pyflyte run --remote test_workflow.py wf
Running Execution on Remote.
Image localhost:30000/image-1:gDSPZbJbEJZi4aE3JU5KsQ.. found. Skip building.
Image localhost:30000/image-2:_m2eLIYc7WSm8vWd9yzNNA.. found. Skip building.

[✔] Go to http://localhost:30080/console/projects/flytesnacks/domains/development/executions/f12b519658cb1441ab0f to see execution in the console.
FIx the issue where the primary container image in pod template can never be picked up The original behavior is: the image of primary container is overridden with primaryContainer's image during serialization. (code)
Copy code
ps = V1PodSpec(
    containers=[
        V1Container(
            name="primary",
            image="primary-image",
        ),
    ]
)

pt = PodTemplate(pod_spec=ps, primary_container_name="primary")
@task(
  pod_template=pt,
)
def t():
  ...
In the above case, the task will use default image instead of
primary-image
at the end because
Note:
primaryContainer
here means the one get from
get_container
, and
primary container
means the one in pod template
1. We construct
primaryContainer
in get_container, and because
container_image
arg in
@task
is empty, it will be filled with the default image. 2. We assign `primaryContaine`r's image (default image) to the
primary container
in the pod template (code), so the actual image (
primary-image
) is overridden. The fixed behavior is that
PrimaryContainer
only overrides when the image in pod_template's
primary container
is empty. With the same example above, it now uses
primary-image
. Tracking Issue flyteorg/flyte#4070 flyteorg/flytekit Codecov: 62.47% (-0.22%) compared to 28adeee Codecov: 25.00% of diff hit (target 62.69%) ✅ 28 other checks have passed 28/30 successful checks