flyte icon indicating copy to clipboard operation
flyte copied to clipboard

[clustered plugin] PodTemplate labels/annotations not propagated to JobSet ObjectMeta

Open chansoo-calico opened this issue 2 months ago • 3 comments

Describe the bug

PodTemplate.labels set via the Flyte 2 SDK's ClusteredTaskEnvironment are propagated to the child pod template (objectMeta) but never to the parent JobSet's ObjectMeta.Labels. This makes it impossible to use Kueue (or any admission controller that reads CRD-level labels) with clustered tasks.

Root cause

In flyteplugins/go/tasks/plugins/k8s/clustered/build.go, BuildResource already merges SDK labels + execution labels + default labels onto the pod template's objectMeta at L63-64:

objectMeta.Labels = utils.UnionMaps(cfg.DefaultLabels, objectMeta.Labels,
    utils.CopyMap(taskCtx.TaskExecutionMetadata().GetLabels()))

But the JobSet itself at L144-149 hardcodes its labels:

ObjectMeta: metav1.ObjectMeta{
    Name:      jobSetName,
    Namespace: taskCtx.TaskExecutionMetadata().GetNamespace(),
    Labels: map[string]string{
        "flyte.org/execution": sanitizeLabelValue(...),
    },
    ...
}

So any labels from the SDK's PodTemplate (e.g. kueue.x-k8s.io/queue-name) land on the pods but not on the JobSet, where Kueue and other controllers look for them.

Proposed fix

Merge objectMeta.Labels into the JobSet's ObjectMeta.Labels, same as already done for the pod template. The flyte.org/execution label takes precedence (rightmost in UnionMaps):

ObjectMeta: metav1.ObjectMeta{
    Name:      jobSetName,
    Namespace: taskCtx.TaskExecutionMetadata().GetNamespace(),
    Labels: utils.UnionMaps(objectMeta.Labels, map[string]string{
        "flyte.org/execution": sanitizeLabelValue(...),
    }),
    Annotations: utils.UnionMaps(objectMeta.Annotations, map[string]string{
        "flyte.org/task-type":      taskType,
        primaryContainerAnnotation: primaryContainerName,
    }),
},

This is a 2-line, non-breaking change. Existing deployments see no difference (default objectMeta.Labels only contains execution-id labels that are already present). Deployments setting custom labels on PodTemplate (e.g. for Kueue) would see those labels propagated to the JobSet.

Expected behavior

PodTemplate.labels should appear on both the JobSet's ObjectMeta.Labels AND the child pod template. This would enable Kueue queue-name labels, gang scheduling via pod-groups, and any custom admission controller integration.

Additional context

  • This was verified empirically on Flyte 2.6.5 with flyte-binary v2.0.42 on GKE 1.35.
  • The 1.x fix for @task(labels=...) (PR #6421, Issue #6238) addressed a similar problem for flytekit 1.16+ and PyTorchJob, but the Flyte 2 clustered plugin's build.go was written separately and does not include this fix.
  • The Ray plugin handles this correctly for RayJob CRDs, providing precedent.
  • Kueue requires kueue.x-k8s.io/queue-name on the parent CRD (JobSet), not on child pods.

Are you sure this issue hasn't been raised already?

  • [X] Yes

Have you read the Code of Conduct?

  • [X] Yes

chansoo-calico avatar Sep 05 '26 06:09 chansoo-calico

You are correct: in the current Flyte 2 clustered plugin implementation, labels and annotations from the SDK's PodTemplate are merged onto the child pod template's objectMeta, but not onto the parent JobSet's ObjectMeta.Labels. The JobSet's labels are hardcoded, so custom labels (e.g., for Kueue) do not propagate to the JobSet CRD, which is required for Kueue and similar controllers to function properly. This is confirmed in build.go, where only the pod template receives the merged labels, while the JobSet receives a fixed label map.

Your proposed fix—to merge objectMeta.Labels into the JobSet's labels using utils.UnionMaps, with "flyte.org/execution" taking precedence—is consistent with Flyte's label propagation patterns and would resolve the issue without breaking existing deployments. This approach is also in line with how the Ray plugin handles label propagation for CRDs. See build.go and related test code for details.

Would you like a step-by-step breakdown of how to implement and test this fix?

Sources:


This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not.

Mention @herald to ask follow-up questions. See runllm.com for more!

runllm avatar Sep 05 '26 06:09 runllm

Hi @chansoo-calico,

I'm a new contributor and this issue looks like a good first task for me to get familiar with the codebase. The problem description and the proposed fix in build.go are very clear, so I'd like to give it a try if no one is already working on it.

I'll implement the label/annotation propagation to the JobSet ObjectMeta and add a unit test. Will open a PR once it's ready.

Thanks!

Chiuuu0209 avatar Sep 05 '26 12:09 Chiuuu0209

Closing this issue, the above PR handles this now. Thanks for raising the issue.

AdilFayyaz avatar Sep 16 '26 22:09 AdilFayyaz