thankful-tailor-28399
05/14/2024, 1:19 PMddtrace-run <INSERT-HERE-WHAT-FLYTE-RUNS>
2. Is there a way to set a fixed container name for tasks? This would be used by configuration options that are defined for a given container_name
Thanks in advance !average-finland-92144
05/14/2024, 5:18 PMthankful-tailor-28399
05/15/2024, 6:41 AMimport ddtrace.auto
...
but that should be done in user’s codebase.
Another way of implementing this would be prefixing flyte command with ddtrace-run
which does that under the hoodthankful-tailor-28399
05/15/2024, 6:41 AMthankful-tailor-28399
05/15/2024, 6:43 AMapiVersion: v1
kind: PodTemplate
metadata:
name: flyte-pod-template
namespace: {{ namespace }}
template:
metadata:
labels:
key: value
annotations:
key: value
spec:
containers:
- name: default
image: <http://docker.io/rwgrim/docker-noop|docker.io/rwgrim/docker-noop>
...
The container name won’t be default, but the one set by Flyte. I would need to define the container name in the annotationaverage-finland-92144
05/15/2024, 3:40 PMaverage-finland-92144
05/15/2024, 4:30 PMfrom flytekit import task, workflow
from flytekitplugins.pod import Pod
from kubernetes.client.models import V1Container, V1PodSpec, V1ResourceRequirements, V1Volume, V1VolumeMount
# Define the shared volume
shared_volume = V1Volume(
name="shared-data",
empty_dir={}
)
# Define the volume mount
shared_volume_mount = V1VolumeMount(
name="shared-data",
mount_path="/data"
)
# Define the pod spec with two containers
pod_spec = V1PodSpec(
containers=[
V1Container(
name="primary",
image="primary-image:latest",
resources=V1ResourceRequirements(
requests={"cpu": "1", "memory": "100Mi"},
limits={"cpu": "1", "memory": "100Mi"}
),
volume_mounts=[shared_volume_mount],
command=["sh", "-c", "echo 'Hello from primary container' && sleep 30"]
),
V1Container(
name="secondary",
image="secondary-image:latest",
command=["sh", "-c", "echo 'Hello from secondary container' > /data/message.txt"],
volume_mounts=[shared_volume_mount]
)
],
volumes=[shared_volume]
)
# Define the task using the Pod plugin
@task(task_config=Pod(pod_spec=pod_spec))
def pod_task() -> str:
with open("/data/message.txt", "r") as f:
return f.read()
# Define the workflow
@workflow
def pod_workflow() -> str:
return pod_task()
and the resulting Pod has the two container names correctly overriden:
...
Controlled By: flyteworkflow/fef559dca8bad46a19db
Containers:
primary:
Container ID: <docker://cf556bfc598ad1b08f765118acc27ddb5cc365cf5757e4e6192914586319001>6
...
secondary:
Container ID:....
...
average-finland-92144
05/15/2024, 4:30 PMthankful-tailor-28399
05/15/2024, 5:09 PMdefault
ends up in a pod like:
spec:
containers:
- name: ax9kd5xb4p8r45bpdv7v-n0-0
(it’s an example) .
So maybe:
• if the container name in the pod-template is default
- the container name gets generated randomly
• if the container name in the pod-template is primary
- the container name is primary
average-finland-92144
05/15/2024, 5:13 PMdefault
is respected:
Controlled By: flyteworkflow/fee5884352573487792d
Containers:
default:
Container ID:
Image: primary-image:latest
...
thankful-tailor-28399
05/15/2024, 5:24 PMaverage-finland-92144
05/15/2024, 5:25 PMdefault-pod-template
but something's missing either in code or docs. It'd be great to have your contribution anyways!