diff --git a/pkg/models/resources/deployments.go b/pkg/models/resources/deployments.go index 4793802fe34b28f64f7ab99afef58df10eb16d66..5980c6d703f8e2ae6f8aecc38ba7809c2d6e8590 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 13c6aed8838d8949f1503ed5424ad7b333f3f6d4..8652ca00a14458b746594ceb3e8fa6fe24716cbf 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 05af020fb5259f8727cf05bc0caf59e9b8d598fb..a7716885cb134ac1b9907da7a4b6bb73d6eb8f8e 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"