Skip to content

Commit 53297eb

Browse files
authored
Merge pull request #3743 from weaveworks/more-pause
kubernetes: detect more 'pause' containers
2 parents a375a54 + 880daa7 commit 53297eb

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

probe/kubernetes/reporter.go

+4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ func (r *Reporter) podEvent(e Event, pod Pod) {
248248
}
249249

250250
func isPauseContainer(n report.Node, rpt report.Report) bool {
251+
k8sContainerType, _ := n.Latest.Lookup(report.DockerLabelPrefix + "io.kubernetes.docker.type")
252+
if k8sContainerType == "podsandbox" { // this label is added by dockershim
253+
return true
254+
}
251255
containerImageIDs, ok := n.Parents.Lookup(report.ContainerImage)
252256
if !ok {
253257
return false

probe/kubernetes/reporter_test.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,48 @@ func BenchmarkReporter(b *testing.B) {
347347

348348
func TestTagger(t *testing.T) {
349349
rpt := report.MakeReport()
350+
rpt.ContainerImage.AddNode(report.MakeNodeWith("image1", map[string]string{
351+
docker.ImageName: "weaveworks/some_interesting_image",
352+
}))
353+
rpt.ContainerImage.AddNode(report.MakeNodeWith("pause_image", map[string]string{
354+
docker.ImageName: "google_containers/pause",
355+
}))
350356
rpt.Container.AddNode(report.MakeNodeWith("container1", map[string]string{
351357
docker.LabelPrefix + "io.kubernetes.pod.uid": "123456",
358+
}).WithParent(report.ContainerImage, "image1"))
359+
// This is the first way that Scope identified a pause container - via image name
360+
rpt.Container.AddNode(report.MakeNodeWith("container2", map[string]string{
361+
docker.LabelPrefix + "io.kubernetes.pod.uid": "123456",
362+
}).WithParent(report.ContainerImage, "pause_image"))
363+
// Second way that Scope identifies a pause container - via docker.type label
364+
rpt.Container.AddNode(report.MakeNodeWith("container3", map[string]string{
365+
docker.LabelPrefix + "io.kubernetes.pod.uid": "123456",
366+
docker.LabelPrefix + "io.kubernetes.docker.type": "podsandbox",
352367
}))
353368

354369
rpt, err := (&kubernetes.Tagger{}).Tag(rpt)
355370
if err != nil {
356371
t.Errorf("Unexpected error: %v", err)
357372
}
358373

359-
have, ok := rpt.Container.Nodes["container1"].Parents.Lookup(report.Pod)
374+
podParents, ok := rpt.Container.Nodes["container1"].Parents.Lookup(report.Pod)
360375
want := report.MakeStringSet(report.MakePodNodeID("123456"))
361-
if !ok || !reflect.DeepEqual(have, want) {
362-
t.Errorf("Expected container to have pod parent %v %v", have, want)
376+
if !ok || !reflect.DeepEqual(podParents, want) {
377+
t.Errorf("Expected container1 to have pod parent %v %v", podParents, want)
378+
}
379+
_, ok = rpt.Container.Nodes["container1"].Latest.Lookup(report.DoesNotMakeConnections)
380+
if ok {
381+
t.Errorf("Expected container1 not to have DoesNotMakeConnections flag")
382+
}
383+
384+
_, ok = rpt.Container.Nodes["container2"].Latest.Lookup(report.DoesNotMakeConnections)
385+
if !ok {
386+
t.Errorf("Expected pause container to have DoesNotMakeConnections flag")
387+
}
388+
389+
_, ok = rpt.Container.Nodes["container3"].Latest.Lookup(report.DoesNotMakeConnections)
390+
if !ok {
391+
t.Errorf("Expected pause container to have DoesNotMakeConnections flag")
363392
}
364393
}
365394

render/filters.go

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ func IsApplication(n report.Node) bool {
245245
if _, ok := systemImagePrefixes[imagePrefix]; ok || report.IsPauseImageName(imagePrefix) {
246246
return false
247247
}
248+
k8sContainerType, _ := n.Latest.Lookup(report.DockerLabelPrefix + "io.kubernetes.docker.type")
249+
if k8sContainerType == "podsandbox" { // another way to detect "pause container"
250+
return false
251+
}
248252
roleLabel, _ := n.Latest.Lookup(report.DockerLabelPrefix + "works.weave.role")
249253
if roleLabel == "system" {
250254
return false

0 commit comments

Comments
 (0)