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

[WIP] [TEST] Testing the behaviour when primary container name is different to the one in basePodSpec #6250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
111 changes: 111 additions & 0 deletions flyteplugins/go/tasks/pluginmachinery/flytek8s/pod_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,117 @@ func TestMergePodSpecs(t *testing.T) {
assert.Equal(t, defaultInitContainerTemplate.TerminationMessagePath, defaultInitContainer.TerminationMessagePath)
}

func TestMergePodSpecsPrimaryContainerName(t *testing.T) {

basePodSpec := v1.PodSpec{
Containers: []v1.Container{
v1.Container{
Name: "primary",
VolumeMounts: []v1.VolumeMount{
{
Name: "nccl",
MountPath: "abc",
},
},
Env: []v1.EnvVar{
{Name: "EnvVar", Value: "EnvVal"},
},
},
v1.Container{
Name: "bar",
},
},
InitContainers: []v1.Container{
v1.Container{
Name: "primary-init",
VolumeMounts: []v1.VolumeMount{
{
Name: "nccl",
MountPath: "abc",
},
},
},
v1.Container{
Name: "bar-init",
},
},
Tolerations: []v1.Toleration{
v1.Toleration{
Key: "bar",
},
v1.Toleration{
Key: "baz",
},
},
}

podSpec := v1.PodSpec{
Containers: []v1.Container{
v1.Container{
Name: "primary-new",
VolumeMounts: []v1.VolumeMount{
{
Name: "nccl-new",
MountPath: "abc-new",
},
},
Env: []v1.EnvVar{
{Name: "EnvVar", Value: "EnvVal"},
},
},
v1.Container{
Name: "bar-new",
},
},
InitContainers: []v1.Container{
v1.Container{
Name: "primary-init-new",
VolumeMounts: []v1.VolumeMount{
{
Name: "nccl-new",
MountPath: "abc-new",
},
},
},
v1.Container{
Name: "bar-init-new",
},
},
Tolerations: []v1.Toleration{
v1.Toleration{
Key: "bar-new",
},
v1.Toleration{
Key: "baz-new",
},
},
}

// primary (init) container name different from basePodSpec
mergedPodSpec, err := MergePodSpecs(&basePodSpec, &podSpec, "primary-new", "primary-init-new")
assert.Nil(t, err)

// validate an appended array
assert.Equal(t, len(basePodSpec.Tolerations)+len(podSpec.Tolerations), len(mergedPodSpec.Tolerations))

// validate primary container, should exclude the one in basePodSpec
primaryContainer := mergedPodSpec.Containers[0]
assert.Equal(t, podSpec.Containers[0].Name, primaryContainer.Name)
// this will also contain the one from basePodSpec
assert.Equal(t, 2, len(primaryContainer.VolumeMounts))
assert.Equal(t, 2, len(primaryContainer.Env))

// WARN: the other container in podSpec is also included
assert.Equal(t, 2, len(mergedPodSpec.Containers))
assert.Equal(t, mergedPodSpec.Containers[1].Name, podSpec.Containers[1].Name)

// validate primary init container
primaryInitContainer := mergedPodSpec.InitContainers[0]
assert.Equal(t, podSpec.InitContainers[0].Name, primaryInitContainer.Name)
// this will also contain the one from basePodSpec
assert.Equal(t, 2, len(primaryInitContainer.VolumeMounts))
}

func TestAddFlyteCustomizationsToContainer_SetConsoleUrl(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading