refactor resources API

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2020-01-09 15:16:05 +08:00
parent 1f5defb044
commit 05e949103e
40 changed files with 469 additions and 1276 deletions

View File

@@ -19,13 +19,9 @@
package resources
import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort"
"strings"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/server/params"
"sort"
"k8s.io/apimachinery/pkg/labels"
@@ -40,25 +36,15 @@ func (*s2iRunSearcher) get(namespace, name string) (interface{}, error) {
}
// exactly Match
func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) bool {
for k, v := range match {
func (*s2iRunSearcher) match(kv map[string]string, item *v1alpha1.S2iRun) 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 string(item.Status.RunState) != 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
}
}
@@ -67,44 +53,17 @@ func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) boo
}
// Fuzzy searchInNamespace
func (*s2iRunSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iRun) 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 (*s2iRunSearcher) fuzzy(kv map[string]string, item *v1alpha1.S2iRun) 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
}
func (*s2iRunSearcher) compare(a, b *v1alpha1.S2iRun, orderBy string) bool {
switch orderBy {
case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case Name:
fallthrough
default:
return strings.Compare(a.Name, b.Name) <= 0
}
return compare(a.ObjectMeta, b.ObjectMeta, orderBy)
}
func (s *s2iRunSearcher) search(namespace string, conditions *params.Conditions, orderBy string, reverse bool) ([]interface{}, error) {