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 15 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 with with_overrides() method across multiple languages, enabling centralized pod template configuration. The implementation includes protobuf definitions, security enhancements through configurable security contexts, and pod template metadata handling. The changes improve email notification system with retry mechanisms, add container port naming support, and enhance array node event handling in Flytepropeller. The refactoring allows users to manage pod templates from a central location, similar to resource overrides.

Unit tests added: True

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

Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
@arbaobao
Copy link
Author

#take

Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
Signed-off-by: Nelson Chen <[email protected]>
@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

flyte-bot commented Dec 29, 2024

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Pod Template Override Support

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

workflow_pb.ts - Added pod template override support to TaskNodeOverrides

tasks.pb.go - Added primary container name field and getters to K8SPod struct

workflow.pb.go - Added pod template override field and getters to TaskNodeOverrides

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

flyteidl.js - Added JavaScript implementations for pod template and primary container name

Feature Improvement - Pod Template Override Support

tasks_pb2.py - Added primary container name field to K8sPod message

workflow_pb2.py - Added pod template override support to TaskNodeOverrides

tasks_pb2.pyi - Added type hints for primary container name field

workflow_pb2.pyi - Added type hints for pod template override

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

tasks.proto - Added primary container name field definition

workflow.proto - Added pod template override field definition

exec_metadata.go - Added GetPodTemplate interface method

task_overrides.go - Added mock implementations for pod template override

k8spluginconfig_flags.go - Added distributed error aggregation flag

k8spluginconfig_flags_test.go - Added tests for distributed error aggregation flag

Feature Improvement - Pod Template Override Implementation

plugin_exec_context.go - Added GetPodTemplate method to support pod template overrides

pod_helper.go - Implemented pod template override functionality in pod creation

nodes.go - Added pod template field and getter to NodeSpec

node.go - Added support for pod template overrides in node compilation

plugin_manager.go - Enhanced metadata handling for pod template overrides

Testing - Pod Template Override Test Coverage

pod_helper_test.go - Added comprehensive tests for pod template override functionality

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

plugin_manager_test.go - Added tests for metadata handling with 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

@@ -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

Signed-off-by: Nelson Chen <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 9, 2025

Code Review Agent Run #81015a

Actionable Suggestions - 0
Additional Suggestions - 10
  • flytepropeller/pkg/controller/controller.go - 1
    • Consider consistent domain prefix for finalizers · Line 68-68
  • flyteplugins/go/tasks/pluginmachinery/tasklog/template.go - 1
    • Consider initializing NodeName regex field · Line 30-30
  • flytepropeller/pkg/controller/handler.go - 1
    • Consider using standard deletion check utility · Line 107-107
  • flyteidl/gen/pb_rust/flyteidl.core.rs - 1
  • flyteadmin/pkg/manager/impl/resources/resource_manager_test.go - 2
    • Consider testing all required fields validation · Line 61-65
    • Consider simplifying mock setup chain · Line 845-845
  • flyteplugins/go/tasks/plugins/webapi/agent/plugin.go - 3
  • flyteidl/protos/flyteidl/core/workflow.proto - 1
    • Consider more descriptive enum values names · Line 154-165
Review Details
  • Files reviewed - 93 · Commit Range: c15830d..bbff25d
    • boilerplate/flyte/golang_support_tools/go.mod
    • boilerplate/flyte/golang_support_tools/go.sum
    • charts/flyte-binary/values.yaml
    • charts/flyte-core/templates/propeller/deployment.yaml
    • charts/flyte-core/values.yaml
    • charts/flyte/values.yaml
    • charts/flyteagent/values.yaml
    • datacatalog/go.mod
    • datacatalog/go.sum
    • deployment/agent/flyte_agent_helm_generated.yaml
    • deployment/eks/flyte_aws_scheduler_helm_generated.yaml
    • deployment/eks/flyte_helm_controlplane_generated.yaml
    • deployment/eks/flyte_helm_dataplane_generated.yaml
    • deployment/eks/flyte_helm_generated.yaml
    • deployment/gcp/flyte_helm_controlplane_generated.yaml
    • deployment/gcp/flyte_helm_dataplane_generated.yaml
    • deployment/gcp/flyte_helm_generated.yaml
    • deployment/sandbox-binary/flyte_sandbox_binary_helm_generated.yaml
    • deployment/sandbox/flyte_helm_generated.yaml
    • docker/sandbox-bundled/manifests/complete-agent.yaml
    • docker/sandbox-bundled/manifests/complete.yaml
    • docker/sandbox-bundled/manifests/dev.yaml
    • docs/_static/custom.js
    • docs/community/contribute/contribute_code.rst
    • docs/community/contribute/index.rst
    • docs/community/index.rst
    • docs/conf.py
    • docs/deployment/configuration/generated/flyteadmin_config.rst
    • docs/deployment/configuration/generated/flytepropeller_config.rst
    • docs/deployment/configuration/generated/scheduler_config.rst
    • flyteadmin/go.mod
    • flyteadmin/go.sum
    • flyteadmin/pkg/manager/impl/resources/resource_manager_test.go
    • flyteadmin/pkg/manager/impl/task_manager.go
    • flyteadmin/pkg/manager/impl/task_manager_test.go
    • flyteadmin/pkg/repositories/gormimpl/task_repo.go
    • flyteadmin/pkg/repositories/transformers/task_execution.go
    • flyteadmin/pkg/workflowengine/impl/prepare_execution.go
    • flyteadmin/pkg/workflowengine/impl/prepare_execution_test.go
    • flytecopilot/go.mod
    • flytecopilot/go.sum
    • flytectl/go.mod
    • flytectl/go.sum
    • flyteidl/gen/pb-es/flyteidl/core/literals_pb.ts
    • flyteidl/gen/pb-es/flyteidl/core/workflow_pb.ts
    • flyteidl/gen/pb-es/flyteidl/event/event_pb.ts
    • flyteidl/gen/pb-go/flyteidl/core/literals.pb.go
    • flyteidl/gen/pb-go/flyteidl/core/workflow.pb.go
    • flyteidl/gen/pb-go/flyteidl/event/event.pb.go
    • flyteidl/gen/pb-js/flyteidl.d.ts
    • flyteidl/gen/pb-js/flyteidl.js
    • flyteidl/gen/pb_python/flyteidl/core/literals_pb2.py
    • flyteidl/gen/pb_python/flyteidl/core/literals_pb2.pyi
    • flyteidl/gen/pb_python/flyteidl/core/workflow_pb2.py
    • flyteidl/gen/pb_python/flyteidl/core/workflow_pb2.pyi
    • flyteidl/gen/pb_python/flyteidl/event/event_pb2.py
    • flyteidl/gen/pb_python/flyteidl/event/event_pb2.pyi
    • flyteidl/gen/pb_rust/flyteidl.core.rs
    • flyteidl/gen/pb_rust/flyteidl.event.rs
    • flyteidl/go.mod
    • flyteidl/go.sum
    • flyteidl/protos/flyteidl/core/literals.proto
    • flyteidl/protos/flyteidl/core/workflow.proto
    • flyteidl/protos/flyteidl/event/event.proto
    • flyteplugins/go.mod
    • flyteplugins/go.sum
    • flyteplugins/go/tasks/logs/logging_utils.go
    • flyteplugins/go/tasks/logs/logging_utils_test.go
    • flyteplugins/go/tasks/pluginmachinery/core/phase.go
    • flyteplugins/go/tasks/pluginmachinery/k8s/plugin.go
    • flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go
    • flyteplugins/go/tasks/pluginmachinery/tasklog/template.go
    • flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go
    • flyteplugins/go/tasks/plugins/array/k8s/subtask.go
    • flyteplugins/go/tasks/plugins/k8s/ray/ray.go
    • flyteplugins/go/tasks/plugins/webapi/agent/plugin.go
    • flytepropeller/go.mod
    • flytepropeller/go.sum
    • flytepropeller/pkg/controller/controller.go
    • flytepropeller/pkg/controller/finalizer.go
    • flytepropeller/pkg/controller/finalizer_test.go
    • flytepropeller/pkg/controller/handler.go
    • flytepropeller/pkg/controller/handler_test.go
    • flytepropeller/pkg/controller/nodes/array/event_recorder.go
    • flytepropeller/pkg/controller/nodes/branch/handler.go
    • flytepropeller/pkg/controller/nodes/branch/handler_test.go
    • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager.go
    • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go
    • flytepropeller/pkg/controller/nodes/task/transformer.go
    • flytestdlib/go.mod
    • flytestdlib/go.sum
    • go.mod
    • go.sum
  • Files skipped - 16
    • .github/PULL_REQUEST_TEMPLATE.md - Reason: Filter setting
    • .github/workflows/single-binary.yml - Reason: Filter setting
    • CHANGELOG/CHANGELOG-v1.14.1.md - Reason: Filter setting
    • README.md - Reason: Filter setting
    • charts/flyte-binary/README.md - Reason: Filter setting
    • charts/flyte-core/README.md - Reason: Filter setting
    • charts/flyte/README.md - Reason: Filter setting
    • charts/flyteagent/README.md - Reason: Filter setting
    • docs/community/contribute/contribute_docs.md - Reason: Filter setting
    • docs/user_guide/data_types_and_io/index.md - Reason: Filter setting
    • docs/user_guide/flyte_fundamentals/index.md - Reason: Filter setting
    • docs/user_guide/flyte_fundamentals/jupyter_notebook_interaction.md - Reason: Filter setting
    • docs/user_guide/flyte_fundamentals/running_and_scheduling_workflows.md - Reason: Filter setting
    • docs/user_guide/productionizing/configuring_logging_links_in_the_ui.md - Reason: Filter setting
    • flyteidl/clients/go/assets/admin.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.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

Comment on lines 340 to 341
// Override for the pod template used by task pods
K8sPod pod_template = 4;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Override for the pod template used by task pods
K8sPod pod_template = 4;
// Override for the pod template used by task pods.
//+optional
K8sPod pod_template = 4;

@@ -286,6 +286,13 @@ func BuildRawPod(ctx context.Context, tCtx pluginsCore.TaskExecutionContext) (*v
*c,
},
}
if tCtx.TaskExecutionMetadata().GetOverrides().GetPodTemplate() != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: could we create a variable for podTemplate here? like

podTemplate := tCtx.TaskExecutionMetadata().GetOverrides().GetPodTemplate
if podTemplate != nil {
  ...
}

if podtemplate.Metadata.Labels != nil {
mergeMapInto(podtemplate.Metadata.Labels, objectMeta.Labels)
}
var podspec_override *v1.PodSpec
Copy link
Member

@pingsutw pingsutw Jan 11, 2025

Choose a reason for hiding this comment

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

Suggested change
var podspec_override *v1.PodSpec
var podSpecOverride *v1.PodSpec

@@ -2022,7 +2023,7 @@ func TestMergeWithBasePodTemplate(t *testing.T) {
taskReader.On("Read", mock.Anything).Return(task, nil)

tCtx := &pluginsCoreMock.TaskExecutionContext{}
tCtx.OnTaskExecutionMetadata().Return(dummyTaskExecutionMetadata(&v1.ResourceRequirements{}, nil, ""))
tCtx.OnTaskExecutionMetadata().Return(dummyTaskExecutionMetadata(&v1.ResourceRequirements{}, nil, "", nil))
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test that has a podTemplate in the dummyTaskExecution?

@@ -446,6 +453,25 @@ func ApplyContainerImageOverride(podSpec *v1.PodSpec, containerImage string, pri
}
}

func ApplyPodTemplateOverride(podSpec *v1.PodSpec, objectMeta metav1.ObjectMeta, podtemplate *core.K8SPod) (*v1.PodSpec, metav1.ObjectMeta, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func ApplyPodTemplateOverride(podSpec *v1.PodSpec, objectMeta metav1.ObjectMeta, podtemplate *core.K8SPod) (*v1.PodSpec, metav1.ObjectMeta, error) {
func ApplyPodTemplateOverride(podSpec *v1.PodSpec, objectMeta metav1.ObjectMeta, podTemplate *core.K8SPod) (*v1.PodSpec, metav1.ObjectMeta, error) {

@flyteorg flyteorg deleted a comment from flyte-bot Jan 11, 2025
Signed-off-by: Nelson Chen <[email protected]>
@arbaobao
Copy link
Author

@pingsutw Hi Kevin, I have added a unit test in pod_helper_test.go and fixed some typos that you mentioned.

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 14, 2025

Code Review Agent Run #7e1782

Actionable Suggestions - 1
  • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper_test.go - 1
Review Details
  • Files reviewed - 6 · Commit Range: bbff25d..b6e360c
    • flyteidl/gen/pb-es/flyteidl/core/workflow_pb.ts
    • flyteidl/gen/pb-go/flyteidl/core/workflow.pb.go
    • flyteidl/gen/pb_rust/flyteidl.core.rs
    • flyteidl/protos/flyteidl/core/workflow.proto
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper_test.go
  • Files skipped - 3
    • 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
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines 1090 to 1105
t.Run("Override pod template", func(t *testing.T) {
taskContext := dummyExecContext(dummyTaskTemplate(), &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1024m"),
}}, nil, "", &core.K8SPod{
PrimaryContainerName: "foo",
PodSpec: podSpecStruct,
Metadata: metadata,
})
p, m, _, err := ToK8sPodSpec(context.TODO(), taskContext)
assert.NoError(t, err)
assert.Equal(t, "a", m.Labels["l"])
assert.Equal(t, "b", m.Annotations["a"])
assert.Equal(t, "foo:latest", p.Containers[0].Image)
assert.Equal(t, "foo", p.Containers[0].Name)
})
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 test cases

Consider adding test cases to verify error scenarios and edge cases in TestPodTemplateOverride. For example, testing with invalid pod specs, missing container names, or empty metadata.

Code suggestion
Check the AI-generated fix before applying
Suggested change
t.Run("Override pod template", func(t *testing.T) {
taskContext := dummyExecContext(dummyTaskTemplate(), &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1024m"),
}}, nil, "", &core.K8SPod{
PrimaryContainerName: "foo",
PodSpec: podSpecStruct,
Metadata: metadata,
})
p, m, _, err := ToK8sPodSpec(context.TODO(), taskContext)
assert.NoError(t, err)
assert.Equal(t, "a", m.Labels["l"])
assert.Equal(t, "b", m.Annotations["a"])
assert.Equal(t, "foo:latest", p.Containers[0].Image)
assert.Equal(t, "foo", p.Containers[0].Name)
})
t.Run("Override pod template", func(t *testing.T) {
taskContext := dummyExecContext(dummyTaskTemplate(), &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1024m"),
}}, nil, "", &core.K8SPod{
PrimaryContainerName: "foo",
PodSpec: podSpecStruct,
Metadata: metadata,
})
p, m, _, err := ToK8sPodSpec(context.TODO(), taskContext)
assert.NoError(t, err)
assert.Equal(t, "a", m.Labels["l"])
assert.Equal(t, "b", m.Annotations["a"])
assert.Equal(t, "foo:latest", p.Containers[0].Image)
assert.Equal(t, "foo", p.Containers[0].Name)
})
t.Run("Invalid pod spec", func(t *testing.T) {
taskContext := dummyExecContext(dummyTaskTemplate(), &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1024m"),
}}, nil, "", &core.K8SPod{
PrimaryContainerName: "foo",
PodSpec: nil,
Metadata: metadata,
})
_, _, _, err := ToK8sPodSpec(context.TODO(), taskContext)
assert.Error(t, err)
})

Code Review Run #7e1782


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

  • it was incorrectly flagged

Signed-off-by: Nelson Chen <[email protected]>
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 31.43%. Comparing base (05c85a8) to head (b16b61e).

Files with missing lines Patch % Lines
flyteidl/gen/pb-go/flyteidl/core/tasks.pb.go 0.00% 5 Missing ⚠️
flyteidl/gen/pb-go/flyteidl/core/workflow.pb.go 0.00% 5 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (05c85a8) and HEAD (b16b61e). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (05c85a8) HEAD (b16b61e)
unittests-flyteplugins 1 0
unittests-flytepropeller 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6118      +/-   ##
==========================================
- Coverage   37.05%   31.43%   -5.62%     
==========================================
  Files        1318      781     -537     
  Lines      132583    84280   -48303     
==========================================
- Hits        49122    26494   -22628     
+ Misses      79211    55673   -23538     
+ Partials     4250     2113    -2137     
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 54.33% <ø> (ø)
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 62.29% <ø> (-0.05%) ⬇️
unittests-flyteidl 7.23% <0.00%> (-0.01%) ⬇️
unittests-flyteplugins ?
unittests-flytepropeller ?
unittests-flytestdlib 55.13% <ø> (ø)

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.

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 15, 2025

Code Review Agent Run #1518a4

Actionable Suggestions - 0
Additional Suggestions - 1
  • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer_test.go - 1
    • Consider standardizing assertion argument order · Line 39-40
Review Details
  • Files reviewed - 37 · Commit Range: b6e360c..b16b61e
    • charts/flyte-binary/templates/deployment.yaml
    • charts/flyte-binary/values.yaml
    • datacatalog/go.mod
    • datacatalog/go.sum
    • docker/sandbox-bundled/manifests/complete-agent.yaml
    • docker/sandbox-bundled/manifests/complete.yaml
    • docker/sandbox-bundled/manifests/dev.yaml
    • flyteadmin/go.mod
    • flyteadmin/go.sum
    • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer.go
    • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer_test.go
    • flyteadmin/pkg/async/notifications/mocks/sendgrid_client.go
    • flytecopilot/go.mod
    • flytecopilot/go.sum
    • flytectl/go.mod
    • flytectl/go.sum
    • 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/go.mod
    • flyteidl/go.sum
    • flyteidl/protos/flyteidl/core/tasks.proto
    • flyteplugins/go.mod
    • flyteplugins/go.sum
    • flytepropeller/go.mod
    • flytepropeller/go.sum
    • flytepropeller/pkg/controller/nodes/array/handler.go
    • flytepropeller/pkg/controller/nodes/array/handler_test.go
    • flytestdlib/go.mod
    • flytestdlib/go.sum
    • flytestdlib/resolver/k8s_resolver.go
    • go.mod
    • go.sum
  • Files skipped - 7
    • charts/flyte-binary/README.md - Reason: Filter setting
    • docs/user_guide/data_types_and_io/flytedirectory.md - Reason: Filter setting
    • docs/user_guide/getting_started_with_workflow_development/running_a_workflow_locally.md - Reason: Filter setting
    • 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

ow := &pluginsIOMock.OutputWriter{}
ow.OnGetOutputPrefixPath().Return("")
ow.OnGetRawOutputPrefix().Return("")
ow.OnGetCheckpointPrefix().Return("/checkpoint")
ow.OnGetPreviousCheckpointsPrefix().Return("/prev")

tCtx := &pluginsCoreMock.TaskExecutionContext{}
tCtx.OnTaskExecutionMetadata().Return(dummyTaskExecutionMetadata(r, rm, containerImage))
tCtx.OnTaskExecutionMetadata().Return(dummyTaskExecutionMetadata(r, rm, containerImage, podtemplate))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tCtx.OnTaskExecutionMetadata().Return(dummyTaskExecutionMetadata(r, rm, containerImage, podtemplate))
tCtx.OnTaskExecutionMetadata().Return(dummyTaskExecutionMetadata(r, rm, containerImage, podTemplate))

@@ -82,15 +84,15 @@ func dummyInputReader() io.InputReader {
return inputReader
}

func dummyExecContext(taskTemplate *core.TaskTemplate, r *v1.ResourceRequirements, rm *core.ExtendedResources, containerImage string) pluginsCore.TaskExecutionContext {
func dummyExecContext(taskTemplate *core.TaskTemplate, r *v1.ResourceRequirements, rm *core.ExtendedResources, containerImage string, podtemplate *core.K8SPod) pluginsCore.TaskExecutionContext {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func dummyExecContext(taskTemplate *core.TaskTemplate, r *v1.ResourceRequirements, rm *core.ExtendedResources, containerImage string, podtemplate *core.K8SPod) pluginsCore.TaskExecutionContext {
func dummyExecContext(taskTemplate *core.TaskTemplate, r *v1.ResourceRequirements, rm *core.ExtendedResources, containerImage string, podTemplate *core.K8SPod) pluginsCore.TaskExecutionContext {

)

func dummyTaskExecutionMetadata(resources *v1.ResourceRequirements, extendedResources *core.ExtendedResources, containerImage string) pluginsCore.TaskExecutionMetadata {
func dummyTaskExecutionMetadata(resources *v1.ResourceRequirements, extendedResources *core.ExtendedResources, containerImage string, podtemplate *core.K8SPod) pluginsCore.TaskExecutionMetadata {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func dummyTaskExecutionMetadata(resources *v1.ResourceRequirements, extendedResources *core.ExtendedResources, containerImage string, podtemplate *core.K8SPod) pluginsCore.TaskExecutionMetadata {
func dummyTaskExecutionMetadata(resources *v1.ResourceRequirements, extendedResources *core.ExtendedResources, containerImage string, podTemplate *core.K8SPod) pluginsCore.TaskExecutionMetadata {

return nil, objectMeta, err
}

return podspec_override, objectMeta, nil
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return podspec_override, objectMeta, nil
return podSpecOverride, objectMeta, nil

mergeMapInto(podTemplate.Metadata.Labels, objectMeta.Labels)
}
var podspec_override *v1.PodSpec
err := utils.UnmarshalStructToObj(podTemplate.PodSpec, &podspec_override)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := utils.UnmarshalStructToObj(podTemplate.PodSpec, &podspec_override)
err := utils.UnmarshalStructToObj(podTemplate.PodSpec, &podSpecOverride)

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 18, 2025

Code Review Agent Run #945160

Actionable Suggestions - 4
  • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go - 1
  • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager.go - 1
    • Potential nil pointer dereference in metadata · Line 115-116
  • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go - 2
Review Details
  • Files reviewed - 5 · Commit Range: b16b61e..3276d4d
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go
    • flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper_test.go
    • flytepropeller/pkg/apis/flyteworkflow/v1alpha1/mocks/ExecutableNode.go
    • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager.go
    • flytepropeller/pkg/controller/nodes/task/k8s/plugin_manager_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +234 to +236
ownerRef metav1.OwnerReference,
annotationsOverride map[string]string,
labelsOverride map[string]string) pluginsCore.TaskExecutionMetadata {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using struct for parameters

Consider updating the function signature to use a struct parameter instead of multiple parameters. The current signature with 8 parameters could be simplified using a configuration struct.

Code suggestion
Check the AI-generated fix before applying
 -func getMockTaskExecutionMetadataCustom(
 -    tid string,
 -    ns string,
 -    annotations map[string]string,
 -    labels map[string]string,
 -    ownerRef metav1.OwnerReference,
 -    annotationsOverride map[string]string,
 -    labelsOverride map[string]string) pluginsCore.TaskExecutionMetadata {
 +func getMockTaskExecutionMetadataCustom(config TaskMetadataConfig) pluginsCore.TaskExecutionMetadata {

Code Review Run #945160


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

  • it was incorrectly flagged

Comment on lines +115 to +116
o.SetAnnotations(pluginsUtils.UnionMaps(cfg.DefaultAnnotations, o.GetAnnotations(), pluginsUtils.CopyMap(taskCtx.GetAnnotations()), taskCtx.GetOverrides().GetPodTemplate().GetMetadata().GetAnnotations()))
o.SetLabels(pluginsUtils.UnionMaps(cfg.DefaultLabels, o.GetLabels(), pluginsUtils.CopyMap(taskCtx.GetLabels()), taskCtx.GetOverrides().GetPodTemplate().GetMetadata().GetLabels()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Potential nil pointer dereference in metadata

Consider handling potential nil pointer dereference when accessing pod template metadata. The code assumes taskCtx.GetOverrides().GetPodTemplate() returns non-nil values.

Code suggestion
Check the AI-generated fix before applying
Suggested change
o.SetAnnotations(pluginsUtils.UnionMaps(cfg.DefaultAnnotations, o.GetAnnotations(), pluginsUtils.CopyMap(taskCtx.GetAnnotations()), taskCtx.GetOverrides().GetPodTemplate().GetMetadata().GetAnnotations()))
o.SetLabels(pluginsUtils.UnionMaps(cfg.DefaultLabels, o.GetLabels(), pluginsUtils.CopyMap(taskCtx.GetLabels()), taskCtx.GetOverrides().GetPodTemplate().GetMetadata().GetLabels()))
podTemplateAnnotations := make(map[string]string)
podTemplateLabels := make(map[string]string)
if overrides := taskCtx.GetOverrides(); overrides != nil {
if podTemplate := overrides.GetPodTemplate(); podTemplate != nil {
if metadata := podTemplate.GetMetadata(); metadata != nil {
podTemplateAnnotations = metadata.GetAnnotations()
podTemplateLabels = metadata.GetLabels()
}
}
}
o.SetAnnotations(pluginsUtils.UnionMaps(cfg.DefaultAnnotations, o.GetAnnotations(), pluginsUtils.CopyMap(taskCtx.GetAnnotations()), podTemplateAnnotations))
o.SetLabels(pluginsUtils.UnionMaps(cfg.DefaultLabels, o.GetLabels(), pluginsUtils.CopyMap(taskCtx.GetLabels()), podTemplateLabels))

Code Review Run #945160


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

  • it was incorrectly flagged

Comment on lines +330 to +332
podSpec, err = ApplyPodTemplateOverride(tCtx.TaskExecutionMetadata().GetOverrides().GetPodTemplate())
if err != nil {
return nil, nil, "", err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider nil check before function call

Consider checking if podTemplate is not nil before calling ApplyPodTemplateOverride. The current code could potentially cause a nil pointer dereference.

Code suggestion
Check the AI-generated fix before applying
Suggested change
podSpec, err = ApplyPodTemplateOverride(tCtx.TaskExecutionMetadata().GetOverrides().GetPodTemplate())
if err != nil {
return nil, nil, "", err
if podTemplate := tCtx.TaskExecutionMetadata().GetOverrides().GetPodTemplate(); podTemplate != nil {
podSpec, err = ApplyPodTemplateOverride(podTemplate)
if err != nil {
return nil, nil, "", err
}
}

Code Review Run #945160


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

  • it was incorrectly flagged

Comment on lines +472 to +475
func ApplyPodTemplateOverride(podTemplate *core.K8SPod) (*v1.PodSpec, error) {
// metadata override will be implemented in plugin_manager.go
var podSpecOverride *v1.PodSpec
err := utils.UnmarshalStructToObj(podTemplate.GetPodSpec(), &podSpecOverride)
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 nil check for podTemplate

Consider adding validation for podTemplate being nil before accessing GetPodSpec()

Code suggestion
Check the AI-generated fix before applying
Suggested change
func ApplyPodTemplateOverride(podTemplate *core.K8SPod) (*v1.PodSpec, error) {
// metadata override will be implemented in plugin_manager.go
var podSpecOverride *v1.PodSpec
err := utils.UnmarshalStructToObj(podTemplate.GetPodSpec(), &podSpecOverride)
func ApplyPodTemplateOverride(podTemplate *core.K8SPod) (*v1.PodSpec, error) {
if podTemplate == nil {
return nil, fmt.Errorf("nil pod template provided")
}
// metadata override will be implemented in plugin_manager.go
var podSpecOverride *v1.PodSpec
err := utils.UnmarshalStructToObj(podTemplate.GetPodSpec(), &podSpecOverride)

Code Review Run #945160


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.

3 participants