Report/render both image and container labels

Daemon labels will have to wait since the go client (Docker API v1.14) doesn't support
them yet (daemon labels were exposed in Docker API v1.16)

See https://godoc.org/github.com/fsouza/go-dockerclient#Client.Info for details.
This commit is contained in:
Alfonso Acosta
2015-08-26 16:41:42 +00:00
parent 529aa3d84f
commit 9ba37402cf
6 changed files with 91 additions and 44 deletions

View File

@@ -312,11 +312,7 @@ func containerOriginTable(nmd report.NodeMetadata, addHostTag bool) (Table, bool
for _, ip := range docker.ExtractContainerIPs(nmd) {
rows = append(rows, Row{Key: "IP Address", ValueMajor: ip, ValueMinor: ""})
}
for labelKey, labelValue := range docker.ExtractContainerLabels(nmd) {
rows = append(rows, Row{Key: fmt.Sprintf("Label %q", labelKey), ValueMajor: labelValue})
}
rows = append(rows, getDockerLabelRows(nmd)...)
if val, ok := nmd.Metadata[docker.MemoryUsage]; ok {
memory, err := strconv.ParseFloat(val, 64)
@@ -354,6 +350,7 @@ func containerImageOriginTable(nmd report.NodeMetadata) (Table, bool) {
rows = append(rows, Row{Key: tuple.human, ValueMajor: val, ValueMinor: ""})
}
}
rows = append(rows, getDockerLabelRows(nmd)...)
title := "Container Image"
var (
nameFound bool
@@ -370,6 +367,21 @@ func containerImageOriginTable(nmd report.NodeMetadata) (Table, bool) {
}, len(rows) > 0 || nameFound
}
func getDockerLabelRows(nmd report.NodeMetadata) []Row {
rows := []Row{}
// Add labels in alphabetical order
labels := docker.ExtractLabels(nmd)
labelKeys := make([]string, 0, len(labels))
for k := range labels {
labelKeys = append(labelKeys, k)
}
sort.Strings(labelKeys)
for _, labelKey := range labelKeys {
rows = append(rows, Row{Key: fmt.Sprintf("Label %q", labelKey), ValueMajor: labels[labelKey]})
}
return rows
}
func hostOriginTable(nmd report.NodeMetadata) (Table, bool) {
rows := []Row{}
for _, tuple := range []struct{ key, human string }{