Merge pull request #24533 from yongtang/24392-docker-info-label-duplicate-keys

Remove duplicate keys in labels of `docker info`
This commit is contained in:
Sebastiaan van Stijn 2016-10-24 18:12:28 -07:00 committed by GitHub
commit f039ba83d0
1 changed files with 15 additions and 0 deletions

View File

@ -223,6 +223,21 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
for _, attribute := range info.Labels { for _, attribute := range info.Labels {
fmt.Fprintf(dockerCli.Out(), " %s\n", attribute) fmt.Fprintf(dockerCli.Out(), " %s\n", attribute)
} }
// TODO: Engine labels with duplicate keys has been deprecated in 1.13 and will be error out
// after 3 release cycles (1.16). For now, a WARNING will be generated. The following will
// be removed eventually.
labelMap := map[string]string{}
for _, label := range info.Labels {
stringSlice := strings.SplitN(label, "=", 2)
if len(stringSlice) > 1 {
// If there is a conflict we will throw out an warning
if v, ok := labelMap[stringSlice[0]]; ok && v != stringSlice[1] {
fmt.Fprintln(dockerCli.Err(), "WARNING: labels with duplicate keys and conflicting values have been deprecated")
break
}
labelMap[stringSlice[0]] = stringSlice[1]
}
}
} }
fmt.Fprintf(dockerCli.Out(), "Experimental: %v\n", info.ExperimentalBuild) fmt.Fprintf(dockerCli.Out(), "Experimental: %v\n", info.ExperimentalBuild)