未验证 提交 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 ( ...@@ -24,6 +24,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/sliceutil" "kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
"time"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
...@@ -108,10 +109,12 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b ...@@ -108,10 +109,12 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b
return true 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 { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case UpdateTime:
return s.lastUpdateTime(a).Before(s.lastUpdateTime(b))
case Name: case Name:
fallthrough fallthrough
default: default:
...@@ -119,6 +122,16 @@ func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool { ...@@ -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) { 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()) 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 { ...@@ -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 { func (*podSearcher) compare(a, b *v1.Pod, orderBy string) bool {
switch orderBy { 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: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case Name: case Name:
......
...@@ -67,6 +67,7 @@ const ( ...@@ -67,6 +67,7 @@ const (
Role = "role" Role = "role"
CreateTime = "createTime" CreateTime = "createTime"
UpdateTime = "updateTime" UpdateTime = "updateTime"
StartTime = "startTime"
LastScheduleTime = "lastScheduleTime" LastScheduleTime = "lastScheduleTime"
chart = "chart" chart = "chart"
release = "release" release = "release"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册