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 pod_template via with_overrides #6118

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

Conversation

arbaobao
Copy link

@arbaobao arbaobao commented Dec 19, 2024

Tracking issue

Related to #5683

Why are the changes needed?

If we can support pod_template in with_overrides, this would reduce a lot of toil since we can supply pod templates in a central location and override downstream tasks, similar to how we can do so for resources.

What changes were proposed in this pull request?

We can use with_override() to override podtemplate, just like resources.

How was this patch tested?

Excute a workflow and using with_override(pod_template=PodTemplate(xxx)) to override the default podtemplate

Setup process

I ran flyte on my local machine and tested my code with this workflow and task:

python

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

@workflow
def hello_world_wf() -> str:
    res = say_hello().with_overrides(limits=Resources(cpu="2", mem="600Mi"),pod_template=PodTemplate(
        primary_container_name="primary-nelson",
        labels={"lKeyA": "lValA", "lKeyB": "lValB"},
        annotations={"aKeyA": "aValA", "aKeyB": "aValB"},
        pod_spec=V1PodSpec(
            containers=[
                V1Container(
                    name="primary-nelson",
                    image="arbaobao/flyte-test-images:pythonpath5",
                    env=[V1EnvVar(name="eKeyC", value="eValC"), V1EnvVar(name="eKeyD", value="eValD")],
                ),
                V1Container(
                    name="primary-nelson2",
                    image="arbaobao/flyte-test-images:pythonpath5",
                    env=[V1EnvVar(name="eKeyC", value="eValC"), V1EnvVar(name="eKeyD", value="eValD")],
                ),
            ],
        )
    ))
    return res

Screenshots

Check all the applicable boxes

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

Related PRs

Docs link

Summary by Bito

This PR implements pod template override functionality through with_overrides() method, adding primary_container_name field to K8sPod and pod_template to TaskNodeOverrides. The implementation spans multiple languages (TypeScript, Go, JavaScript) with protobuf definitions. The changes enable centralized pod template specification with downstream task override capability, similar to resource overrides.

Unit tests added: True

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

Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
@arbaobao
Copy link
Author

#take

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

flyte-bot commented Dec 29, 2024

Code Review Agent Run #9af1d5

Actionable Suggestions - 7
  • flyteplugins/go/tasks/pluginmachinery/flytek8s/config/k8spluginconfig_flags_test.go - 1
  • flyteidl/gen/pb-js/flyteidl.d.ts - 1
    • Consider making primaryContainerName field required · Line 6964-6964
  • flytepropeller/pkg/compiler/transformers/k8s/node.go - 2
    • Consider initializing podtemplate variable · Line 34-34
    • Consider validating pod template before assignment · Line 65-67
  • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go - 1
    • Consider improving variable naming and error handling · Line 463-464
  • flyteidl/setup.py - 1
    • Consider adding setup configuration parameters · Line 3-3
  • flyteplugins/tests/end_to_end.go - 1
Review Details
  • Files reviewed - 25 · Commit Range: 0a92e7e..c15830d
    • flyteidl/gen/pb-es/flyteidl/core/tasks_pb.ts
    • flyteidl/gen/pb-es/flyteidl/core/workflow_pb.ts
    • flyteidl/gen/pb-go/flyteidl/core/tasks.pb.go
    • flyteidl/gen/pb-go/flyteidl/core/workflow.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_python/flyteidl/core/workflow_pb2.py
    • flyteidl/gen/pb_python/flyteidl/core/workflow_pb2.pyi
    • flyteidl/gen/pb_rust/flyteidl.core.rs
    • flyteidl/protos/flyteidl/core/tasks.proto
    • flyteidl/protos/flyteidl/core/workflow.proto
    • flyteidl/setup.py
    • flyteplugins/go/tasks/pluginmachinery/core/exec_metadata.go
    • flyteplugins/go/tasks/pluginmachinery/core/mocks/task_overrides.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/config/k8spluginconfig_flags.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/config/k8spluginconfig_flags_test.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/plugin_exec_context.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper_test.go
    • flyteplugins/tests/end_to_end.go
    • flytepropeller/pkg/apis/flyteworkflow/v1alpha1/iface.go
    • flytepropeller/pkg/apis/flyteworkflow/v1alpha1/nodes.go
    • flytepropeller/pkg/compiler/transformers/k8s/node.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
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

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
Feature Improvement - Enhanced Task Pod Template Override Support

tasks_pb.ts - Added primary container name field to K8sPod structure

workflow_pb.ts - Added pod template override capability to TaskNodeOverrides

tasks.pb.go - Implemented primary container name functionality in K8SPod

workflow.pb.go - Added pod template support in TaskNodeOverrides

flyteidl.d.ts - Added TypeScript definitions for pod template and primary container name

flyteidl.js - Added JavaScript implementations for pod template overrides

Feature Improvement - Enhanced Pod Template Override Support

tasks.proto - Added primary_container_name field to K8sPod message

workflow.proto - Added pod_template field to TaskNodeOverrides message

tasks_pb2.py - Updated protobuf generated code for K8sPod with primary container name

workflow_pb2.py - Updated protobuf generated code for TaskNodeOverrides with pod template

flyteidl.core.rs - Added Rust implementations for pod template and primary container name

exec_metadata.go - Added GetPodTemplate interface method

plugin_exec_context.go - Implemented GetPodTemplate method in task overrides

Testing - Pod Template Override Test Coverage

task_overrides.go - Added mock implementations for pod template overrides

k8spluginconfig_flags_test.go - Added tests for distributed error aggregation configuration

Feature Improvement - Pod Template Override Implementation

pod_helper.go - Added pod template override functionality with metadata and spec handling

iface.go - Added GetPodTemplate interface method

nodes.go - Added pod template support in node specifications

node.go - Implemented pod template override handling in node building

Testing - Pod Template Override Test Coverage

pod_helper_test.go - Updated test cases to include pod template parameter

end_to_end.go - Added end-to-end test for pod template overrides

Comment on lines +382 to +395
t.Run("Test_enable-distributed-error-aggregation", func(t *testing.T) {

t.Run("Override", func(t *testing.T) {
testValue := "1"

cmdFlags.Set("enable-distributed-error-aggregation", testValue)
if vBool, err := cmdFlags.GetBool("enable-distributed-error-aggregation"); err == nil {
testDecodeJson_K8sPluginConfig(t, fmt.Sprintf("%v", vBool), &actual.EnableDistributedErrorAggregation)

} else {
assert.FailNow(t, err.Error())
}
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding more test cases

Consider adding test cases for both true and false values for the enable-distributed-error-aggregation flag to ensure proper boolean parsing behavior.

Code suggestion
Check the AI-generated fix before applying
 @@ -382,14 +382,40 @@ func TestK8sPluginConfig_SetFlags(t *testing.T) {
 	t.Run("Test_enable-distributed-error-aggregation", func(t *testing.T) {
 		t.Run("Override with 1", func(t *testing.T) {
 			testValue := "1"
 			cmdFlags.Set("enable-distributed-error-aggregation", testValue)
 			if vBool, err := cmdFlags.GetBool("enable-distributed-error-aggregation"); err == nil {
 				testDecodeJson_K8sPluginConfig(t, fmt.Sprintf("%v", vBool), &actual.EnableDistributedErrorAggregation)
 			} else {
 				assert.FailNow(t, err.Error())
 			}
 		})
 		t.Run("Override with true", func(t *testing.T) {
 			testValue := "true"
 			cmdFlags.Set("enable-distributed-error-aggregation", testValue)
 			if vBool, err := cmdFlags.GetBool("enable-distributed-error-aggregation"); err == nil {
 				testDecodeJson_K8sPluginConfig(t, fmt.Sprintf("%v", vBool), &actual.EnableDistributedErrorAggregation)
 			} else {
 				assert.FailNow(t, err.Error())
 			}
 		})
 		t.Run("Override with false", func(t *testing.T) {
 			testValue := "false"
 			cmdFlags.Set("enable-distributed-error-aggregation", testValue)
 			if vBool, err := cmdFlags.GetBool("enable-distributed-error-aggregation"); err == nil {
 				testDecodeJson_K8sPluginConfig(t, fmt.Sprintf("%v", vBool), &actual.EnableDistributedErrorAggregation)
 			} else {
 				assert.FailNow(t, err.Error())
 			}
 		})
 	})

Code Review Run #9af1d5


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

  • it was incorrectly flagged

@@ -6953,6 +6959,9 @@ export namespace flyteidl {

/** K8sPod dataConfig */
dataConfig?: (flyteidl.core.IDataLoadingConfig|null);

/** K8sPod primaryContainerName */
primaryContainerName?: (string|null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider making primaryContainerName field required

Consider making primaryContainerName required instead of optional since it appears to be a critical field for K8sPod configuration. The interface shows it as optional with ? but the class implementation has it as required. A similar issue was also found in flyteidl/gen/pb-js/flyteidl.d.ts (line 6985-6986).

Code suggestion
Check the AI-generated fix before applying
Suggested change
primaryContainerName?: (string|null);
primaryContainerName: string;

Code Review Run #9af1d5


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

  • it was incorrectly flagged

@@ -31,6 +31,7 @@ func buildNodeSpec(n *core.Node, tasks []*core.CompiledTask, errs errors.Compile
var resources *core.Resources
var extendedResources *v1alpha1.ExtendedResources
var containerImage string
var podtemplate *core.K8SPod
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider initializing podtemplate variable

Consider initializing the podtemplate variable with a default value to avoid potential nil pointer dereference issues.

Code suggestion
Check the AI-generated fix before applying
Suggested change
var podtemplate *core.K8SPod
var podtemplate *core.K8SPod = &core.K8SPod{}

Code Review Run #9af1d5


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

  • it was incorrectly flagged

Comment on lines +65 to +67
if overrides.GetPodTemplate() != nil {
podtemplate = overrides.GetPodTemplate()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider validating pod template before assignment

Consider adding validation for podtemplate before assignment. The current code directly assigns the pod template without any validation which could lead to issues if an invalid template is provided.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if overrides.GetPodTemplate() != nil {
podtemplate = overrides.GetPodTemplate()
}
if template := overrides.GetPodTemplate(); template != nil {
if err := validatePodTemplate(template); err != nil {
return nil, err
}
podtemplate = template
}

Code Review Run #9af1d5


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

  • it was incorrectly flagged

Comment on lines +463 to +464
var podspec_override *v1.PodSpec
err := utils.UnmarshalStructToObj(podtemplate.PodSpec, &podspec_override)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider improving variable naming and error handling

Consider using podspec_override instead of podspec_override for better Go naming conventions. Also, error handling could be improved by returning a more descriptive error.

Code suggestion
Check the AI-generated fix before applying
Suggested change
var podspec_override *v1.PodSpec
err := utils.UnmarshalStructToObj(podtemplate.PodSpec, &podspec_override)
var podSpecOverride *v1.PodSpec
if err := utils.UnmarshalStructToObj(podtemplate.PodSpec, &podSpecOverride); err != nil {
return nil, objectMeta, fmt.Errorf("failed to unmarshal pod spec: %w", err)
}

Code Review Run #9af1d5


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

  • it was incorrectly flagged

@@ -1,3 +1,3 @@
from setuptools import setup, find_packages

setup()
setup()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding setup configuration parameters

The empty setup() call may be missing required parameters. Consider adding necessary configuration like name, version, packages, etc.

Code suggestion
Check the AI-generated fix before applying
 @@ -1,3 +1,9 @@
 from setuptools import setup, find_packages

 -setup()
 +setup(
 +    name='flyteidl',
 +    version='0.1.0',
 +    packages=find_packages(),
 +    install_requires=[],
 +    python_requires='>=3.7'
 +)

Code Review Run #9af1d5


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

  • it was incorrectly flagged

@@ -148,6 +148,7 @@ func RunPluginEndToEndTest(t *testing.T, executor pluginCore.Plugin, template *i
})
overrides.OnGetExtendedResources().Return(&idlCore.ExtendedResources{})
overrides.OnGetContainerImage().Return("")
overrides.OnGetPodTemplate().Return(&idlCore.K8SPod{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding error handling for mock

Consider adding error handling for the mock return value setup. The OnGetPodTemplate() call may need error handling to properly simulate failure scenarios.

Code suggestion
Check the AI-generated fix before applying
Suggested change
overrides.OnGetPodTemplate().Return(&idlCore.K8SPod{})
overrides.OnGetPodTemplate().Return(&idlCore.K8SPod{}, nil)

Code Review Run #9af1d5


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

  • it was incorrectly flagged

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

Successfully merging this pull request may close these issues.

2 participants