mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #25802 from dshulyak/sort_history
Automatic merge from submit-queue Sort revisions in rollout history as integers Previously keys were sorted as strings, thus it was possible to see such order as 1, 10, 2, 3, 4, 5. fixes: #25788
This commit is contained in:
commit
7813e90026
@ -19,8 +19,6 @@ package kubectl
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
@ -29,7 +27,7 @@ import (
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
deploymentutil "k8s.io/kubernetes/pkg/util/deployment"
|
||||
"k8s.io/kubernetes/pkg/util/errors"
|
||||
sliceutil "k8s.io/kubernetes/pkg/util/slice"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -103,30 +101,24 @@ func PrintRolloutHistory(historyInfo HistoryInfo, resource, name string) (string
|
||||
return fmt.Sprintf("No rollout history found in %s %q", resource, name), nil
|
||||
}
|
||||
// Sort the revisionToChangeCause map by revision
|
||||
var revisions []string
|
||||
for k := range historyInfo.RevisionToTemplate {
|
||||
revisions = append(revisions, strconv.FormatInt(k, 10))
|
||||
var revisions []int64
|
||||
for r := range historyInfo.RevisionToTemplate {
|
||||
revisions = append(revisions, r)
|
||||
}
|
||||
sort.Strings(revisions)
|
||||
sliceutil.SortInts64(revisions)
|
||||
|
||||
return tabbedString(func(out io.Writer) error {
|
||||
fmt.Fprintf(out, "%s %q:\n", resource, name)
|
||||
fmt.Fprintf(out, "REVISION\tCHANGE-CAUSE\n")
|
||||
errs := []error{}
|
||||
for _, r := range revisions {
|
||||
// Find the change-cause of revision r
|
||||
r64, err := strconv.ParseInt(r, 10, 64)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
changeCause := historyInfo.RevisionToTemplate[r64].Annotations[ChangeCauseAnnotation]
|
||||
changeCause := historyInfo.RevisionToTemplate[r].Annotations[ChangeCauseAnnotation]
|
||||
if len(changeCause) == 0 {
|
||||
changeCause = "<none>"
|
||||
}
|
||||
fmt.Fprintf(out, "%s\t%s\n", r, changeCause)
|
||||
fmt.Fprintf(out, "%d\t%s\n", r, changeCause)
|
||||
}
|
||||
return errors.NewAggregate(errs)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -48,3 +48,14 @@ func ShuffleStrings(s []string) []string {
|
||||
}
|
||||
return shuffled
|
||||
}
|
||||
|
||||
// Int64Slice attaches the methods of Interface to []int64,
|
||||
// sorting in increasing order.
|
||||
type Int64Slice []int64
|
||||
|
||||
func (p Int64Slice) Len() int { return len(p) }
|
||||
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
|
||||
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||
|
||||
// Sorts []int64 in increasing order
|
||||
func SortInts64(a []int64) { sort.Sort(Int64Slice(a)) }
|
||||
|
@ -68,3 +68,12 @@ func TestShuffleStrings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortInts64(t *testing.T) {
|
||||
src := []int64{10, 1, 2, 3, 4, 5, 6}
|
||||
expected := []int64{1, 2, 3, 4, 5, 6, 10}
|
||||
SortInts64(src)
|
||||
if !reflect.DeepEqual(src, expected) {
|
||||
t.Errorf("func Ints64 didnt sort correctly, %v !- %v", src, expected)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user