Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overriding task annotations and labels via with_overrides #3061

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arbaobao
Copy link
Contributor

@arbaobao arbaobao commented Jan 15, 2025

Tracking issue

Why are the changes needed?

Improvement to allow setting labels and annotations dynamically at run time for things like cost allocation.

What changes were proposed in this pull request?

Adds labels and annotations to with_overrides().

How was this patch tested?

Excute a workflow and using with_override(labels={"lKeyA": "lValA"},annotations={"lKeyB": "lValB"}).

Setup process

python

@task
def say_hello() -> str:
    return "Hello, World!"

@workflow
def hello_world_wf() -> str:
    res = say_hello().with_overrides(labels={"lKeyA": "lValA"},annotations={"lKeyB": "lValB"})
    return res

It can be tested by using kubectl describe pods {pod_name} -n flytesnacks-development

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

flyte 6171

Docs link

Summary by Bito

Implementation of task annotations and labels override functionality via with_overrides() method. Added label and annotation fields to Node class and TaskNodeOverrides with serialization support. Enables dynamic runtime configuration of labels/annotations for cost allocation purposes. Includes comprehensive test coverage across various task types.

Unit tests added: True

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

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 15, 2025

Code Review Agent Run #2c0fc5

Actionable Suggestions - 2
  • flytekit/core/node.py - 1
    • Consider consolidating duplicate validation logic · Line 228-234
  • flytekit/tools/translator.py - 1
Review Details
  • Files reviewed - 6 · Commit Range: 44e8c1b..44e8c1b
    • flytekit/core/node.py
    • flytekit/models/core/workflow.py
    • flytekit/tools/translator.py
    • tests/flytekit/unit/core/test_array_node_map_task.py
    • tests/flytekit/unit/core/test_map_task.py
    • tests/flytekit/unit/core/test_node_creation.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 15, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Task Node Override Enhancement

node.py - Added support for labels and annotations in Node class

workflow.py - Implemented label and annotation fields in TaskNodeOverrides

translator.py - Added serialization support for labels and annotations

Testing - Test Coverage for Label and Annotation Overrides

test_array_node_map_task.py - Added tests for map task overrides with labels and annotations

test_map_task.py - Added tests for map task label and annotation overrides

test_node_creation.py - Added dedicated tests for label and annotation overrides

Comment on lines +228 to +234
if annotations is not None:
assert_not_promise(annotations, "annotations")
self._annotations = annotations

if labels is not None:
assert_not_promise(labels, "labels")
self._labels = labels
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider consolidating duplicate validation logic

Consider consolidating the duplicate validation logic for annotations and labels into a helper function to reduce code duplication. The same pattern of checking for None and calling assert_not_promise() is repeated.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if annotations is not None:
assert_not_promise(annotations, "annotations")
self._annotations = annotations
if labels is not None:
assert_not_promise(labels, "labels")
self._labels = labels
def _validate_dict_param(value: Optional[Dict[str, str]], param_name: str) -> None:
if value is not None:
assert_not_promise(value, param_name)
setattr(self, f"_{param_name}", value)
_validate_dict_param(annotations, "annotations")
_validate_dict_param(labels, "labels")

Code Review Run #2c0fc5


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +469 to +470
annotations=entity._annotations,
labels=entity._labels,
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider validating node override fields

Consider adding validation for _annotations and _labels before passing them to TaskNodeOverrides. These fields could potentially be None which may cause issues downstream.

Code suggestion
Check the AI-generated fix before applying
Suggested change
annotations=entity._annotations,
labels=entity._labels,
annotations=entity._annotations if entity._annotations is not None else {},
labels=entity._labels if entity._labels is not None else {},

Code Review Run #2c0fc5


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 15, 2025

Code Review Agent Run #db4a2c

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: e485d6a..7df32f2
    • flytekit/core/node.py
    • flytekit/models/core/workflow.py
    • flytekit/tools/translator.py
    • tests/flytekit/unit/core/test_array_node_map_task.py
    • tests/flytekit/unit/core/test_map_task.py
    • tests/flytekit/unit/core/test_node_creation.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants