From b83f7e8ce62aead5592e7ad2529cef91a8924a43 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 21 Dec 2017 15:23:13 +0000 Subject: [PATCH] render sensible labels for images with little/no metadata We fall back to image id when we cannot find a name. We extract the image id from the node id rather than the docker.ImageID latest map entry since that way we are guaranteed to get it. --- render/detailed/summary.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/render/detailed/summary.go b/render/detailed/summary.go index 27e8292a7..e46e9b7df 100644 --- a/render/detailed/summary.go +++ b/render/detailed/summary.go @@ -243,25 +243,24 @@ func containerNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) { } func containerImageNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) { - imageName, ok := n.Latest.Lookup(docker.ImageName) - if !ok { - return NodeSummary{}, false + var ( + imageName, _ = n.Latest.Lookup(docker.ImageName) + imageNameWithoutVersion = docker.ImageNameWithoutVersion(imageName) + ) + switch { + case imageNameWithoutVersion != "" && imageNameWithoutVersion != ImageNameNone: + base.Label = imageNameWithoutVersion + case imageName != "" && imageName != ImageNameNone: + base.Label = imageName + default: + // The id can be an image id or an image name. Ideally we'd + // truncate the former but not the latter, but short of + // heuristic regexp match we cannot tell the difference. + base.Label, _ = report.ParseContainerImageNodeID(n.ID) } - - imageNameWithoutVersion := docker.ImageNameWithoutVersion(imageName) - base.Label = imageNameWithoutVersion - base.Rank = imageNameWithoutVersion - base.Stack = true - - if base.Label == ImageNameNone { - base.Label, _ = n.Latest.Lookup(docker.ImageID) - if len(base.Label) > 12 { - base.Label = base.Label[:12] - } - } - base.LabelMinor = pluralize(n.Counters, report.Container, "container", "containers") - + base.Rank = base.Label + base.Stack = true return base, true }