Skip to content

Commit fa4e30a

Browse files
committed
CD daemon: fix sorting upon logging DNS mapping updates
Sort by DNS name (map value). Signed-off-by: Dr. Jan-Philip Gehrcke <[email protected]>
1 parent 14f3a7b commit fa4e30a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cmd/compute-domain-daemon/dnsnames.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package main
1818

1919
import (
20+
"cmp"
2021
"fmt"
2122
"maps"
2223
"os"
@@ -110,13 +111,20 @@ func (m *DNSNameManager) LogDNSNameMappings() {
110111
return
111112
}
112113

113-
klog.Infof("Current compute-domain-daemon mappings:")
114+
// Sort alphabetically by DNS name (map value) -> sort ips (map keys) based
115+
// on their corresponding values.
116+
var ips []string
117+
for ip := range m.ipToDNSName {
118+
ips = append(ips, ip)
119+
}
120+
121+
slices.SortFunc(ips, func(a, b string) int {
122+
return cmp.Compare(m.ipToDNSName[a], m.ipToDNSName[b])
123+
})
114124

115-
// Sort alphabetically by DNS name. Right-justify DNS names by adding
116-
// whitespace to the left.
117-
for _, ip := range slices.Sorted(maps.Keys(m.ipToDNSName)) {
125+
for _, ip := range ips {
118126
dnsname := m.ipToDNSName[ip]
119-
klog.Infof("%26s -> %s", dnsname, ip)
127+
klog.Infof("%s -> %s", dnsname, ip)
120128
}
121129
}
122130

0 commit comments

Comments
 (0)