-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update the k8s Job container logic for custom actions to match v… (
#9584) * fix: Update the k8s Job container logic for custom actions to match verify * chore: add license to new test file * chore: adjust import order to address linter errors * chore: fix license formatting in new test file
- Loading branch information
Showing
2 changed files
with
158 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
Copyright 2024 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package k8sjob | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/GoogleContainerTools/skaffold/v2/testutil" | ||
) | ||
|
||
func TestPatchToK8sContainer(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
actionContainer corev1.Container | ||
k8sContainer corev1.Container | ||
expected corev1.Container | ||
}{ | ||
{ | ||
description: "update all fields", | ||
actionContainer: corev1.Container{ | ||
Image: "my-image:latest", | ||
Command: []string{"/bin/bash"}, | ||
Args: []string{"-c", "echo hello world"}, | ||
Name: "my-container", | ||
Env: []corev1.EnvVar{ | ||
{Name: "FOO", Value: "BAR"}, | ||
}, | ||
}, | ||
k8sContainer: corev1.Container{}, | ||
expected: corev1.Container{ | ||
Image: "my-image:latest", | ||
Command: []string{"/bin/bash"}, | ||
Args: []string{"-c", "echo hello world"}, | ||
Name: "my-container", | ||
Env: []corev1.EnvVar{ | ||
{Name: "FOO", Value: "BAR"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "update image", | ||
actionContainer: corev1.Container{ | ||
Image: "my-new-image:latest", | ||
}, | ||
k8sContainer: corev1.Container{ | ||
Image: "my-image:latest", | ||
}, | ||
expected: corev1.Container{ | ||
Image: "my-new-image:latest", | ||
}, | ||
}, | ||
{ | ||
description: "update command", | ||
actionContainer: corev1.Container{ | ||
Command: []string{"/bin/ls"}, | ||
}, | ||
k8sContainer: corev1.Container{ | ||
Command: []string{"/bin/bash"}, | ||
}, | ||
expected: corev1.Container{ | ||
Command: []string{"/bin/ls"}, | ||
}, | ||
}, | ||
{ | ||
description: "update args", | ||
actionContainer: corev1.Container{ | ||
Args: []string{"-l"}, | ||
}, | ||
k8sContainer: corev1.Container{ | ||
Args: []string{"-c", "echo hello world"}, | ||
}, | ||
expected: corev1.Container{ | ||
Args: []string{"-l"}, | ||
}, | ||
}, | ||
{ | ||
description: "update name", | ||
actionContainer: corev1.Container{ | ||
Name: "my-new-container", | ||
}, | ||
k8sContainer: corev1.Container{ | ||
Name: "my-container", | ||
}, | ||
expected: corev1.Container{ | ||
Name: "my-new-container", | ||
}, | ||
}, | ||
{ | ||
description: "update env", | ||
actionContainer: corev1.Container{ | ||
Env: []corev1.EnvVar{ | ||
{Name: "FOO", Value: "BARR"}, | ||
{Name: "BAZ", Value: "QUX"}, | ||
}, | ||
}, | ||
k8sContainer: corev1.Container{ | ||
Env: []corev1.EnvVar{ | ||
{Name: "FOO", Value: "BAR"}, | ||
}, | ||
}, | ||
// Duplicate name should be ok, as the last writer should win. | ||
expected: corev1.Container{ | ||
Env: []corev1.EnvVar{ | ||
{Name: "FOO", Value: "BAR"}, | ||
{Name: "FOO", Value: "BARR"}, | ||
{Name: "BAZ", Value: "QUX"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
patchToK8sContainer(test.actionContainer, &test.k8sContainer) | ||
t.CheckDeepEqual(test.expected, test.k8sContainer) | ||
}) | ||
} | ||
} |