mirror of https://github.com/docker/cli.git
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:
commit
f039ba83d0
|
@ -223,6 +223,21 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
|
|||
for _, attribute := range info.Labels {
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue