Skip to content

Commit

Permalink
Update pod example for local run (flyteorg#680)
Browse files Browse the repository at this point in the history
* Update pod example for local run

Signed-off-by: Alekhya Sai Punnamaraju <[email protected]>

* Grammar changes

Signed-off-by: Alekhya Sai Punnamaraju <[email protected]>

* Apply suggestions from code review

Co-authored-by: Samhita Alla <[email protected]>

Co-authored-by: Samhita Alla <[email protected]>
  • Loading branch information
AlekhyaSasi and samhita-alla authored Mar 7, 2022
1 parent 836aaa5 commit 548146e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cookbook/integrations/kubernetes/pod/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Pod tasks can be used whenever multiple containers need to spin up within a single task.
They expose a fully modifiable Kubernetes `pod spec <https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podspec-v1-core>`__ which can be used to customize the task execution runtime.
All we need to do to use pod tasks is:
All we need to do to use pod tasks are:
1. Define a pod spec
2. Specify the name of the primary container
Expand All @@ -15,8 +15,7 @@
Pod tasks accept arguments that ordinary container tasks usually accept, such as resource specifications, etc.
However, these are only applied to the primary container.
To customize other containers brought up during the execution, we can define a full-fledged pod spec.
This is done using the `Kubernetes Python client library <https://github.com/kubernetes-client/python>`__,
specifically with the
This is done using the `Kubernetes Python client library <https://github.com/kubernetes-client/python>`__'s,
`V1PodSpec <https://github.com/kubernetes-client/python/blob/master/kubernetes/client/models/v1_pod_spec.py>`__.
"""

Expand Down Expand Up @@ -49,10 +48,10 @@
# We define a simple pod spec with two containers.
def generate_pod_spec_for_task():

# primary containers do not require us to specify an image, the default image built for Flyte tasks will get used
# Primary containers do not require us to specify an image, the default image built for Flyte tasks will get used.
primary_container = V1Container(name="primary")

# NOTE: for non-primary containers, we must specify the image
# NOTE: For non-primary containers, we must specify the image.
secondary_container = V1Container(
name="secondary",
image="alpine",
Expand Down Expand Up @@ -97,7 +96,7 @@ def generate_pod_spec_for_task():
),
)
def my_pod_task() -> str:
# the code defined in this task will get injected into the primary container.
# The code defined in this task will get injected into the primary container.
while not os.path.isfile(_SHARED_DATA_PATH):
time.sleep(5)

Expand Down Expand Up @@ -162,6 +161,8 @@ def my_map_workflow(a: List[int]) -> str:
return coalesced

# %%
# Since pod tasks cannot be run locally, we use the ``pass`` keyword to skip running the tasks.
# The workflows can be executed locally as follows:
if __name__ == "__main__":
pass
print(f"Running {__file__} main...")
print(f"Calling PodWorkflow()... {PodWorkflow()}")
print(f"Calling my_map_workflow()... {my_map_workflow()}")

0 comments on commit 548146e

Please sign in to comment.