Merge pull request #61255 from dixudx/fix_describe_taint

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

fix sorting taints in case the sorting keys are equal

**What this PR does / why we need it**:
/kind bug
/sig cli

When describing node taints, the similar issue mentioned in #61250 also exists.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
xref #61250

**Special notes for your reviewer**:
/cc @kubernetes/sig-cli-bugs 
@kubernetes/sig-cli-api-reviews 

**Release note**:

```release-note
fix sorting taints in case the sorting keys are equal
```
This commit is contained in:
Kubernetes Submit Queue 2018-03-25 07:07:57 -07:00 committed by GitHub
commit 83a4f278ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3808,23 +3808,19 @@ func printTaintsMultilineWithIndent(w PrefixWriter, initialIndent, title, innerI
}
// to print taints in the sorted order
keys := make([]string, 0, len(taints))
for _, taint := range taints {
keys = append(keys, string(taint.Effect)+","+taint.Key)
}
sort.Strings(keys)
for i, key := range keys {
for _, taint := range taints {
if string(taint.Effect)+","+taint.Key == key {
if i != 0 {
w.Write(LEVEL_0, "%s", initialIndent)
w.Write(LEVEL_0, "%s", innerIndent)
}
w.Write(LEVEL_0, "%s\n", taint.ToString())
i++
}
sort.Slice(taints, func(i, j int) bool {
cmpKey := func(taint api.Taint) string {
return string(taint.Effect) + "," + taint.Key
}
return cmpKey(taints[i]) < cmpKey(taints[j])
})
for i, taint := range taints {
if i != 0 {
w.Write(LEVEL_0, "%s", initialIndent)
w.Write(LEVEL_0, "%s", innerIndent)
}
w.Write(LEVEL_0, "%s\n", taint.ToString())
}
}