Skip to content

Commit

Permalink
Filter out docker containers for pods in the kube-system namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie authored and tomwilkie committed May 6, 2016
1 parent 3e7dd1a commit 2315630
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func IsApplication(n report.Node) bool {
if roleLabel == "system" {
return false
}
namespace, _ := n.Latest.Lookup(kubernetes.Namespace)
namespace, _ := n.Latest.Lookup(docker.LabelPrefix + "io.kubernetes.pod.namespace")
if namespace == "kube-system" {
return false
}
Expand Down Expand Up @@ -278,8 +278,8 @@ func HasChildren(topology string) FilterFunc {
// IsNamespace checks if the node is a pod/service in the specified namespace
func IsNamespace(namespace string) FilterFunc {
return func(n report.Node) bool {
gotNamespace, ok := n.Latest.Lookup(kubernetes.Namespace)
return !ok || namespace == gotNamespace
gotNamespace, _ := n.Latest.Lookup(kubernetes.Namespace)
return namespace == gotNamespace
}
}

Expand Down
20 changes: 9 additions & 11 deletions render/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package render_test
import (
"testing"

"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/render/expected"
Expand All @@ -20,22 +19,20 @@ func TestPodRenderer(t *testing.T) {
}
}

func filterNonKubeSystem(renderer render.Renderer) render.Renderer {
return render.MakeFilter(render.Complement(render.IsNamespace("kube-system")), renderer)
}

func TestPodFilterRenderer(t *testing.T) {
// tag on containers or pod namespace in the topology and ensure
// it is filtered out correctly.
input := fixture.Report.Copy()
input.Pod.Nodes[fixture.ClientPodNodeID] = input.Pod.Nodes[fixture.ClientPodNodeID].WithLatests(map[string]string{
kubernetes.PodID: "kube-system/foo",
kubernetes.Namespace: "kube-system",
kubernetes.PodName: "foo",
})
input.Container.Nodes[fixture.ClientContainerNodeID] = input.Container.Nodes[fixture.ClientContainerNodeID].WithLatests(map[string]string{
docker.LabelPrefix + "io.kubernetes.pod.name": "kube-system/foo",
})
have := Prune(render.PodRenderer.Render(input, render.FilterApplication))
have := Prune(render.PodRenderer.Render(input, filterNonKubeSystem))
want := Prune(expected.RenderedPods.Copy())
delete(want, fixture.ClientPodNodeID)
delete(want, fixture.ClientContainerNodeID)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
Expand All @@ -53,12 +50,13 @@ func TestPodServiceFilterRenderer(t *testing.T) {
// tag on containers or pod namespace in the topology and ensure
// it is filtered out correctly.
input := fixture.Report.Copy()
have := Prune(render.PodServiceRenderer.Render(input, render.FilterSystem))
input.Service.Nodes[fixture.ServiceNodeID] = input.Service.Nodes[fixture.ServiceNodeID].WithLatests(map[string]string{
kubernetes.Namespace: "kube-system",
})
have := Prune(render.PodServiceRenderer.Render(input, filterNonKubeSystem))
want := Prune(expected.RenderedPodServices.Copy())
delete(want, fixture.ServiceNodeID)
delete(want, expected.UnmanagedServerID)
delete(want, render.IncomingInternetID)
delete(want, render.OutgoingInternetID)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
Expand Down

0 comments on commit 2315630

Please sign in to comment.