Skip to content
Open
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
14 changes: 14 additions & 0 deletions integration/testdata/verify-fail-k8s/failing-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: batch/v1
kind: Job
metadata:
name: failing-job-manifest
spec:
backoffLimit: 0
template:
spec:
containers:
- name: failing-job-manifest
image: alpine:3.15.4
command: ["/bin/sh"]
args: ["-c", "echo failure from job manifest; exit 1"]
restartPolicy: Never
12 changes: 11 additions & 1 deletion integration/testdata/verify-fail-k8s/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ verify:
kubernetesCluster: {}

profiles:
- name: with-failing-job-manifest
verify:
- name: failing-job-manifest
executionMode:
kubernetesCluster:
jobManifestPath: failing-job.yaml
container:
name: failing-job-manifest
image: alpine:3.15.4

- name: no-duplicated-logs
verify:
- name: alpine-1
Expand Down Expand Up @@ -88,4 +98,4 @@ profiles:
name: alpine-7
image: alpine:3.15.4
command: ["/bin/sh"]
args: ["-c", "echo alpine-7; sleep 15; echo bye alpine-7"]
args: ["-c", "echo alpine-7; sleep 15; echo bye alpine-7"]
9 changes: 9 additions & 0 deletions integration/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func TestKubernetesJobVerifyEnvVarFromJobManifest(t *testing.T) {
testutil.CheckContains(t, "ZZZ with-job-manifest", logs)
}

func TestKubernetesJobVerifyFailureFromJobManifest(t *testing.T) {
MarkIntegrationTest(t, CanRunWithoutGcp)

out, err := skaffold.Verify("--default-repo=", "-p", "with-failing-job-manifest").InDir("testdata/verify-fail-k8s").RunWithCombinedOutput(t)

testutil.CheckError(t, true, err)
testutil.CheckContains(t, "failure from job manifest", string(out))
}

func TestKubernetesJobVerifyOneTestFailsWithEnvVar(t *testing.T) {
MarkIntegrationTest(t, CanRunWithoutGcp)
tmp := t.TempDir()
Expand Down
8 changes: 6 additions & 2 deletions pkg/skaffold/verify/k8sjob/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,12 @@ func (v *Verifier) createJobFromManifestPath(jobName string, container latest.Ve

func patchToK8sContainer(container latest.VerifyContainer, dst *corev1.Container) {
dst.Image = container.Image
dst.Command = container.Command
dst.Args = container.Args
if container.Command != nil {
dst.Command = container.Command
}
if container.Args != nil {
dst.Args = container.Args
}
dst.Name = container.Name

for _, e := range container.Env {
Expand Down
40 changes: 40 additions & 0 deletions pkg/skaffold/verify/k8sjob/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,46 @@ func TestPatchToK8sContainer(t *testing.T) {
Args: []string{"-l"},
},
},
{
description: "preserve command and args when not configured",
verifyContainer: latest.VerifyContainer{
Name: "my-container",
Image: "my-new-image:latest",
},
k8sContainer: corev1.Container{
Name: "my-container",
Image: "my-image:latest",
Command: []string{"/bin/sh"},
Args: []string{"-c", "exit 1"},
},
expected: corev1.Container{
Name: "my-container",
Image: "my-new-image:latest",
Command: []string{"/bin/sh"},
Args: []string{"-c", "exit 1"},
},
},
{
description: "clear command and args when explicitly configured empty",
verifyContainer: latest.VerifyContainer{
Name: "my-container",
Image: "my-image:latest",
Command: []string{},
Args: []string{},
},
k8sContainer: corev1.Container{
Name: "my-container",
Image: "my-image:latest",
Command: []string{"/bin/sh"},
Args: []string{"-c", "exit 1"},
},
expected: corev1.Container{
Name: "my-container",
Image: "my-image:latest",
Command: []string{},
Args: []string{},
},
},
{
description: "update name",
verifyContainer: latest.VerifyContainer{
Expand Down