Skip to content

Conversation

@fg91
Copy link
Member

@fg91 fg91 commented Apr 19, 2025

Tracking issue

Closes #6238

Why are the changes needed?

Today, as a Flyte user, I have the following options to set labels/annotations on the pods/CRD objects of K8s tasks in a flyte workflow execution:

  1. Set via pod template:

    def task(
        pod_template=PodTemplate(annotations=..., labels=...)
    )

    This sets labels/annotations on the pods of individual tasks.
    For distributed tasks (like pytorch, ray, ...) this sets the metadata not on the CRD object but its pod template spec.

  2. Set via pyflyte run --labels ... --annotations ...

    This applies the metadata to all K8s objects in a flyte workflow execution, including task pods and task CRD objects. However, this mechanism doesn't work on an individual task level.

What changes were proposed in this pull request?

As a Flyte user, I would like to be able to specify specific labels/annotations for individual k8s task CRD objects like pytorch jobs, ray job, ... (the same way I already can today for pods via the pod template). For this aim, the following arguments are added to the task decorator:

@task(
    labels=...,
    annotations=...,
)
def test_task():
    ...

These labels and annotations are added to the object metadata of the object executing the task (Pod or CRD object).

This PR adds a metadata field of type K8sObjectMetadata to the TaskMetadata proto message and applies this additional metadata in the plugin manager's addObjectMetadata function.

How was this patch tested?

  • Executed flyteadmin and flytpropeller with these changes and the corresponding changes in flytekit.
  • Adapted unit tests
  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

flyteorg/flytekit#3243

Summary by Bito

This pull request adds a new metadata field to the TaskMetadata proto, enabling users to apply custom labels and annotations to Kubernetes objects. The enhancement spans multiple language implementations including Go, TypeScript, Python, and Rust, providing more granular control over metadata for both pods and custom resources.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 5

…ons=...) to pods and CR objects

Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Apr 19, 2025

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - Bito Automatic Review Skipped - Draft PR

    Bito didn't auto-review because this pull request is in draft status.
    To trigger review, mark the PR as ready or type /review in the comment and save.
    You can change draft PR review settings here, or contact the agent instance creator at eduardo@union.ai.

@codecov
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes missing coverage. Please review.

Project coverage is 58.47%. Comparing base (42002f4) to head (cedcb78).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...er/pkg/controller/nodes/task/k8s/plugin_manager.go 55.55% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6421      +/-   ##
==========================================
- Coverage   58.48%   58.47%   -0.01%     
==========================================
  Files         940      940              
  Lines       71562    71575      +13     
==========================================
+ Hits        41850    41855       +5     
- Misses      26531    26537       +6     
- Partials     3181     3183       +2     
Flag Coverage Δ
unittests-datacatalog 59.03% <ø> (ø)
unittests-flyteadmin 56.24% <ø> (ø)
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 64.70% <ø> (ø)
unittests-flyteidl 76.12% <ø> (ø)
unittests-flyteplugins 60.95% <ø> (ø)
unittests-flytepropeller 54.78% <55.55%> (-0.02%) ⬇️
unittests-flytestdlib 64.04% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fg91 fg91 added the added Merged changes that add new functionality label Apr 21, 2025
@fg91 fg91 self-assigned this Apr 21, 2025
Fabio Grätz added 5 commits April 21, 2025 12:36
Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
@fg91 fg91 changed the title Feat: Apply labels and annotations set via @task(labels=..., annotations=...) to pods and CR objects Feat: Apply labels and annotations set via task decorator to pods and CR objects Apr 21, 2025
})

t.Run("Task template K8s metadata overwrites object metadata", func(t *testing.T) {
o := &v1.Pod{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels/Annotations set via @task(pod_template=PodTemplate(...)) are overwritten by @task(labels=..., annotations=...).

})

t.Run("Task template K8s metadata overwritten by task execution metadata", func(t *testing.T) {
o := &v1.Pod{}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels/annotations set via @task(labels=..., ...) are overwritten by pyflyte run --labels ... --annotations ....

@fg91 fg91 marked this pull request as ready for review April 21, 2025 11:23
@fg91 fg91 requested a review from pingsutw April 21, 2025 11:23
@flyte-bot
Copy link
Collaborator

flyte-bot commented Apr 21, 2025

Code Review Agent Run #c6bea5

Actionable Suggestions - 1
  • flyteidl/gen/pb-go/flyteidl/core/tasks.pb.go - 1
Additional Suggestions - 4
  • flyteidl/gen/pb-js/flyteidl.d.ts - 1
  • flyteidl/gen/pb-go/flyteidl/core/tasks.pb.go - 1
  • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager.go - 1
  • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go - 1
    • Inconsistent variable declaration and comment usage · Line 278-279
Review Details
  • Files reviewed - 10 · Commit Range: c715aea..cedcb78
    • flyteidl/gen/pb-es/flyteidl/core/tasks_pb.ts
    • flyteidl/gen/pb-go/flyteidl/core/tasks.pb.go
    • flyteidl/gen/pb-js/flyteidl.d.ts
    • flyteidl/gen/pb-js/flyteidl.js
    • flyteidl/gen/pb_python/flyteidl/core/tasks_pb2.py
    • flyteidl/gen/pb_python/flyteidl/core/tasks_pb2.pyi
    • flyteidl/gen/pb_rust/flyteidl.core.rs
    • flyteidl/protos/flyteidl/core/tasks.proto
    • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager.go
    • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go
  • Files skipped - 4
    • flyteidl/clients/go/assets/admin.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/agent.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/external_plugin_service.swagger.json - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

Refer to the documentation for additional commands.

Configuration

This repository uses code_review_bito You can customize the agent settings here or contact your Bito workspace admin at haytham@union.ai.

Documentation & Help

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Collaborator

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
New Feature - Added Task Metadata Field

tasks.pb.go - Revised protobuf definitions by inserting a new metadata field and updating field indices to support labels and annotations for both pod templates and CR objects.

tasks_pb.ts - Introduced a new metadata field with detailed comments to capture Kubernetes pod and CR object labels and annotations within TaskMetadata (from previous run).

flyteidl.d.ts - Enhanced TypeScript definitions by adding documentation and new metadata property in the TaskMetadata interface.

flyteidl.js - Integrated handling for the new metadata field by updating encoding, decoding, and verification routines in the JavaScript protobuf implementation.

tasks_pb2.py - Updated Python protobuf descriptors to include the new metadata field, ensuring consistency with modifications in other language implementations.

tasks_pb2.pyi - Augmented type hints and constructor to incorporate new metadata for Kubernetes object integration.

flyteidl.core.rs - Introduced annotations and documentation for the new metadata field in the Rust implementation.

tasks.proto - Extended protobuf definitions to include the new metadata field with comprehensive inline comments.

Feature Improvement - Enhanced Plugin Manager Metadata Handling

plugin_manager.go - Modified addObjectMetadata function to accept a taskTemplate parameter and merge attached metadata, enabling the propagation of task decorator labels/annotations to pods and CR objects.

plugin_manager_test.go - Updated test cases to include the new metadata parameter in addObjectMetadata calls and verify the proper merging and override behaviors of annotations and labels.

37, // [37:37] is the sub-list for extension type_name
37, // [37:37] is the sub-list for extension extendee
0, // [0:37] is the sub-list for field type_name
19, // 10: flyteidl.core.TaskMetadata.metadata:type_name -> flyteidl.core.K8sObjectMetadata
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect protobuf field mapping for TaskMetadata

The TaskMetadata.metadata field is incorrectly mapped to K8sObjectMetadata at index 19 in the dependency indexes array. This will cause incorrect type mapping in the protobuf initialization.

Code suggestion
Check the AI-generated fix before applying
Suggested change
19, // 10: flyteidl.core.TaskMetadata.metadata:type_name -> flyteidl.core.K8sObjectMetadata

Code Review Run #c6bea5


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Copy link
Member

@Sovietaced Sovietaced left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me. Labels/annotations set at the launch plan would apply to all the CRs since they get inherited by the workflow CR. So this should let you deviate on a per task basis.

@fg91 fg91 merged commit d7e0675 into master Apr 30, 2025
49 of 50 checks passed
@fg91 fg91 deleted the fg91/feat/task-k8s-metadata branch April 30, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

added Merged changes that add new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core feature] Allow setting metadata (labels&annotations) individually on all K8s task types

4 participants