@@ -19,14 +19,11 @@ package job
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/informers"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha2"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
|
||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
@@ -64,7 +61,6 @@ func jobStatus(item *batchv1.Job) string {
|
||||
return status
|
||||
}
|
||||
|
||||
// Exactly Match
|
||||
func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool {
|
||||
for k, v := range match {
|
||||
switch k {
|
||||
@@ -80,18 +76,8 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool {
|
||||
if v == "false" && k8sutil.IsControlledBy(item.OwnerReferences, s2iRunKind, "") {
|
||||
return false
|
||||
}
|
||||
case v1alpha2.Name:
|
||||
names := strings.Split(v, "|")
|
||||
if !sliceutil.HasString(names, item.Name) {
|
||||
return false
|
||||
}
|
||||
case v1alpha2.Keyword:
|
||||
if !strings.Contains(item.Name, v) && !v1alpha2.SearchFuzzy(item.Labels, "", v) && !v1alpha2.SearchFuzzy(item.Annotations, "", v) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
// label not exist or value not equal
|
||||
if val, ok := item.Labels[k]; !ok || val != v {
|
||||
if !v1alpha2.ObjectMetaExactlyMath(k, v, item.ObjectMeta) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -100,33 +86,11 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool {
|
||||
}
|
||||
|
||||
func (*jobSearcher) fuzzy(fuzzy map[string]string, item *batchv1.Job) bool {
|
||||
|
||||
for k, v := range fuzzy {
|
||||
switch k {
|
||||
case v1alpha2.Name:
|
||||
if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
|
||||
return false
|
||||
}
|
||||
case v1alpha2.Label:
|
||||
if !v1alpha2.SearchFuzzy(item.Labels, "", v) {
|
||||
return false
|
||||
}
|
||||
case v1alpha2.Annotation:
|
||||
if !v1alpha2.SearchFuzzy(item.Annotations, "", v) {
|
||||
return false
|
||||
}
|
||||
if !v1alpha2.ObjectMetaFuzzyMath(k, v, item.ObjectMeta) {
|
||||
return false
|
||||
case v1alpha2.App:
|
||||
if !strings.Contains(item.Labels[v1alpha2.Chart], v) && !strings.Contains(item.Labels[v1alpha2.Release], v) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
if !v1alpha2.SearchFuzzy(item.Labels, k, v) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -143,16 +107,12 @@ func jobUpdateTime(item *batchv1.Job) time.Time {
|
||||
return updateTime
|
||||
}
|
||||
|
||||
func (*jobSearcher) compare(a, b *batchv1.Job, orderBy string) bool {
|
||||
func (*jobSearcher) compare(left, right *batchv1.Job, orderBy string) bool {
|
||||
switch orderBy {
|
||||
case v1alpha2.CreateTime:
|
||||
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
|
||||
case v1alpha2.UpdateTime:
|
||||
return jobUpdateTime(a).Before(jobUpdateTime(b))
|
||||
case v1alpha2.Name:
|
||||
fallthrough
|
||||
return jobUpdateTime(left).Before(jobUpdateTime(right))
|
||||
default:
|
||||
return strings.Compare(a.Name, b.Name) <= 0
|
||||
return v1alpha2.ObjectMetaCompare(left.ObjectMeta, right.ObjectMeta, orderBy)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,9 +136,7 @@ func (s *jobSearcher) Search(namespace string, conditions *params.Conditions, or
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
if reverse {
|
||||
tmp := i
|
||||
i = j
|
||||
j = tmp
|
||||
i, j = j, i
|
||||
}
|
||||
return s.compare(result[i], result[j], orderBy)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user