未验证 提交 c02417bd 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #1038 from wansir/sort-resource

fix: sort deployment by last update time
......@@ -24,6 +24,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort"
"strings"
"time"
"k8s.io/apimachinery/pkg/labels"
......@@ -108,10 +109,12 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b
return true
}
func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
func (s *deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
switch orderBy {
case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case UpdateTime:
return s.lastUpdateTime(a).Before(s.lastUpdateTime(b))
case Name:
fallthrough
default:
......@@ -119,6 +122,16 @@ func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
}
}
func (s *deploymentSearcher) lastUpdateTime(deployment *v1.Deployment) time.Time {
lastUpdateTime := deployment.CreationTimestamp.Time
for _, condition := range deployment.Status.Conditions {
if condition.LastUpdateTime.After(lastUpdateTime) {
lastUpdateTime = condition.LastUpdateTime.Time
}
}
return lastUpdateTime
}
func (s *deploymentSearcher) search(namespace string, conditions *params.Conditions, orderBy string, reverse bool) ([]interface{}, error) {
deployments, err := informers.SharedInformerFactory().Apps().V1().Deployments().Lister().Deployments(namespace).List(labels.Everything())
......
......@@ -221,6 +221,14 @@ func (*podSearcher) fuzzy(fuzzy map[string]string, item *v1.Pod) bool {
func (*podSearcher) compare(a, b *v1.Pod, orderBy string) bool {
switch orderBy {
case StartTime:
if a.Status.StartTime == nil {
return false
}
if b.Status.StartTime == nil {
return true
}
return a.Status.StartTime.Before(b.Status.StartTime)
case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case Name:
......
......@@ -67,6 +67,7 @@ const (
Role = "role"
CreateTime = "createTime"
UpdateTime = "updateTime"
StartTime = "startTime"
LastScheduleTime = "lastScheduleTime"
chart = "chart"
release = "release"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册