Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that the image is already in cst so we don't need to look it up. That simplified this logic quite a bit.

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