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

extend pod customization to include init containers #5685

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@
IncludeConsoleURL: hasExternalLinkType(taskTemplate),
}

// iterate over the initContainers first
for index := range podSpec.InitContainers {
samhita-alla marked this conversation as resolved.
Show resolved Hide resolved
var resourceMode = ResourceCustomizationModeEnsureExistingResourcesInRange

Check warning on line 353 in flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go#L353

Added line #L353 was not covered by tests

if err := AddFlyteCustomizationsToContainer(ctx, templateParameters, resourceMode, &podSpec.InitContainers[index]); err != nil {
return nil, nil, err

Check warning on line 356 in flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper.go#L355-L356

Added lines #L355 - L356 were not covered by tests
}
}

resourceRequests := make([]v1.ResourceRequirements, 0, len(podSpec.Containers))
var primaryContainer *v1.Container
for index, container := range podSpec.Containers {
Expand Down
16 changes: 16 additions & 0 deletions flyteplugins/go/tasks/plugins/k8s/pod/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func dummyContainerTaskTemplate(command []string, args []string) *core.TaskTempl
func dummyContainerTaskTemplateWithPodSpec(command []string, args []string) *core.TaskTemplate {

podSpec := v1.PodSpec{
InitContainers: []v1.Container{
v1.Container{
Name: "test-image",
Command: command,
Args: args,
},
},
Containers: []v1.Container{
v1.Container{
Name: "test-image",
Expand Down Expand Up @@ -174,24 +181,28 @@ func TestContainerTaskExecutor_BuildResource(t *testing.T) {
taskTemplate *core.TaskTemplate
taskMetadata pluginsCore.TaskExecutionMetadata
expectServiceAccount string
checkInitContainer bool
}{
{
name: "BuildResource",
taskTemplate: dummyContainerTaskTemplate(command, args),
taskMetadata: dummyContainerTaskMetadata(containerResourceRequirements, nil, true, ""),
expectServiceAccount: serviceAccount,
checkInitContainer: false,
},
{
name: "BuildResource_PodTemplate",
taskTemplate: dummyContainerTaskTemplateWithPodSpec(command, args),
taskMetadata: dummyContainerTaskMetadata(containerResourceRequirements, nil, true, ""),
expectServiceAccount: podTemplateServiceAccount,
checkInitContainer: true,
},
{
name: "BuildResource_SecurityContext",
taskTemplate: dummyContainerTaskTemplate(command, args),
taskMetadata: dummyContainerTaskMetadata(containerResourceRequirements, nil, false, ""),
expectServiceAccount: securityContextServiceAccount,
checkInitContainer: false,
},
}
for _, tc := range testCases {
Expand All @@ -213,6 +224,11 @@ func TestContainerTaskExecutor_BuildResource(t *testing.T) {
assert.Equal(t, command, j.Spec.Containers[0].Command)
assert.Equal(t, []string{"test-data-reference"}, j.Spec.Containers[0].Args)

if tc.checkInitContainer {
assert.Equal(t, command, j.Spec.InitContainers[0].Command)
assert.Equal(t, []string{"test-data-reference"}, j.Spec.InitContainers[0].Args)
}

assert.Equal(t, tc.expectServiceAccount, j.Spec.ServiceAccountName)
})
}
Expand Down
Loading