@@ -18,10 +18,8 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/informers"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -45,25 +43,15 @@ func cronJobStatus(item *v1beta1.CronJob) string {
|
||||
}
|
||||
|
||||
// Exactly Match
|
||||
func (*cronJobSearcher) match(match map[string]string, item *v1beta1.CronJob) bool {
|
||||
for k, v := range match {
|
||||
func (*cronJobSearcher) match(kv map[string]string, item *v1beta1.CronJob) bool {
|
||||
for k, v := range kv {
|
||||
switch k {
|
||||
case Name:
|
||||
names := strings.Split(v, "|")
|
||||
if !sliceutil.HasString(names, item.Name) {
|
||||
return false
|
||||
}
|
||||
case Status:
|
||||
if cronJobStatus(item) != v {
|
||||
return false
|
||||
}
|
||||
case Keyword:
|
||||
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
// label not exist or value not equal
|
||||
if val, ok := item.Labels[k]; !ok || val != v {
|
||||
if !match(k, v, item.ObjectMeta) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -71,34 +59,12 @@ func (*cronJobSearcher) match(match map[string]string, item *v1beta1.CronJob) bo
|
||||
return true
|
||||
}
|
||||
|
||||
func (*cronJobSearcher) fuzzy(fuzzy map[string]string, item *v1beta1.CronJob) bool {
|
||||
|
||||
for k, v := range fuzzy {
|
||||
switch k {
|
||||
case Name:
|
||||
if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
|
||||
return false
|
||||
}
|
||||
case Label:
|
||||
if !searchFuzzy(item.Labels, "", v) {
|
||||
return false
|
||||
}
|
||||
case annotation:
|
||||
if !searchFuzzy(item.Annotations, "", v) {
|
||||
return false
|
||||
}
|
||||
func (*cronJobSearcher) fuzzy(kv map[string]string, item *v1beta1.CronJob) bool {
|
||||
for k, v := range kv {
|
||||
if !fuzzy(k, v, item.ObjectMeta) {
|
||||
return false
|
||||
case app:
|
||||
if !strings.Contains(item.Labels[chart], v) && !strings.Contains(item.Labels[release], v) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
if !searchFuzzy(item.Labels, k, v) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -111,13 +77,12 @@ func (*cronJobSearcher) compare(a, b *v1beta1.CronJob, orderBy string) bool {
|
||||
if b.Status.LastScheduleTime == nil {
|
||||
return false
|
||||
}
|
||||
if a.Status.LastScheduleTime.Equal(b.Status.LastScheduleTime) {
|
||||
return strings.Compare(a.Name, b.Name) <= 0
|
||||
}
|
||||
return a.Status.LastScheduleTime.Before(b.Status.LastScheduleTime)
|
||||
case CreateTime:
|
||||
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
|
||||
default:
|
||||
fallthrough
|
||||
case Name:
|
||||
return strings.Compare(a.Name, b.Name) <= 0
|
||||
return compare(a.ObjectMeta, b.ObjectMeta, orderBy)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user