Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

sort labels for metadata diffing #235

Merged
merged 1 commit into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions differs/metadata_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,38 @@ func getMetadataList(image pkgutil.Image) ([]string, error) {
return nil, err
}
c := configFile.Config

return []string{
fmt.Sprintf("Domainname: %s", c.Domainname),
fmt.Sprintf("User: %s", c.User),
fmt.Sprintf("AttachStdin: %t", c.AttachStdin),
fmt.Sprintf("AttachStdout: %t", c.AttachStdout),
fmt.Sprintf("AttachStderr: %t", c.AttachStderr),
fmt.Sprintf("ExposedPorts: %v", pkgutil.SortMap(c.ExposedPorts)),
fmt.Sprintf("ExposedPorts: %v", pkgutil.SortMap(StructMapToStringMap(c.ExposedPorts))),
fmt.Sprintf("Tty: %t", c.Tty),
fmt.Sprintf("OpenStdin: %t", c.OpenStdin),
fmt.Sprintf("StdinOnce: %t", c.StdinOnce),
fmt.Sprintf("Env: %s", strings.Join(c.Env, ",")),
fmt.Sprintf("Cmd: %s", strings.Join(c.Cmd, ",")),
fmt.Sprintf("ArgsEscaped: %t", c.ArgsEscaped),
fmt.Sprintf("Volumes: %v", pkgutil.SortMap(c.Volumes)),
fmt.Sprintf("Volumes: %v", pkgutil.SortMap(StructMapToStringMap(c.Volumes))),
fmt.Sprintf("Workdir: %s", c.WorkingDir),
fmt.Sprintf("Entrypoint: %s", strings.Join(c.Entrypoint, ",")),
fmt.Sprintf("NetworkDisabled: %t", c.NetworkDisabled),
fmt.Sprintf("MacAddress: %s", c.MacAddress),
fmt.Sprintf("OnBuild: %s", strings.Join(c.OnBuild, ",")),
fmt.Sprintf("Labels: %v", c.Labels),
fmt.Sprintf("Labels: %v", pkgutil.SortMap(c.Labels)),
fmt.Sprintf("StopSignal: %s", c.StopSignal),
fmt.Sprintf("Shell: %s", strings.Join(c.Shell, ",")),
}, nil
}

// StructMapToStringMap converts map[string]struct{} to map[string]string knowing that the
// struct in the value is always empty
func StructMapToStringMap(m map[string]struct{}) map[string]string {
newMap := make(map[string]string)
for k := range m {
newMap[k] = fmt.Sprintf("%s", m[k])
}
return newMap
}
2 changes: 1 addition & 1 deletion pkg/util/image_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func CleanupImage(image Image) {
}
}

func SortMap(m map[string]struct{}) string {
func SortMap(m map[string]string) string {
pairs := make([]string, 0)
for key := range m {
pairs = append(pairs, fmt.Sprintf("%s:%s", key, m[key]))
Expand Down