diff --git a/pkg/models/resources/deployments.go b/pkg/models/resources/deployments.go index 4793802fe..5980c6d70 100644 --- a/pkg/models/resources/deployments.go +++ b/pkg/models/resources/deployments.go @@ -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()) diff --git a/pkg/models/resources/pods.go b/pkg/models/resources/pods.go index 13c6aed88..8652ca00a 100644 --- a/pkg/models/resources/pods.go +++ b/pkg/models/resources/pods.go @@ -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: diff --git a/pkg/models/resources/resources.go b/pkg/models/resources/resources.go index 05af020fb..a7716885c 100644 --- a/pkg/models/resources/resources.go +++ b/pkg/models/resources/resources.go @@ -67,6 +67,7 @@ const ( Role = "role" CreateTime = "createTime" UpdateTime = "updateTime" + StartTime = "startTime" LastScheduleTime = "lastScheduleTime" chart = "chart" release = "release"