Skip to content

Commit

Permalink
bugfix(k8s): skip false error in logs correctly (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Apr 28, 2022
1 parent c0823e8 commit 2a0efdd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
14 changes: 3 additions & 11 deletions runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,9 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container)

// avoid a panic if the build ends without terminating all containers
if cst.State.Terminated == nil {
for _, container := range pod.Spec.Containers {
if cst.Name != container.Name {
continue
}

// steps that were not executed will still be "running" the pause image as expected.
if container.Image == pauseImage {
return nil
}

break
// steps that were not executed will still be "running" the pause image as expected.
if cst.Image == pauseImage || cst.Image == image.Parse(pauseImage) {
return nil
}

return fmt.Errorf("expected container %s to be terminated, got %v", ctn.ID, cst.State)
Expand Down
50 changes: 50 additions & 0 deletions runtime/kubernetes/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/internal/image"
velav1alpha1 "github.com/go-vela/worker/runtime/kubernetes/apis/vela/v1alpha1"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -52,6 +53,53 @@ func TestKubernetes_InspectContainer(t *testing.T) {
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
Image: _container.Image,
},
},
},
},
container: _container,
},
{
name: "build stops before container execution with raw pauseImage",
failure: false,
pod: &v1.Pod{
ObjectMeta: _pod.ObjectMeta,
TypeMeta: _pod.TypeMeta,
Spec: _pod.Spec,
Status: v1.PodStatus{
Phase: v1.PodRunning,
ContainerStatuses: []v1.ContainerStatus{
{
Name: "step-github-octocat-1-clone",
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
// container not patched yet with correct image
Image: pauseImage,
},
},
},
},
container: _container,
},
{
name: "build stops before container execution with canonical pauseImage",
failure: false,
pod: &v1.Pod{
ObjectMeta: _pod.ObjectMeta,
TypeMeta: _pod.TypeMeta,
Spec: _pod.Spec,
Status: v1.PodStatus{
Phase: v1.PodRunning,
ContainerStatuses: []v1.ContainerStatus{
{
Name: "step-github-octocat-1-clone",
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
// container not patched yet with correct image
Image: image.Parse(pauseImage),
},
},
},
Expand Down Expand Up @@ -411,6 +459,7 @@ func TestKubernetes_WaitContainer(t *testing.T) {
ExitCode: 0,
},
},
Image: "alpine:latest",
},
{
Name: "step-github-octocat-1-clone",
Expand All @@ -420,6 +469,7 @@ func TestKubernetes_WaitContainer(t *testing.T) {
ExitCode: 0,
},
},
Image: "target/vela-git:v0.4.0",
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions runtime/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var (
ExitCode: 0,
},
},
Image: "target/vela-git:v0.4.0",
},
{
Name: "step-github-octocat-1-echo",
Expand All @@ -115,6 +116,7 @@ var (
ExitCode: 0,
},
},
Image: "alpine:latest",
},
},
},
Expand Down

0 comments on commit 2a0efdd

Please sign in to comment.