提交 8e862caf 编写于 作者: H hongming 提交者: zryfish

fix terminal api

Signed-off-by: Nhongming <talonwan@yunify.com>
上级 eea2bb37
...@@ -131,7 +131,7 @@ func (h Auth) InjectContext(req *http.Request, token *jwt.Token) (*http.Request, ...@@ -131,7 +131,7 @@ func (h Auth) InjectContext(req *http.Request, token *jwt.Token) (*http.Request,
} }
// hard code, support jenkins auth plugin // hard code, support jenkins auth plugin
if httpserver.Path(req.URL.Path).Matches("/apis/jenkins.kubesphere.io") || httpserver.Path(req.URL.Path).Matches("job") { if httpserver.Path(req.URL.Path).Matches("/kapis/jenkins.kubesphere.io") || httpserver.Path(req.URL.Path).Matches("job") {
req.SetBasicAuth(username, token.Raw) req.SetBasicAuth(username, token.Raw)
} }
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"fmt" "fmt"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/endpoints/request"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"net/http" "net/http"
"strings" "strings"
...@@ -31,7 +32,6 @@ import ( ...@@ -31,7 +32,6 @@ import (
k8serr "k8s.io/apimachinery/pkg/api/errors" k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/util/slice"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/utils/sliceutil" "kubesphere.io/kubesphere/pkg/utils/sliceutil"
) )
...@@ -132,14 +132,13 @@ func roleValidate(attrs authorizer.Attributes) (bool, error) { ...@@ -132,14 +132,13 @@ func roleValidate(attrs authorizer.Attributes) (bool, error) {
} }
for _, roleBinding := range roleBindings { for _, roleBinding := range roleBindings {
if k8sutil.ContainsUser(roleBinding.Subjects, attrs.GetUser().GetName()) {
for _, subj := range roleBinding.Subjects {
if (subj.Kind == v1.UserKind && subj.Name == attrs.GetUser().GetName()) ||
(subj.Kind == v1.GroupKind && slice.ContainsString(attrs.GetUser().GetGroups(), subj.Name, nil)) {
role, err := roleLister.Roles(attrs.GetNamespace()).Get(roleBinding.RoleRef.Name) role, err := roleLister.Roles(attrs.GetNamespace()).Get(roleBinding.RoleRef.Name)
if err != nil { if err != nil {
if k8serr.IsNotFound(err) {
continue
}
return false, err return false, err
} }
...@@ -150,7 +149,6 @@ func roleValidate(attrs authorizer.Attributes) (bool, error) { ...@@ -150,7 +149,6 @@ func roleValidate(attrs authorizer.Attributes) (bool, error) {
} }
} }
} }
}
return false, nil return false, nil
} }
...@@ -165,14 +163,13 @@ func clusterRoleValidate(attrs authorizer.Attributes) (bool, error) { ...@@ -165,14 +163,13 @@ func clusterRoleValidate(attrs authorizer.Attributes) (bool, error) {
for _, clusterRoleBinding := range clusterRoleBindings { for _, clusterRoleBinding := range clusterRoleBindings {
for _, subject := range clusterRoleBinding.Subjects { if k8sutil.ContainsUser(clusterRoleBinding.Subjects, attrs.GetUser().GetName()) {
if (subject.Kind == v1.UserKind && subject.Name == attrs.GetUser().GetName()) ||
(subject.Kind == v1.GroupKind && sliceutil.HasString(attrs.GetUser().GetGroups(), subject.Name)) {
clusterRole, err := clusterRoleLister.Get(clusterRoleBinding.RoleRef.Name) clusterRole, err := clusterRoleLister.Get(clusterRoleBinding.RoleRef.Name)
if err != nil { if err != nil {
if k8serr.IsNotFound(err) {
continue
}
return false, err return false, err
} }
...@@ -186,12 +183,10 @@ func clusterRoleValidate(attrs authorizer.Attributes) (bool, error) { ...@@ -186,12 +183,10 @@ func clusterRoleValidate(attrs authorizer.Attributes) (bool, error) {
return true, nil return true, nil
} }
} }
} }
} }
} }
}
return false, nil return false, nil
} }
......
...@@ -41,14 +41,14 @@ func addWebService(c *restful.Container) error { ...@@ -41,14 +41,14 @@ func addWebService(c *restful.Container) error {
tags := []string{"Terminal"} tags := []string{"Terminal"}
webservice.Route(webservice.GET("/namespaces/{namespace}/pods/{pods}"). webservice.Route(webservice.GET("/namespaces/{namespace}/pods/{pod}").
To(terminal.CreateTerminalSession). To(terminal.CreateTerminalSession).
Doc("create terminal session"). Doc("create terminal session").
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(models.PodInfo{})) Writes(models.PodInfo{}))
path := runtime.ApiRootPath + "/" + GroupVersion.String() + "/sockjs" path := runtime.ApiRootPath + "/" + GroupVersion.String() + "/sockjs"
c.Handle(path, terminal.NewTerminalHandler(path)) c.Handle(path+"/", terminal.NewTerminalHandler(path))
c.Add(webservice) c.Add(webservice)
......
...@@ -98,7 +98,7 @@ func DescribeWorkspaceUser(req *restful.Request, resp *restful.Response) { ...@@ -98,7 +98,7 @@ func DescribeWorkspaceUser(req *restful.Request, resp *restful.Response) {
return return
} }
user.WorkspaceRole = workspaceRole.Labels[constants.DisplayNameLabelKey] user.WorkspaceRole = workspaceRole.Annotations[constants.DisplayNameAnnotationKey]
resp.WriteAsJson(user) resp.WriteAsJson(user)
} }
......
...@@ -32,8 +32,8 @@ const ( ...@@ -32,8 +32,8 @@ const (
IngressControllerPrefix = "kubesphere-router-" IngressControllerPrefix = "kubesphere-router-"
WorkspaceLabelKey = "kubesphere.io/workspace" WorkspaceLabelKey = "kubesphere.io/workspace"
DisplayNameLabelKey = "displayName" DisplayNameAnnotationKey = "displayName"
CreatorLabelKey = "creator" CreatorLabelAnnotationKey = "creator"
OpenPitrixRuntimeAnnotationKey = "openpitrix_runtime" OpenPitrixRuntimeAnnotationKey = "openpitrix_runtime"
WorkspaceAdmin = "workspace-admin" WorkspaceAdmin = "workspace-admin"
ClusterAdmin = "cluster-admin" ClusterAdmin = "cluster-admin"
......
...@@ -195,7 +195,7 @@ func (r *ReconcileNamespace) checkAndCreateRoles(namespace *corev1.Namespace) er ...@@ -195,7 +195,7 @@ func (r *ReconcileNamespace) checkAndCreateRoles(namespace *corev1.Namespace) er
func (r *ReconcileNamespace) checkAndCreateRoleBindings(namespace *corev1.Namespace) error { func (r *ReconcileNamespace) checkAndCreateRoleBindings(namespace *corev1.Namespace) error {
workspaceName := namespace.Labels[constants.WorkspaceLabelKey] workspaceName := namespace.Labels[constants.WorkspaceLabelKey]
creatorName := namespace.Labels[constants.CreatorLabelKey] creatorName := namespace.Annotations[constants.CreatorLabelAnnotationKey]
creator := rbac.Subject{APIGroup: "rbac.authorization.k8s.io", Kind: "User", Name: creatorName} creator := rbac.Subject{APIGroup: "rbac.authorization.k8s.io", Kind: "User", Name: creatorName}
......
...@@ -473,7 +473,8 @@ func getWorkspaceViewerRoleBindingName(workspaceName string) string { ...@@ -473,7 +473,8 @@ func getWorkspaceViewerRoleBindingName(workspaceName string) string {
func getWorkspaceAdmin(workspaceName string) *rbac.ClusterRole { func getWorkspaceAdmin(workspaceName string) *rbac.ClusterRole {
admin := &rbac.ClusterRole{} admin := &rbac.ClusterRole{}
admin.Name = getWorkspaceAdminRoleName(workspaceName) admin.Name = getWorkspaceAdminRoleName(workspaceName)
admin.Labels = map[string]string{constants.WorkspaceLabelKey: workspaceName, constants.DisplayNameLabelKey: constants.WorkspaceAdmin} admin.Labels = map[string]string{constants.WorkspaceLabelKey: workspaceName}
admin.Annotations = map[string]string{constants.DisplayNameAnnotationKey: constants.WorkspaceAdmin}
admin.Rules = []rbac.PolicyRule{ admin.Rules = []rbac.PolicyRule{
{ {
Verbs: []string{"*"}, Verbs: []string{"*"},
...@@ -494,7 +495,8 @@ func getWorkspaceAdmin(workspaceName string) *rbac.ClusterRole { ...@@ -494,7 +495,8 @@ func getWorkspaceAdmin(workspaceName string) *rbac.ClusterRole {
func getWorkspaceRegular(workspaceName string) *rbac.ClusterRole { func getWorkspaceRegular(workspaceName string) *rbac.ClusterRole {
regular := &rbac.ClusterRole{} regular := &rbac.ClusterRole{}
regular.Name = getWorkspaceRegularRoleName(workspaceName) regular.Name = getWorkspaceRegularRoleName(workspaceName)
regular.Labels = map[string]string{constants.WorkspaceLabelKey: workspaceName, constants.DisplayNameLabelKey: constants.WorkspaceRegular} regular.Labels = map[string]string{constants.WorkspaceLabelKey: workspaceName}
regular.Annotations = map[string]string{constants.DisplayNameAnnotationKey: constants.WorkspaceRegular}
regular.Rules = []rbac.PolicyRule{ regular.Rules = []rbac.PolicyRule{
{ {
Verbs: []string{"get"}, Verbs: []string{"get"},
...@@ -521,7 +523,8 @@ func getWorkspaceRegular(workspaceName string) *rbac.ClusterRole { ...@@ -521,7 +523,8 @@ func getWorkspaceRegular(workspaceName string) *rbac.ClusterRole {
func getWorkspaceViewer(workspaceName string) *rbac.ClusterRole { func getWorkspaceViewer(workspaceName string) *rbac.ClusterRole {
viewer := &rbac.ClusterRole{} viewer := &rbac.ClusterRole{}
viewer.Name = getWorkspaceViewerRoleName(workspaceName) viewer.Name = getWorkspaceViewerRoleName(workspaceName)
viewer.Labels = map[string]string{constants.WorkspaceLabelKey: workspaceName, constants.DisplayNameLabelKey: constants.WorkspaceViewer} viewer.Labels = map[string]string{constants.WorkspaceLabelKey: workspaceName}
viewer.Annotations = map[string]string{constants.DisplayNameAnnotationKey: constants.WorkspaceViewer}
viewer.Rules = []rbac.PolicyRule{ viewer.Rules = []rbac.PolicyRule{
{ {
Verbs: []string{"get", "list"}, Verbs: []string{"get", "list"},
......
...@@ -413,7 +413,7 @@ func ListWorkspaceRoles(workspace string, conditions *params.Conditions, orderBy ...@@ -413,7 +413,7 @@ func ListWorkspaceRoles(workspace string, conditions *params.Conditions, orderBy
for i, item := range result.Items { for i, item := range result.Items {
if role, ok := item.(*v1.ClusterRole); ok { if role, ok := item.(*v1.ClusterRole); ok {
role = role.DeepCopy() role = role.DeepCopy()
role.Name = role.Labels[constants.DisplayNameLabelKey] role.Name = role.Annotations[constants.DisplayNameAnnotationKey]
result.Items[i] = role result.Items[i] = role
} }
} }
...@@ -477,7 +477,7 @@ func GetUserWorkspaceSimpleRules(workspace, username string) ([]models.SimpleRul ...@@ -477,7 +477,7 @@ func GetUserWorkspaceSimpleRules(workspace, username string) ([]models.SimpleRul
if err != nil { if err != nil {
return nil, err return nil, err
} }
return GetWorkspaceRoleSimpleRules(workspace, workspaceRole.Labels[constants.DisplayNameLabelKey]), nil return GetWorkspaceRoleSimpleRules(workspace, workspaceRole.Annotations[constants.DisplayNameAnnotationKey]), nil
} }
func GetWorkspaceRoleSimpleRules(workspace, roleName string) []models.SimpleRule { func GetWorkspaceRoleSimpleRules(workspace, roleName string) []models.SimpleRule {
......
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/k8sutil" "kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -48,11 +49,12 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol ...@@ -48,11 +49,12 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol
if !k8sutil.IsControlledBy(item.OwnerReferences, kind, name) { if !k8sutil.IsControlledBy(item.OwnerReferences, kind, name) {
return false return false
} }
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -75,8 +77,8 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol ...@@ -75,8 +77,8 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol
func (*clusterRoleSearcher) fuzzy(fuzzy map[string]string, item *rbac.ClusterRole) bool { func (*clusterRoleSearcher) fuzzy(fuzzy map[string]string, item *rbac.ClusterRole) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -101,7 +103,7 @@ func (*clusterRoleSearcher) compare(a, b *rbac.ClusterRole, orderBy string) bool ...@@ -101,7 +103,7 @@ func (*clusterRoleSearcher) compare(a, b *rbac.ClusterRole, orderBy string) bool
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
...@@ -143,7 +145,7 @@ func (s *clusterRoleSearcher) search(namespace string, conditions *params.Condit ...@@ -143,7 +145,7 @@ func (s *clusterRoleSearcher) search(namespace string, conditions *params.Condit
} }
func isUserFacingClusterRole(role *rbac.ClusterRole) bool { func isUserFacingClusterRole(role *rbac.ClusterRole) bool {
if role.Labels[constants.CreatorLabelKey] != "" && role.Labels[constants.WorkspaceLabelKey] == "" { if role.Annotations[constants.CreatorLabelAnnotationKey] != "" && role.Labels[constants.WorkspaceLabelKey] == "" {
return true return true
} }
return false return false
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*configMapSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*configMapSearcher) get(namespace, name string) (interface{}, error) {
func (*configMapSearcher) match(match map[string]string, item *v1.ConfigMap) bool { func (*configMapSearcher) match(match map[string]string, item *v1.ConfigMap) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*configMapSearcher) match(match map[string]string, item *v1.ConfigMap) boo ...@@ -59,8 +62,8 @@ func (*configMapSearcher) match(match map[string]string, item *v1.ConfigMap) boo
func (*configMapSearcher) fuzzy(fuzzy map[string]string, item *v1.ConfigMap) bool { func (*configMapSearcher) fuzzy(fuzzy map[string]string, item *v1.ConfigMap) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*configMapSearcher) compare(a, b *v1.ConfigMap, orderBy string) bool { ...@@ -89,7 +92,7 @@ func (*configMapSearcher) compare(a, b *v1.ConfigMap, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -46,15 +48,16 @@ func cronJobStatus(item *v1beta1.CronJob) string { ...@@ -46,15 +48,16 @@ func cronJobStatus(item *v1beta1.CronJob) string {
func (*cronJobSearcher) match(match map[string]string, item *v1beta1.CronJob) bool { func (*cronJobSearcher) match(match map[string]string, item *v1beta1.CronJob) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case status: case status:
if cronJobStatus(item) != v { if cronJobStatus(item) != v {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -71,8 +74,8 @@ func (*cronJobSearcher) fuzzy(fuzzy map[string]string, item *v1beta1.CronJob) bo ...@@ -71,8 +74,8 @@ func (*cronJobSearcher) fuzzy(fuzzy map[string]string, item *v1beta1.CronJob) bo
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -112,7 +115,7 @@ func (*cronJobSearcher) compare(a, b *v1beta1.CronJob, orderBy string) bool { ...@@ -112,7 +115,7 @@ func (*cronJobSearcher) compare(a, b *v1beta1.CronJob, orderBy string) bool {
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
default: default:
fallthrough fallthrough
case name: case Name:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
} }
} }
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -52,11 +54,12 @@ func (*daemonSetSearcher) match(match map[string]string, item *v1.DaemonSet) boo ...@@ -52,11 +54,12 @@ func (*daemonSetSearcher) match(match map[string]string, item *v1.DaemonSet) boo
if daemonSetStatus(item) != v { if daemonSetStatus(item) != v {
return false return false
} }
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -73,8 +76,8 @@ func (*daemonSetSearcher) fuzzy(fuzzy map[string]string, item *v1.DaemonSet) boo ...@@ -73,8 +76,8 @@ func (*daemonSetSearcher) fuzzy(fuzzy map[string]string, item *v1.DaemonSet) boo
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -104,7 +107,7 @@ func (*daemonSetSearcher) compare(a, b *v1.DaemonSet, orderBy string) bool { ...@@ -104,7 +107,7 @@ func (*daemonSetSearcher) compare(a, b *v1.DaemonSet, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -56,11 +58,12 @@ func (*deploymentSearcher) match(match map[string]string, item *v1.Deployment) b ...@@ -56,11 +58,12 @@ func (*deploymentSearcher) match(match map[string]string, item *v1.Deployment) b
if deploymentStatus(item) != v { if deploymentStatus(item) != v {
return false return false
} }
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -77,8 +80,8 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b ...@@ -77,8 +80,8 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -108,7 +111,7 @@ func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool { ...@@ -108,7 +111,7 @@ func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -39,11 +41,12 @@ func (*ingressSearcher) get(namespace, name string) (interface{}, error) { ...@@ -39,11 +41,12 @@ func (*ingressSearcher) get(namespace, name string) (interface{}, error) {
func (*ingressSearcher) match(match map[string]string, item *extensions.Ingress) bool { func (*ingressSearcher) match(match map[string]string, item *extensions.Ingress) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -60,8 +63,8 @@ func (*ingressSearcher) match(match map[string]string, item *extensions.Ingress) ...@@ -60,8 +63,8 @@ func (*ingressSearcher) match(match map[string]string, item *extensions.Ingress)
func (*ingressSearcher) fuzzy(fuzzy map[string]string, item *extensions.Ingress) bool { func (*ingressSearcher) fuzzy(fuzzy map[string]string, item *extensions.Ingress) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -90,7 +93,7 @@ func (*ingressSearcher) compare(a, b *extensions.Ingress, orderBy string) bool { ...@@ -90,7 +93,7 @@ func (*ingressSearcher) compare(a, b *extensions.Ingress, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
"time" "time"
...@@ -58,11 +60,12 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool { ...@@ -58,11 +60,12 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool {
if jobStatus(item) != v { if jobStatus(item) != v {
return false return false
} }
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -79,8 +82,8 @@ func (*jobSearcher) fuzzy(fuzzy map[string]string, item *batchv1.Job) bool { ...@@ -79,8 +82,8 @@ func (*jobSearcher) fuzzy(fuzzy map[string]string, item *batchv1.Job) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -125,7 +128,7 @@ func (*jobSearcher) compare(a, b *batchv1.Job, orderBy string) bool { ...@@ -125,7 +128,7 @@ func (*jobSearcher) compare(a, b *batchv1.Job, orderBy string) bool {
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case updateTime: case updateTime:
return jobUpdateTime(a).Before(jobUpdateTime(b)) return jobUpdateTime(a).Before(jobUpdateTime(b))
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*namespaceSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*namespaceSearcher) get(namespace, name string) (interface{}, error) {
func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) bool { func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) boo ...@@ -59,8 +62,8 @@ func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) boo
func (*namespaceSearcher) fuzzy(fuzzy map[string]string, item *v1.Namespace) bool { func (*namespaceSearcher) fuzzy(fuzzy map[string]string, item *v1.Namespace) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*namespaceSearcher) compare(a, b *v1.Namespace, orderBy string) bool { ...@@ -89,7 +92,7 @@ func (*namespaceSearcher) compare(a, b *v1.Namespace, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*nodeSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*nodeSearcher) get(namespace, name string) (interface{}, error) {
func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool { func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool { ...@@ -59,8 +62,8 @@ func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool {
func (*nodeSearcher) fuzzy(fuzzy map[string]string, item *v1.Node) bool { func (*nodeSearcher) fuzzy(fuzzy map[string]string, item *v1.Node) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*nodeSearcher) compare(a, b *v1.Node, orderBy string) bool { ...@@ -89,7 +92,7 @@ func (*nodeSearcher) compare(a, b *v1.Node, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*persistentVolumeClaimSearcher) get(namespace, name string) (interface{}, ...@@ -38,11 +40,12 @@ func (*persistentVolumeClaimSearcher) get(namespace, name string) (interface{},
func (*persistentVolumeClaimSearcher) match(match map[string]string, item *v1.PersistentVolumeClaim) bool { func (*persistentVolumeClaimSearcher) match(match map[string]string, item *v1.PersistentVolumeClaim) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*persistentVolumeClaimSearcher) match(match map[string]string, item *v1.Pe ...@@ -59,8 +62,8 @@ func (*persistentVolumeClaimSearcher) match(match map[string]string, item *v1.Pe
func (*persistentVolumeClaimSearcher) fuzzy(fuzzy map[string]string, item *v1.PersistentVolumeClaim) bool { func (*persistentVolumeClaimSearcher) fuzzy(fuzzy map[string]string, item *v1.PersistentVolumeClaim) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*persistentVolumeClaimSearcher) compare(a, b *v1.PersistentVolumeClaim, or ...@@ -89,7 +92,7 @@ func (*persistentVolumeClaimSearcher) compare(a, b *v1.PersistentVolumeClaim, or
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -19,8 +19,10 @@ package resources ...@@ -19,8 +19,10 @@ package resources
import ( import (
v12 "k8s.io/api/apps/v1" v12 "k8s.io/api/apps/v1"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -168,11 +170,12 @@ func (*podSearcher) match(match map[string]string, item *v1.Pod) bool { ...@@ -168,11 +170,12 @@ func (*podSearcher) match(match map[string]string, item *v1.Pod) bool {
if !podBelongToService(item, v) { if !podBelongToService(item, v) {
return false return false
} }
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -189,8 +192,8 @@ func (*podSearcher) match(match map[string]string, item *v1.Pod) bool { ...@@ -189,8 +192,8 @@ func (*podSearcher) match(match map[string]string, item *v1.Pod) bool {
func (*podSearcher) fuzzy(fuzzy map[string]string, item *v1.Pod) bool { func (*podSearcher) fuzzy(fuzzy map[string]string, item *v1.Pod) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -219,7 +222,7 @@ func (*podSearcher) compare(a, b *v1.Pod, orderBy string) bool { ...@@ -219,7 +222,7 @@ func (*podSearcher) compare(a, b *v1.Pod, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -55,18 +55,17 @@ var ( ...@@ -55,18 +55,17 @@ var (
) )
const ( const (
name = "name" Name = "name"
label = "label" label = "label"
ownerKind = "ownerKind" ownerKind = "ownerKind"
ownerName = "ownerName" ownerName = "ownerName"
CreateTime = "CreateTime" CreateTime = "createTime"
updateTime = "updateTime" updateTime = "updateTime"
lastScheduleTime = "lastScheduleTime" lastScheduleTime = "lastScheduleTime"
displayName = "displayName"
chart = "chart" chart = "chart"
release = "release" release = "release"
annotation = "annotation" annotation = "annotation"
keyword = "keyword" Keyword = "keyword"
status = "status" status = "status"
running = "running" running = "running"
paused = "paused" paused = "paused"
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*roleSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*roleSearcher) get(namespace, name string) (interface{}, error) {
func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool { func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool { ...@@ -59,8 +62,8 @@ func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool {
func (*roleSearcher) fuzzy(fuzzy map[string]string, item *rbac.Role) bool { func (*roleSearcher) fuzzy(fuzzy map[string]string, item *rbac.Role) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -85,7 +88,7 @@ func (*roleSearcher) compare(a, b *rbac.Role, orderBy string) bool { ...@@ -85,7 +88,7 @@ func (*roleSearcher) compare(a, b *rbac.Role, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -21,8 +21,10 @@ package resources ...@@ -21,8 +21,10 @@ package resources
import ( import (
"github.com/kubesphere/s2ioperator/pkg/apis/devops/v1alpha1" "github.com/kubesphere/s2ioperator/pkg/apis/devops/v1alpha1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
) )
...@@ -38,11 +40,12 @@ func (*s2iBuilderSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*s2iBuilderSearcher) get(namespace, name string) (interface{}, error) {
func (*s2iBuilderSearcher) match(match map[string]string, item *v1alpha1.S2iBuilder) bool { func (*s2iBuilderSearcher) match(match map[string]string, item *v1alpha1.S2iBuilder) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*s2iBuilderSearcher) match(match map[string]string, item *v1alpha1.S2iBuil ...@@ -59,8 +62,8 @@ func (*s2iBuilderSearcher) match(match map[string]string, item *v1alpha1.S2iBuil
func (*s2iBuilderSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iBuilder) bool { func (*s2iBuilderSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iBuilder) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*s2iBuilderSearcher) compare(a, b *v1alpha1.S2iBuilder, orderBy string) bo ...@@ -89,7 +92,7 @@ func (*s2iBuilderSearcher) compare(a, b *v1alpha1.S2iBuilder, orderBy string) bo
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -19,8 +19,10 @@ package resources ...@@ -19,8 +19,10 @@ package resources
import ( import (
"github.com/kubesphere/s2ioperator/pkg/apis/devops/v1alpha1" "github.com/kubesphere/s2ioperator/pkg/apis/devops/v1alpha1"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*s2iBuilderTemplateSearcher) get(namespace, name string) (interface{}, err ...@@ -38,11 +40,12 @@ func (*s2iBuilderTemplateSearcher) get(namespace, name string) (interface{}, err
func (*s2iBuilderTemplateSearcher) match(match map[string]string, item *v1alpha1.S2iBuilderTemplate) bool { func (*s2iBuilderTemplateSearcher) match(match map[string]string, item *v1alpha1.S2iBuilderTemplate) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*s2iBuilderTemplateSearcher) match(match map[string]string, item *v1alpha1 ...@@ -59,8 +62,8 @@ func (*s2iBuilderTemplateSearcher) match(match map[string]string, item *v1alpha1
func (*s2iBuilderTemplateSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iBuilderTemplate) bool { func (*s2iBuilderTemplateSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iBuilderTemplate) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -85,7 +88,7 @@ func (*s2iBuilderTemplateSearcher) compare(a, b *v1alpha1.S2iBuilderTemplate, or ...@@ -85,7 +88,7 @@ func (*s2iBuilderTemplateSearcher) compare(a, b *v1alpha1.S2iBuilderTemplate, or
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -41,15 +43,16 @@ func (*s2iRunSearcher) get(namespace, name string) (interface{}, error) { ...@@ -41,15 +43,16 @@ func (*s2iRunSearcher) get(namespace, name string) (interface{}, error) {
func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) bool { func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case status: case status:
if string(item.Status.RunState) != v { if string(item.Status.RunState) != v {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -66,8 +69,8 @@ func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) boo ...@@ -66,8 +69,8 @@ func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) boo
func (*s2iRunSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iRun) bool { func (*s2iRunSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iRun) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -96,7 +99,7 @@ func (*s2iRunSearcher) compare(a, b *v1alpha1.S2iRun, orderBy string) bool { ...@@ -96,7 +99,7 @@ func (*s2iRunSearcher) compare(a, b *v1alpha1.S2iRun, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,15 +40,16 @@ func (*secretSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,15 +40,16 @@ func (*secretSearcher) get(namespace, name string) (interface{}, error) {
func (*secretSearcher) match(match map[string]string, item *v1.Secret) bool { func (*secretSearcher) match(match map[string]string, item *v1.Secret) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case "type": case "type":
if string(item.Type) != v { if string(item.Type) != v {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -63,8 +66,8 @@ func (*secretSearcher) match(match map[string]string, item *v1.Secret) bool { ...@@ -63,8 +66,8 @@ func (*secretSearcher) match(match map[string]string, item *v1.Secret) bool {
func (*secretSearcher) fuzzy(fuzzy map[string]string, item *v1.Secret) bool { func (*secretSearcher) fuzzy(fuzzy map[string]string, item *v1.Secret) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -93,7 +96,7 @@ func (*secretSearcher) compare(a, b *v1.Secret, orderBy string) bool { ...@@ -93,7 +96,7 @@ func (*secretSearcher) compare(a, b *v1.Secret, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*serviceSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*serviceSearcher) get(namespace, name string) (interface{}, error) {
func (*serviceSearcher) match(match map[string]string, item *v1.Service) bool { func (*serviceSearcher) match(match map[string]string, item *v1.Service) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*serviceSearcher) match(match map[string]string, item *v1.Service) bool { ...@@ -59,8 +62,8 @@ func (*serviceSearcher) match(match map[string]string, item *v1.Service) bool {
func (*serviceSearcher) fuzzy(fuzzy map[string]string, item *v1.Service) bool { func (*serviceSearcher) fuzzy(fuzzy map[string]string, item *v1.Service) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*serviceSearcher) compare(a, b *v1.Service, orderBy string) bool { ...@@ -89,7 +92,7 @@ func (*serviceSearcher) compare(a, b *v1.Service, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -51,6 +53,15 @@ func statefulSetStatus(item *v1.StatefulSet) string { ...@@ -51,6 +53,15 @@ func statefulSetStatus(item *v1.StatefulSet) string {
func (*statefulSetSearcher) match(match map[string]string, item *v1.StatefulSet) bool { func (*statefulSetSearcher) match(match map[string]string, item *v1.StatefulSet) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case Name:
names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false
}
case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false
}
case status: case status:
if statefulSetStatus(item) != v { if statefulSetStatus(item) != v {
return false return false
...@@ -68,8 +79,8 @@ func (*statefulSetSearcher) fuzzy(fuzzy map[string]string, item *v1.StatefulSet) ...@@ -68,8 +79,8 @@ func (*statefulSetSearcher) fuzzy(fuzzy map[string]string, item *v1.StatefulSet)
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -85,10 +96,6 @@ func (*statefulSetSearcher) fuzzy(fuzzy map[string]string, item *v1.StatefulSet) ...@@ -85,10 +96,6 @@ func (*statefulSetSearcher) fuzzy(fuzzy map[string]string, item *v1.StatefulSet)
if !strings.Contains(item.Labels[chart], v) && !strings.Contains(item.Labels[release], v) { if !strings.Contains(item.Labels[chart], v) && !strings.Contains(item.Labels[release], v) {
return false return false
} }
case keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false
}
default: default:
if !searchFuzzy(item.Labels, k, v) && !searchFuzzy(item.Annotations, k, v) { if !searchFuzzy(item.Labels, k, v) && !searchFuzzy(item.Annotations, k, v) {
return false return false
...@@ -103,7 +110,7 @@ func (*statefulSetSearcher) compare(a, b *v1.StatefulSet, orderBy string) bool { ...@@ -103,7 +110,7 @@ func (*statefulSetSearcher) compare(a, b *v1.StatefulSet, orderBy string) bool {
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
package resources package resources
import ( import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*storageClassesSearcher) get(namespace, name string) (interface{}, error) ...@@ -38,11 +40,12 @@ func (*storageClassesSearcher) get(namespace, name string) (interface{}, error)
func (*storageClassesSearcher) match(match map[string]string, item *v1.StorageClass) bool { func (*storageClassesSearcher) match(match map[string]string, item *v1.StorageClass) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*storageClassesSearcher) match(match map[string]string, item *v1.StorageCl ...@@ -59,8 +62,8 @@ func (*storageClassesSearcher) match(match map[string]string, item *v1.StorageCl
func (*storageClassesSearcher) fuzzy(fuzzy map[string]string, item *v1.StorageClass) bool { func (*storageClassesSearcher) fuzzy(fuzzy map[string]string, item *v1.StorageClass) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -85,7 +88,7 @@ func (*storageClassesSearcher) compare(a, b *v1.StorageClass, orderBy string) bo ...@@ -85,7 +88,7 @@ func (*storageClassesSearcher) compare(a, b *v1.StorageClass, orderBy string) bo
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -19,8 +19,10 @@ package resources ...@@ -19,8 +19,10 @@ package resources
import ( import (
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -38,11 +40,12 @@ func (*workspaceSearcher) get(namespace, name string) (interface{}, error) { ...@@ -38,11 +40,12 @@ func (*workspaceSearcher) get(namespace, name string) (interface{}, error) {
func (*workspaceSearcher) match(match map[string]string, item *tenantv1alpha1.Workspace) bool { func (*workspaceSearcher) match(match map[string]string, item *tenantv1alpha1.Workspace) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case name: case Name:
if item.Name != v && item.Labels[displayName] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case keyword: case Keyword:
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
...@@ -59,8 +62,8 @@ func (*workspaceSearcher) match(match map[string]string, item *tenantv1alpha1.Wo ...@@ -59,8 +62,8 @@ func (*workspaceSearcher) match(match map[string]string, item *tenantv1alpha1.Wo
func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *tenantv1alpha1.Workspace) bool { func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *tenantv1alpha1.Workspace) bool {
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case name: case Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
case label: case label:
...@@ -89,7 +92,7 @@ func (*workspaceSearcher) compare(a, b *tenantv1alpha1.Workspace, orderBy string ...@@ -89,7 +92,7 @@ func (*workspaceSearcher) compare(a, b *tenantv1alpha1.Workspace, orderBy string
switch orderBy { switch orderBy {
case CreateTime: case CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case name: case Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -24,7 +24,9 @@ import ( ...@@ -24,7 +24,9 @@ import (
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models/iam" "kubesphere.io/kubesphere/pkg/models/iam"
"kubesphere.io/kubesphere/pkg/models/resources"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
) )
...@@ -36,11 +38,12 @@ type namespaceSearcher struct { ...@@ -36,11 +38,12 @@ type namespaceSearcher struct {
func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) bool { func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case "name": case resources.Name:
if item.Name != v && item.Labels[constants.DisplayNameLabelKey] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case "keyword": case resources.Keyword:
if !strings.Contains(item.Name, v) && !contains(item.Labels, "", v) && !contains(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !contains(item.Labels, "", v) && !contains(item.Annotations, "", v) {
return false return false
} }
...@@ -57,8 +60,8 @@ func (*namespaceSearcher) fuzzy(fuzzy map[string]string, item *v1.Namespace) boo ...@@ -57,8 +60,8 @@ func (*namespaceSearcher) fuzzy(fuzzy map[string]string, item *v1.Namespace) boo
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case "name": case resources.Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels["displayName"], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
default: default:
......
...@@ -39,7 +39,7 @@ func CreateNamespace(workspaceName string, namespace *v1.Namespace, username str ...@@ -39,7 +39,7 @@ func CreateNamespace(workspaceName string, namespace *v1.Namespace, username str
namespace.Labels = make(map[string]string, 0) namespace.Labels = make(map[string]string, 0)
} }
if username != "" { if username != "" {
namespace.Labels[constants.CreatorLabelKey] = username namespace.Annotations[constants.CreatorLabelAnnotationKey] = username
} }
namespace.Labels[constants.WorkspaceLabelKey] = workspaceName namespace.Labels[constants.WorkspaceLabelKey] = workspaceName
......
...@@ -24,7 +24,9 @@ import ( ...@@ -24,7 +24,9 @@ import (
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models/iam" "kubesphere.io/kubesphere/pkg/models/iam"
"kubesphere.io/kubesphere/pkg/models/resources"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
) )
...@@ -36,11 +38,12 @@ type workspaceSearcher struct { ...@@ -36,11 +38,12 @@ type workspaceSearcher struct {
func (*workspaceSearcher) match(match map[string]string, item *v1alpha1.Workspace) bool { func (*workspaceSearcher) match(match map[string]string, item *v1alpha1.Workspace) bool {
for k, v := range match { for k, v := range match {
switch k { switch k {
case "name": case resources.Name:
if item.Name != v && item.Labels[constants.DisplayNameLabelKey] != v { names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) {
return false return false
} }
case "keyword": case resources.Keyword:
if !strings.Contains(item.Name, v) && !contains(item.Labels, "", v) && !contains(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !contains(item.Labels, "", v) && !contains(item.Annotations, "", v) {
return false return false
} }
...@@ -57,8 +60,8 @@ func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.Workspac ...@@ -57,8 +60,8 @@ func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.Workspac
for k, v := range fuzzy { for k, v := range fuzzy {
switch k { switch k {
case "name": case resources.Name:
if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels["displayName"], v) { if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) {
return false return false
} }
default: default:
...@@ -71,9 +74,9 @@ func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.Workspac ...@@ -71,9 +74,9 @@ func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.Workspac
func (*workspaceSearcher) compare(a, b *v1alpha1.Workspace, orderBy string) bool { func (*workspaceSearcher) compare(a, b *v1alpha1.Workspace, orderBy string) bool {
switch orderBy { switch orderBy {
case "createTime": case resources.CreateTime:
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
case "name": case resources.Name:
fallthrough fallthrough
default: default:
return strings.Compare(a.Name, b.Name) <= 0 return strings.Compare(a.Name, b.Name) <= 0
......
...@@ -248,34 +248,33 @@ func isValidShell(validShells []string, shell string) bool { ...@@ -248,34 +248,33 @@ func isValidShell(validShells []string, shell string) bool {
// Waits for the SockJS connection to be opened by the client the session to be bound in handleTerminalSession // Waits for the SockJS connection to be opened by the client the session to be bound in handleTerminalSession
func WaitingForConnection(shell string, namespace, podName, containerName string, sessionId string) { func WaitingForConnection(shell string, namespace, podName, containerName string, sessionId string) {
glog.Infof("WaitingForConnection, ID:%s", sessionId) glog.Infof("WaitingForConnection, ID:%s", sessionId)
session := terminalSessions[sessionId]
select { select {
case <-session.bound: case <-terminalSessions[sessionId].bound:
close(session.bound) close(terminalSessions[sessionId].bound)
defer delete(terminalSessions, sessionId) defer delete(terminalSessions, sessionId)
var err error var err error
validShells := []string{"sh", "bash"} validShells := []string{"sh", "bash"}
if isValidShell(validShells, shell) { if isValidShell(validShells, shell) {
cmd := []string{shell} cmd := []string{shell}
err = startProcess(namespace, podName, containerName, cmd, session) err = startProcess(namespace, podName, containerName, cmd, terminalSessions[sessionId])
} else { } else {
// No shell given or it was not valid: try some shells until one succeeds or all fail // No shell given or it was not valid: try some shells until one succeeds or all fail
// FIXME: if the first shell fails then the first keyboard event is lost // FIXME: if the first shell fails then the first keyboard event is lost
for _, testShell := range validShells { for _, testShell := range validShells {
cmd := []string{testShell} cmd := []string{testShell}
if err = startProcess(namespace, podName, containerName, cmd, session); err == nil { if err = startProcess(namespace, podName, containerName, cmd, terminalSessions[sessionId]); err == nil {
break break
} }
} }
} }
if err != nil { if err != nil {
session.Close(2, err.Error()) terminalSessions[sessionId].Close(2, err.Error())
return return
} }
session.Close(1, "Process exited") terminalSessions[sessionId].Close(1, "Process exited")
} }
} }
......
...@@ -109,7 +109,7 @@ func RemoveUser(workspaceName string, username string) error { ...@@ -109,7 +109,7 @@ func RemoveUser(workspaceName string, username string) error {
if err != nil { if err != nil {
return err return err
} }
err = DeleteWorkspaceRoleBinding(workspaceName, username, workspaceRole.Labels[constants.DisplayNameLabelKey]) err = DeleteWorkspaceRoleBinding(workspaceName, username, workspaceRole.Annotations[constants.DisplayNameAnnotationKey])
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册