Show image tag separate from image name in Node Details.

This commit is contained in:
Filip Barl
2018-05-15 15:52:41 +02:00
parent 0b3ee4647a
commit 4382deb39b
4 changed files with 35 additions and 18 deletions

View File

@@ -472,13 +472,21 @@ func (r *registry) WalkNetworks(f func(docker_client.Network)) {
}
}
// ImageNameWithoutVersion splits the image name apart, returning the name
// without the version, if possible
func ImageNameWithoutVersion(name string) string {
func ImageNameParts(name string) []string {
parts := strings.SplitN(name, "/", 3)
if len(parts) == 3 {
name = fmt.Sprintf("%s/%s", parts[1], parts[2])
}
parts = strings.SplitN(name, ":", 2)
return parts[0]
return strings.SplitN(name, ":", 2)
}
// ImageNameWithoutVersion splits the image name apart, returning the name
// without the version, if possible
func ImageNameWithoutVersion(name string) string {
return ImageNameParts(name)[0]
}
// ImageNameVersion splits the image name apart, returning the version, if possible
func ImageNameVersion(name string) string {
return ImageNameParts(name)[1]
}

View File

@@ -16,6 +16,7 @@ import (
const (
ImageID = report.DockerImageID
ImageName = report.DockerImageName
ImageTag = report.DockerImageTag
ImageSize = report.DockerImageSize
ImageVirtualSize = report.DockerImageVirtualSize
IsInHostNetwork = report.DockerIsInHostNetwork
@@ -29,16 +30,17 @@ const (
// Exposed for testing
var (
ContainerMetadataTemplates = report.MetadataTemplates{
ImageName: {ID: ImageName, Label: "Image", From: report.FromLatest, Priority: 1},
ContainerCommand: {ID: ContainerCommand, Label: "Command", From: report.FromLatest, Priority: 2},
ContainerStateHuman: {ID: ContainerStateHuman, Label: "State", From: report.FromLatest, Priority: 3},
ContainerUptime: {ID: ContainerUptime, Label: "Uptime", From: report.FromLatest, Priority: 4, Datatype: report.Duration},
ContainerRestartCount: {ID: ContainerRestartCount, Label: "Restart #", From: report.FromLatest, Priority: 5},
ContainerNetworks: {ID: ContainerNetworks, Label: "Networks", From: report.FromSets, Priority: 6},
ContainerIPs: {ID: ContainerIPs, Label: "IPs", From: report.FromSets, Priority: 7},
ContainerPorts: {ID: ContainerPorts, Label: "Ports", From: report.FromSets, Priority: 8},
ContainerCreated: {ID: ContainerCreated, Label: "Created", From: report.FromLatest, Datatype: report.DateTime, Priority: 9},
ContainerID: {ID: ContainerID, Label: "ID", From: report.FromLatest, Truncate: 12, Priority: 10},
ImageTag: {ID: ImageTag, Label: "Image tag", From: report.FromLatest, Priority: 1},
ImageName: {ID: ImageName, Label: "Image name", From: report.FromLatest, Priority: 2},
ContainerCommand: {ID: ContainerCommand, Label: "Command", From: report.FromLatest, Priority: 3},
ContainerStateHuman: {ID: ContainerStateHuman, Label: "State", From: report.FromLatest, Priority: 4},
ContainerUptime: {ID: ContainerUptime, Label: "Uptime", From: report.FromLatest, Priority: 5, Datatype: report.Duration},
ContainerRestartCount: {ID: ContainerRestartCount, Label: "Restart #", From: report.FromLatest, Priority: 6},
ContainerNetworks: {ID: ContainerNetworks, Label: "Networks", From: report.FromSets, Priority: 7},
ContainerIPs: {ID: ContainerIPs, Label: "IPs", From: report.FromSets, Priority: 8},
ContainerPorts: {ID: ContainerPorts, Label: "Ports", From: report.FromSets, Priority: 9},
ContainerCreated: {ID: ContainerCreated, Label: "Created", From: report.FromLatest, Datatype: report.DateTime, Priority: 10},
ContainerID: {ID: ContainerID, Label: "ID", From: report.FromLatest, Truncate: 12, Priority: 11},
}
ContainerMetricTemplates = report.MetricTemplates{
@@ -56,8 +58,10 @@ var (
Label: "Image",
Type: report.PropertyListType,
FixedRows: map[string]string{
ImageID: "ID",
ImageName: "Name",
// Prepend spaces as a hack to keep at the top when sorted.
ImageID: " ID",
ImageName: " Name",
ImageTag: " Tag",
ImageSize: "Size",
ImageVirtualSize: "Virtual Size",
},
@@ -278,7 +282,9 @@ func (r *Reporter) containerImageTopology() report.Topology {
ImageVirtualSize: humanize.Bytes(uint64(image.VirtualSize)),
}
if len(image.RepoTags) > 0 {
latests[ImageName] = image.RepoTags[0]
imageFullName := image.RepoTags[0]
latests[ImageName] = ImageNameWithoutVersion(imageFullName)
latests[ImageTag] = ImageNameVersion(imageFullName)
}
nodeID := report.MakeContainerImageNodeID(imageID)
node := report.MakeNodeWith(nodeID, latests)

View File

@@ -144,6 +144,7 @@ func (r containerWithImageNameRenderer) Render(rpt report.Report) Nodes {
imageNodeID := report.MakeContainerImageNodeID(imageNameWithoutVersion)
c = propagateLatest(docker.ImageName, image, c)
c = propagateLatest(docker.ImageTag, image, c)
c = propagateLatest(docker.ImageSize, image, c)
c = propagateLatest(docker.ImageVirtualSize, image, c)
c = propagateLatest(docker.ImageLabelPrefix+"works.weave.role", image, c)

View File

@@ -16,6 +16,7 @@ const (
DockerContainerID = "docker_container_id"
DockerImageID = "docker_image_id"
DockerImageName = "docker_image_name"
DockerImageTag = "docker_image_tag"
DockerImageSize = "docker_image_size"
DockerImageVirtualSize = "docker_image_virtual_size"
DockerIsInHostNetwork = "docker_is_in_host_network"
@@ -121,6 +122,7 @@ var commonKeys = map[string]string{
DockerContainerID: DockerContainerID,
DockerImageID: DockerImageID,
DockerImageName: DockerImageName,
DockerImageTag: DockerImageTag,
DockerImageSize: DockerImageSize,
DockerImageVirtualSize: DockerImageVirtualSize,
DockerIsInHostNetwork: DockerIsInHostNetwork,