Skip to content

Commit

Permalink
Also match init containers when selecting pods
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jun 28, 2019
1 parent a59f050 commit 580078b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/skaffold/kubernetes/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (l *ImageList) Select(pod *v1.Pod) bool {
l.RLock()
defer l.RUnlock()

for _, container := range pod.Spec.Containers {
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
if l.names[container.Image] {
return true
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/skaffold/kubernetes/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/GoogleContainerTools/skaffold/testutil"
v1 "k8s.io/api/core/v1"
)

func TestSinceSeconds(t *testing.T) {
Expand Down Expand Up @@ -49,3 +50,41 @@ func TestSinceSeconds(t *testing.T) {
})
}
}

func TestSelect(t *testing.T) {
var tests = []struct {
description string
images []string
podSpec v1.PodSpec
expectedMatch bool
}{
{
description: "match container",
podSpec: v1.PodSpec{Containers: []v1.Container{{Image: "image1"}}},
expectedMatch: true,
},
{
description: "match init container",
podSpec: v1.PodSpec{InitContainers: []v1.Container{{Image: "image2"}}},
expectedMatch: true,
},
{
description: "no match",
podSpec: v1.PodSpec{Containers: []v1.Container{{Image: "image3"}}},
expectedMatch: false,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
list := NewImageList()
list.Add("image1")
list.Add("image2")

selected := list.Select(&v1.Pod{
Spec: test.podSpec,
})

t.CheckDeepEqual(test.expectedMatch, selected)
})
}
}

0 comments on commit 580078b

Please sign in to comment.