Skip to content

Commit 17b5ad0

Browse files
committed
bugfix(k8s): skip false error in logs correctly
We have to use the canonical pause image or it won't match.
1 parent 270eddd commit 17b5ad0

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

runtime/kubernetes/container.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,9 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container)
5353

5454
// avoid a panic if the build ends without terminating all containers
5555
if cst.State.Terminated == nil {
56-
for _, container := range pod.Spec.Containers {
57-
if cst.Name != container.Name {
58-
continue
59-
}
60-
61-
// steps that were not executed will still be "running" the pause image as expected.
62-
if container.Image == pauseImage {
63-
return nil
64-
}
65-
66-
break
56+
// steps that were not executed will still be "running" the pause image as expected.
57+
if cst.Image == pauseImage || cst.Image == image.Parse(pauseImage) {
58+
return nil
6759
}
6860

6961
return fmt.Errorf("expected container %s to be terminated, got %v", ctn.ID, cst.State)

runtime/kubernetes/container_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/go-vela/types/pipeline"
13+
"github.com/go-vela/worker/internal/image"
1314
velav1alpha1 "github.com/go-vela/worker/runtime/kubernetes/apis/vela/v1alpha1"
1415

1516
v1 "k8s.io/api/core/v1"
@@ -52,6 +53,53 @@ func TestKubernetes_InspectContainer(t *testing.T) {
5253
State: v1.ContainerState{
5354
Running: &v1.ContainerStateRunning{},
5455
},
56+
Image: _container.Image,
57+
},
58+
},
59+
},
60+
},
61+
container: _container,
62+
},
63+
{
64+
name: "build stops before container execution with raw pauseImage",
65+
failure: false,
66+
pod: &v1.Pod{
67+
ObjectMeta: _pod.ObjectMeta,
68+
TypeMeta: _pod.TypeMeta,
69+
Spec: _pod.Spec,
70+
Status: v1.PodStatus{
71+
Phase: v1.PodRunning,
72+
ContainerStatuses: []v1.ContainerStatus{
73+
{
74+
Name: "step-github-octocat-1-clone",
75+
State: v1.ContainerState{
76+
Running: &v1.ContainerStateRunning{},
77+
},
78+
// container not patched yet with correct image
79+
Image: pauseImage,
80+
},
81+
},
82+
},
83+
},
84+
container: _container,
85+
},
86+
{
87+
name: "build stops before container execution with canonical pauseImage",
88+
failure: false,
89+
pod: &v1.Pod{
90+
ObjectMeta: _pod.ObjectMeta,
91+
TypeMeta: _pod.TypeMeta,
92+
Spec: _pod.Spec,
93+
Status: v1.PodStatus{
94+
Phase: v1.PodRunning,
95+
ContainerStatuses: []v1.ContainerStatus{
96+
{
97+
Name: "step-github-octocat-1-clone",
98+
State: v1.ContainerState{
99+
Running: &v1.ContainerStateRunning{},
100+
},
101+
// container not patched yet with correct image
102+
Image: image.Parse(pauseImage),
55103
},
56104
},
57105
},
@@ -411,6 +459,7 @@ func TestKubernetes_WaitContainer(t *testing.T) {
411459
ExitCode: 0,
412460
},
413461
},
462+
Image: "alpine:latest",
414463
},
415464
{
416465
Name: "step-github-octocat-1-clone",
@@ -420,6 +469,7 @@ func TestKubernetes_WaitContainer(t *testing.T) {
420469
ExitCode: 0,
421470
},
422471
},
472+
Image: "target/vela-git:v0.4.0",
423473
},
424474
},
425475
},

runtime/kubernetes/kubernetes_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ var (
106106
ExitCode: 0,
107107
},
108108
},
109+
Image: "target/vela-git:v0.4.0",
109110
},
110111
{
111112
Name: "step-github-octocat-1-echo",
@@ -115,6 +116,7 @@ var (
115116
ExitCode: 0,
116117
},
117118
},
119+
Image: "alpine:latest",
118120
},
119121
},
120122
},

0 commit comments

Comments
 (0)