mirror of https://github.com/docker/cli.git
Remove duplicate keys in labels of `docker info`
This fix tries to address the issue raised in 24392 where labels with duplicate keys exist in `docker info`, which contradicts with the specifications in the docs. The reason for duplicate keys is that labels are stored as slice of strings in the format of `A=B` (and the input/output). This fix tries to address this issue by checking conflict labels when daemon started, and remove duplicate labels (K-V). The existing `/info` API has not been changed. An additional integration test has been added to cover the changes in this fix. This fix fixes 24392. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
879b4d1fba
commit
805f669512
|
@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ioutils.FprintfIfTrue(dockerCli.Out(), "Experimental: %v\n", info.ExperimentalBuild)
|
||||
|
|
Loading…
Reference in New Issue