diff --git a/pkg/apigateway/caddy-plugin/authenticate/authenticate.go b/pkg/apigateway/caddy-plugin/authenticate/authenticate.go index e23df9b3b7f1610d239467a7802fd911ffded636..696b26bc20facc2a387e42f0a0e6474121dcf234 100644 --- a/pkg/apigateway/caddy-plugin/authenticate/authenticate.go +++ b/pkg/apigateway/caddy-plugin/authenticate/authenticate.go @@ -131,7 +131,7 @@ func (h Auth) InjectContext(req *http.Request, token *jwt.Token) (*http.Request, } // 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) } diff --git a/pkg/apigateway/caddy-plugin/authentication/authentication.go b/pkg/apigateway/caddy-plugin/authentication/authentication.go index cd875176de7f498b5db3ba46c44a23d6b8671001..3270106df3873031a6e3724aa1d14cfec9759bf0 100644 --- a/pkg/apigateway/caddy-plugin/authentication/authentication.go +++ b/pkg/apigateway/caddy-plugin/authentication/authentication.go @@ -23,6 +23,7 @@ import ( "fmt" "k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/endpoints/request" + "kubesphere.io/kubesphere/pkg/utils/k8sutil" "net/http" "strings" @@ -31,7 +32,6 @@ import ( k8serr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/kubernetes/pkg/util/slice" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/utils/sliceutil" ) @@ -132,21 +132,19 @@ func roleValidate(attrs authorizer.Attributes) (bool, error) { } for _, roleBinding := range roleBindings { + if k8sutil.ContainsUser(roleBinding.Subjects, attrs.GetUser().GetName()) { + role, err := roleLister.Roles(attrs.GetNamespace()).Get(roleBinding.RoleRef.Name) - 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) - - if err != nil { - return false, err + if err != nil { + if k8serr.IsNotFound(err) { + continue } + return false, err + } - for _, rule := range role.Rules { - if ruleMatchesRequest(rule, attrs.GetAPIGroup(), "", attrs.GetResource(), attrs.GetSubresource(), attrs.GetName(), attrs.GetVerb()) { - return true, nil - } + for _, rule := range role.Rules { + if ruleMatchesRequest(rule, attrs.GetAPIGroup(), "", attrs.GetResource(), attrs.GetSubresource(), attrs.GetName(), attrs.GetVerb()) { + return true, nil } } } @@ -165,31 +163,28 @@ func clusterRoleValidate(attrs authorizer.Attributes) (bool, error) { for _, clusterRoleBinding := range clusterRoleBindings { - for _, subject := range clusterRoleBinding.Subjects { - - 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) + if k8sutil.ContainsUser(clusterRoleBinding.Subjects, attrs.GetUser().GetName()) { + clusterRole, err := clusterRoleLister.Get(clusterRoleBinding.RoleRef.Name) - if err != nil { - return false, err + if err != nil { + if k8serr.IsNotFound(err) { + continue } + return false, err + } - for _, rule := range clusterRole.Rules { - if attrs.IsResourceRequest() { - if ruleMatchesRequest(rule, attrs.GetAPIGroup(), "", attrs.GetResource(), attrs.GetSubresource(), attrs.GetName(), attrs.GetVerb()) { - return true, nil - } - } else { - if ruleMatchesRequest(rule, "", attrs.GetPath(), "", "", "", attrs.GetVerb()) { - return true, nil - } + for _, rule := range clusterRole.Rules { + if attrs.IsResourceRequest() { + if ruleMatchesRequest(rule, attrs.GetAPIGroup(), "", attrs.GetResource(), attrs.GetSubresource(), attrs.GetName(), attrs.GetVerb()) { + return true, nil + } + } else { + if ruleMatchesRequest(rule, "", attrs.GetPath(), "", "", "", attrs.GetVerb()) { + return true, nil } - } - } + } } diff --git a/pkg/apis/terminal/v1alpha2/register.go b/pkg/apis/terminal/v1alpha2/register.go index 258c6f7cc63f441dd32074701e42b04d450e5d53..c8e84bc61cc26c0c94bf2b85092a6e8bb2c2734a 100644 --- a/pkg/apis/terminal/v1alpha2/register.go +++ b/pkg/apis/terminal/v1alpha2/register.go @@ -41,14 +41,14 @@ func addWebService(c *restful.Container) error { tags := []string{"Terminal"} - webservice.Route(webservice.GET("/namespaces/{namespace}/pods/{pods}"). + webservice.Route(webservice.GET("/namespaces/{namespace}/pods/{pod}"). To(terminal.CreateTerminalSession). Doc("create terminal session"). Metadata(restfulspec.KeyOpenAPITags, tags). Writes(models.PodInfo{})) path := runtime.ApiRootPath + "/" + GroupVersion.String() + "/sockjs" - c.Handle(path, terminal.NewTerminalHandler(path)) + c.Handle(path+"/", terminal.NewTerminalHandler(path)) c.Add(webservice) diff --git a/pkg/apiserver/iam/workspaces.go b/pkg/apiserver/iam/workspaces.go index 67794b2d290db823b057a8dab918a97147fc1e41..b850b4dcbd27b9da63f4f3d28389e591e19318d8 100644 --- a/pkg/apiserver/iam/workspaces.go +++ b/pkg/apiserver/iam/workspaces.go @@ -98,7 +98,7 @@ func DescribeWorkspaceUser(req *restful.Request, resp *restful.Response) { return } - user.WorkspaceRole = workspaceRole.Labels[constants.DisplayNameLabelKey] + user.WorkspaceRole = workspaceRole.Annotations[constants.DisplayNameAnnotationKey] resp.WriteAsJson(user) } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 3225c1581cddfd20a999084d569587692031fc34..40ebc7f223256f8e1cab647b0fb453a0ad8e6276 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -32,8 +32,8 @@ const ( IngressControllerPrefix = "kubesphere-router-" WorkspaceLabelKey = "kubesphere.io/workspace" - DisplayNameLabelKey = "displayName" - CreatorLabelKey = "creator" + DisplayNameAnnotationKey = "displayName" + CreatorLabelAnnotationKey = "creator" OpenPitrixRuntimeAnnotationKey = "openpitrix_runtime" WorkspaceAdmin = "workspace-admin" ClusterAdmin = "cluster-admin" diff --git a/pkg/controller/namespace/namespace_controller.go b/pkg/controller/namespace/namespace_controller.go index 1c24404c05a585a05b306aec5a28db54741caf18..2661e548ff89f48837114d4887b9e3152c7efff8 100644 --- a/pkg/controller/namespace/namespace_controller.go +++ b/pkg/controller/namespace/namespace_controller.go @@ -195,7 +195,7 @@ func (r *ReconcileNamespace) checkAndCreateRoles(namespace *corev1.Namespace) er func (r *ReconcileNamespace) checkAndCreateRoleBindings(namespace *corev1.Namespace) error { 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} diff --git a/pkg/controller/workspace/workspace_controller.go b/pkg/controller/workspace/workspace_controller.go index 126b6a3ed2002e0ee68070a21f03516c2e598603..a897214ebde9651362b754e0638caf5a31a5444b 100644 --- a/pkg/controller/workspace/workspace_controller.go +++ b/pkg/controller/workspace/workspace_controller.go @@ -473,7 +473,8 @@ func getWorkspaceViewerRoleBindingName(workspaceName string) string { func getWorkspaceAdmin(workspaceName string) *rbac.ClusterRole { admin := &rbac.ClusterRole{} 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{ { Verbs: []string{"*"}, @@ -494,7 +495,8 @@ func getWorkspaceAdmin(workspaceName string) *rbac.ClusterRole { func getWorkspaceRegular(workspaceName string) *rbac.ClusterRole { regular := &rbac.ClusterRole{} 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{ { Verbs: []string{"get"}, @@ -521,7 +523,8 @@ func getWorkspaceRegular(workspaceName string) *rbac.ClusterRole { func getWorkspaceViewer(workspaceName string) *rbac.ClusterRole { viewer := &rbac.ClusterRole{} 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{ { Verbs: []string{"get", "list"}, diff --git a/pkg/models/iam/am.go b/pkg/models/iam/am.go index 34501b25749ce0144a03bc5efbb34c327b2144c2..22750edfa66a1e110dd12c2e15ef62e081fd6b9c 100644 --- a/pkg/models/iam/am.go +++ b/pkg/models/iam/am.go @@ -413,7 +413,7 @@ func ListWorkspaceRoles(workspace string, conditions *params.Conditions, orderBy for i, item := range result.Items { if role, ok := item.(*v1.ClusterRole); ok { role = role.DeepCopy() - role.Name = role.Labels[constants.DisplayNameLabelKey] + role.Name = role.Annotations[constants.DisplayNameAnnotationKey] result.Items[i] = role } } @@ -477,7 +477,7 @@ func GetUserWorkspaceSimpleRules(workspace, username string) ([]models.SimpleRul if err != nil { 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 { diff --git a/pkg/models/resources/clusterroles.go b/pkg/models/resources/clusterroles.go index 0de2e0ad2a6569eb4997f4d162756213819bf325..f37de1f280216c1865e6f52334a870fb71e333c0 100644 --- a/pkg/models/resources/clusterroles.go +++ b/pkg/models/resources/clusterroles.go @@ -22,6 +22,7 @@ import ( "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/utils/k8sutil" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -48,11 +49,12 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol if !k8sutil.IsControlledBy(item.OwnerReferences, kind, name) { return false } - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -101,7 +103,7 @@ func (*clusterRoleSearcher) compare(a, b *rbac.ClusterRole, orderBy string) bool switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 @@ -143,7 +145,7 @@ func (s *clusterRoleSearcher) search(namespace string, conditions *params.Condit } 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 false diff --git a/pkg/models/resources/configmaps.go b/pkg/models/resources/configmaps.go index f2f0a2c6c37087628910c8adf5000daac9023cc1..4e4ed71db40e9e6dd7a78f414d9b85d97b8dbe64 100644 --- a/pkg/models/resources/configmaps.go +++ b/pkg/models/resources/configmaps.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*configMapSearcher) get(namespace, name string) (interface{}, error) { func (*configMapSearcher) match(match map[string]string, item *v1.ConfigMap) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*configMapSearcher) compare(a, b *v1.ConfigMap, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/cronjobs.go b/pkg/models/resources/cronjobs.go index e3e0a2f6095c98df91f709c27f7ac24a4380006f..fe90ad3ee74d1493fdf12dcecfbbd0681b1e45ee 100644 --- a/pkg/models/resources/cronjobs.go +++ b/pkg/models/resources/cronjobs.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -46,15 +48,16 @@ func cronJobStatus(item *v1beta1.CronJob) string { func (*cronJobSearcher) match(match map[string]string, item *v1beta1.CronJob) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } case status: if cronJobStatus(item) != v { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -71,8 +74,8 @@ func (*cronJobSearcher) fuzzy(fuzzy map[string]string, item *v1beta1.CronJob) bo for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -112,7 +115,7 @@ func (*cronJobSearcher) compare(a, b *v1beta1.CronJob, orderBy string) bool { return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) default: fallthrough - case name: + case Name: return strings.Compare(a.Name, b.Name) <= 0 } } diff --git a/pkg/models/resources/daemonsets.go b/pkg/models/resources/daemonsets.go index df2241390bde3838b2fb30c4ed8e3d738f00e6f9..b4e256f913f8ca38745c4e86caabb75893167e88 100644 --- a/pkg/models/resources/daemonsets.go +++ b/pkg/models/resources/daemonsets.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -52,11 +54,12 @@ func (*daemonSetSearcher) match(match map[string]string, item *v1.DaemonSet) boo if daemonSetStatus(item) != v { return false } - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -73,8 +76,8 @@ func (*daemonSetSearcher) fuzzy(fuzzy map[string]string, item *v1.DaemonSet) boo for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -104,7 +107,7 @@ func (*daemonSetSearcher) compare(a, b *v1.DaemonSet, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/deployments.go b/pkg/models/resources/deployments.go index 3983b067b5db6c624602d14c9d20df7f422b76a4..97fbc8dc8feb247e353aa51a56ffb8bb46de06af 100644 --- a/pkg/models/resources/deployments.go +++ b/pkg/models/resources/deployments.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -56,11 +58,12 @@ func (*deploymentSearcher) match(match map[string]string, item *v1.Deployment) b if deploymentStatus(item) != v { return false } - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -77,8 +80,8 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -108,7 +111,7 @@ func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/ingresses.go b/pkg/models/resources/ingresses.go index e39aef38f8accbd6e9cbdb72406ea9b99b6f1690..3d7967bc44cd6e5340ffa0bb3751e466dfea8478 100644 --- a/pkg/models/resources/ingresses.go +++ b/pkg/models/resources/ingresses.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -39,11 +41,12 @@ func (*ingressSearcher) get(namespace, name string) (interface{}, error) { func (*ingressSearcher) match(match map[string]string, item *extensions.Ingress) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -90,7 +93,7 @@ func (*ingressSearcher) compare(a, b *extensions.Ingress, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/jobs.go b/pkg/models/resources/jobs.go index 1b47510d7dee9c348490fa7a881140a6d014604a..d22b0a577f1f38816624890b7d7ede750462c964 100644 --- a/pkg/models/resources/jobs.go +++ b/pkg/models/resources/jobs.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" "time" @@ -58,11 +60,12 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool { if jobStatus(item) != v { return false } - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -79,8 +82,8 @@ func (*jobSearcher) fuzzy(fuzzy map[string]string, item *batchv1.Job) bool { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -125,7 +128,7 @@ func (*jobSearcher) compare(a, b *batchv1.Job, orderBy string) bool { return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) case updateTime: return jobUpdateTime(a).Before(jobUpdateTime(b)) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/namespaces.go b/pkg/models/resources/namespaces.go index 76aa6c4e41a4c2ede0e90b3b572cd07a1e53c488..9aa5a6dcd37fcbcbfd8561829bd6ebfabe77766f 100644 --- a/pkg/models/resources/namespaces.go +++ b/pkg/models/resources/namespaces.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*namespaceSearcher) get(namespace, name string) (interface{}, error) { func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*namespaceSearcher) compare(a, b *v1.Namespace, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/nodes.go b/pkg/models/resources/nodes.go index af8366c9ce2e7022c93aec98c4c0adc3f839d1b5..530a442f8ee141e3ba6c5524dec0e6ad7318c398 100644 --- a/pkg/models/resources/nodes.go +++ b/pkg/models/resources/nodes.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*nodeSearcher) get(namespace, name string) (interface{}, error) { func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*nodeSearcher) compare(a, b *v1.Node, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/persistentvolumeclaims.go b/pkg/models/resources/persistentvolumeclaims.go index 2d6790312e50e152fe3e49c3bdff0c7d822de627..c50e1d35e0d000d61fb54a689d2f23ef8960125b 100644 --- a/pkg/models/resources/persistentvolumeclaims.go +++ b/pkg/models/resources/persistentvolumeclaims.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*persistentVolumeClaimSearcher) get(namespace, name string) (interface{}, func (*persistentVolumeClaimSearcher) match(match map[string]string, item *v1.PersistentVolumeClaim) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*persistentVolumeClaimSearcher) compare(a, b *v1.PersistentVolumeClaim, or switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/pods.go b/pkg/models/resources/pods.go index df95d97bbcd730c3391c7f4c15bc1961cccac21f..33ada22f3ffdf46de9aa32b4912d4419e251552e 100644 --- a/pkg/models/resources/pods.go +++ b/pkg/models/resources/pods.go @@ -19,8 +19,10 @@ package resources import ( v12 "k8s.io/api/apps/v1" + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -168,11 +170,12 @@ func (*podSearcher) match(match map[string]string, item *v1.Pod) bool { if !podBelongToService(item, v) { return false } - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -219,7 +222,7 @@ func (*podSearcher) compare(a, b *v1.Pod, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/resources.go b/pkg/models/resources/resources.go index ea415872d364f935e9e32b577eb241b9aee6684a..5a64e3af890ede0c7aeba67c862f39a00a538e3d 100644 --- a/pkg/models/resources/resources.go +++ b/pkg/models/resources/resources.go @@ -55,18 +55,17 @@ var ( ) const ( - name = "name" + Name = "name" label = "label" ownerKind = "ownerKind" ownerName = "ownerName" - CreateTime = "CreateTime" + CreateTime = "createTime" updateTime = "updateTime" lastScheduleTime = "lastScheduleTime" - displayName = "displayName" chart = "chart" release = "release" annotation = "annotation" - keyword = "keyword" + Keyword = "keyword" status = "status" running = "running" paused = "paused" diff --git a/pkg/models/resources/roles.go b/pkg/models/resources/roles.go index 221d42a208968ebd65defcdec997dd7f32c84535..1fbc8f2ae76dcf82f50b00f1ecf322c78daa238e 100644 --- a/pkg/models/resources/roles.go +++ b/pkg/models/resources/roles.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*roleSearcher) get(namespace, name string) (interface{}, error) { func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -85,7 +88,7 @@ func (*roleSearcher) compare(a, b *rbac.Role, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/s2ibuilder.go b/pkg/models/resources/s2ibuilder.go index 0a9f11a8529ad749e87fe60a299c828393257581..b67be7e57f79cffe223b9c5ce13380812f7cee6e 100644 --- a/pkg/models/resources/s2ibuilder.go +++ b/pkg/models/resources/s2ibuilder.go @@ -21,8 +21,10 @@ package resources import ( "github.com/kubesphere/s2ioperator/pkg/apis/devops/v1alpha1" "k8s.io/apimachinery/pkg/labels" + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" ) @@ -38,11 +40,12 @@ func (*s2iBuilderSearcher) get(namespace, name string) (interface{}, error) { func (*s2iBuilderSearcher) match(match map[string]string, item *v1alpha1.S2iBuilder) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*s2iBuilderSearcher) compare(a, b *v1alpha1.S2iBuilder, orderBy string) bo switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/s2ibuildertemplate.go b/pkg/models/resources/s2ibuildertemplate.go index 7140323b4ff02e751217e58c1ccffdc5a53eaf4b..9479f9cfa54b99b357704699d19f775ea159c748 100644 --- a/pkg/models/resources/s2ibuildertemplate.go +++ b/pkg/models/resources/s2ibuildertemplate.go @@ -19,8 +19,10 @@ package resources import ( "github.com/kubesphere/s2ioperator/pkg/apis/devops/v1alpha1" + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*s2iBuilderTemplateSearcher) get(namespace, name string) (interface{}, err func (*s2iBuilderTemplateSearcher) match(match map[string]string, item *v1alpha1.S2iBuilderTemplate) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -59,8 +62,8 @@ func (*s2iBuilderTemplateSearcher) match(match map[string]string, item *v1alpha1 func (*s2iBuilderTemplateSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.S2iBuilderTemplate) bool { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -85,7 +88,7 @@ func (*s2iBuilderTemplateSearcher) compare(a, b *v1alpha1.S2iBuilderTemplate, or switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/s2irun.go b/pkg/models/resources/s2irun.go index 72f23ce93f94a48841f3ee6b1bd44f62da8586ff..b00244dee381442b2fbc28c8a9e77d96647ebe5c 100644 --- a/pkg/models/resources/s2irun.go +++ b/pkg/models/resources/s2irun.go @@ -19,6 +19,8 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -41,15 +43,16 @@ func (*s2iRunSearcher) get(namespace, name string) (interface{}, error) { func (*s2iRunSearcher) match(match map[string]string, item *v1alpha1.S2iRun) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + 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: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -96,7 +99,7 @@ func (*s2iRunSearcher) compare(a, b *v1alpha1.S2iRun, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/secrets.go b/pkg/models/resources/secrets.go index 7eefd2f9313d1310592ca270194b1c82e06b0ae3..883119bb48c8fae65d33d9f9b6dfe69c187d0ab0 100644 --- a/pkg/models/resources/secrets.go +++ b/pkg/models/resources/secrets.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,15 +40,16 @@ func (*secretSearcher) get(namespace, name string) (interface{}, error) { func (*secretSearcher) match(match map[string]string, item *v1.Secret) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } case "type": if string(item.Type) != v { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -93,7 +96,7 @@ func (*secretSearcher) compare(a, b *v1.Secret, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/services.go b/pkg/models/resources/services.go index b5dc7535fbdae87ef11acd2a28a75a3b62fc66c5..0b38d2e0525fc2e4fe13d7986ff88d5931e10e88 100644 --- a/pkg/models/resources/services.go +++ b/pkg/models/resources/services.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*serviceSearcher) get(namespace, name string) (interface{}, error) { func (*serviceSearcher) match(match map[string]string, item *v1.Service) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*serviceSearcher) compare(a, b *v1.Service, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/statefulsets.go b/pkg/models/resources/statefulsets.go index e3f9789d06340025880e4e8528c630f1220ceaa9..474d8ca5626935e8554f934526e434c763ee7538 100644 --- a/pkg/models/resources/statefulsets.go +++ b/pkg/models/resources/statefulsets.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -51,6 +53,15 @@ func statefulSetStatus(item *v1.StatefulSet) string { func (*statefulSetSearcher) match(match map[string]string, item *v1.StatefulSet) bool { for k, v := range match { 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: if statefulSetStatus(item) != v { return false @@ -68,8 +79,8 @@ func (*statefulSetSearcher) fuzzy(fuzzy map[string]string, item *v1.StatefulSet) for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -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) { return false } - case keyword: - if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { - return false - } default: if !searchFuzzy(item.Labels, k, v) && !searchFuzzy(item.Annotations, k, v) { return false @@ -103,7 +110,7 @@ func (*statefulSetSearcher) compare(a, b *v1.StatefulSet, orderBy string) bool { switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/storageclasses.go b/pkg/models/resources/storageclasses.go index ba21aaef01904d5e37c7cd7eb83c30d5662e768c..7f11b9d21543ab6dc2ec4e09de4358bc1c52f000 100644 --- a/pkg/models/resources/storageclasses.go +++ b/pkg/models/resources/storageclasses.go @@ -18,8 +18,10 @@ package resources import ( + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*storageClassesSearcher) get(namespace, name string) (interface{}, error) func (*storageClassesSearcher) match(match map[string]string, item *v1.StorageClass) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -85,7 +88,7 @@ func (*storageClassesSearcher) compare(a, b *v1.StorageClass, orderBy string) bo switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/resources/workspaces.go b/pkg/models/resources/workspaces.go index 41580b6a0a62c0b98e04651b6245723383ccf910..63ed46ea0732ffc7e42cff52edc2378cf6512d8f 100644 --- a/pkg/models/resources/workspaces.go +++ b/pkg/models/resources/workspaces.go @@ -19,8 +19,10 @@ package resources import ( tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" + "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" @@ -38,11 +40,12 @@ func (*workspaceSearcher) get(namespace, name string) (interface{}, error) { func (*workspaceSearcher) match(match map[string]string, item *tenantv1alpha1.Workspace) bool { for k, v := range match { switch k { - case name: - if item.Name != v && item.Labels[displayName] != v { + case Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case keyword: + case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false } @@ -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 { for k, v := range fuzzy { switch k { - case name: - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels[displayName], v) { + case Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } case label: @@ -89,7 +92,7 @@ func (*workspaceSearcher) compare(a, b *tenantv1alpha1.Workspace, orderBy string switch orderBy { case CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case name: + case Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/tenant/namespaces.go b/pkg/models/tenant/namespaces.go index 72dc916f4d3daf0348eccdc739394dbf045d78a4..23f4fa5314ed85feee95d20837016d169525ae90 100644 --- a/pkg/models/tenant/namespaces.go +++ b/pkg/models/tenant/namespaces.go @@ -24,7 +24,9 @@ import ( "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/models/iam" + "kubesphere.io/kubesphere/pkg/models/resources" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" ) @@ -36,11 +38,12 @@ type namespaceSearcher struct { func (*namespaceSearcher) match(match map[string]string, item *v1.Namespace) bool { for k, v := range match { switch k { - case "name": - if item.Name != v && item.Labels[constants.DisplayNameLabelKey] != v { + case resources.Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case "keyword": + case resources.Keyword: if !strings.Contains(item.Name, v) && !contains(item.Labels, "", v) && !contains(item.Annotations, "", v) { return false } @@ -57,8 +60,8 @@ func (*namespaceSearcher) fuzzy(fuzzy map[string]string, item *v1.Namespace) boo for k, v := range fuzzy { switch k { - case "name": - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels["displayName"], v) { + case resources.Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } default: diff --git a/pkg/models/tenant/tenant.go b/pkg/models/tenant/tenant.go index 1f478b3af712f5a2432a534c22bfd67c3f19e2d8..642402abc440957a273b70801d7e84dbbdd89269 100644 --- a/pkg/models/tenant/tenant.go +++ b/pkg/models/tenant/tenant.go @@ -39,7 +39,7 @@ func CreateNamespace(workspaceName string, namespace *v1.Namespace, username str namespace.Labels = make(map[string]string, 0) } if username != "" { - namespace.Labels[constants.CreatorLabelKey] = username + namespace.Annotations[constants.CreatorLabelAnnotationKey] = username } namespace.Labels[constants.WorkspaceLabelKey] = workspaceName diff --git a/pkg/models/tenant/workspaces.go b/pkg/models/tenant/workspaces.go index 50d4860d0530345bf9728329655bd747a498d840..524bde1dc12ef0356635eace619966e5325c821d 100644 --- a/pkg/models/tenant/workspaces.go +++ b/pkg/models/tenant/workspaces.go @@ -24,7 +24,9 @@ import ( "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/models/iam" + "kubesphere.io/kubesphere/pkg/models/resources" "kubesphere.io/kubesphere/pkg/params" + "kubesphere.io/kubesphere/pkg/utils/sliceutil" "sort" "strings" ) @@ -36,11 +38,12 @@ type workspaceSearcher struct { func (*workspaceSearcher) match(match map[string]string, item *v1alpha1.Workspace) bool { for k, v := range match { switch k { - case "name": - if item.Name != v && item.Labels[constants.DisplayNameLabelKey] != v { + case resources.Name: + names := strings.Split(v, "|") + if !sliceutil.HasString(names, item.Name) { return false } - case "keyword": + case resources.Keyword: if !strings.Contains(item.Name, v) && !contains(item.Labels, "", v) && !contains(item.Annotations, "", v) { return false } @@ -57,8 +60,8 @@ func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.Workspac for k, v := range fuzzy { switch k { - case "name": - if !strings.Contains(item.Name, v) && !strings.Contains(item.Labels["displayName"], v) { + case resources.Name: + if !strings.Contains(item.Name, v) && !strings.Contains(item.Annotations[constants.DisplayNameAnnotationKey], v) { return false } default: @@ -71,9 +74,9 @@ func (*workspaceSearcher) fuzzy(fuzzy map[string]string, item *v1alpha1.Workspac func (*workspaceSearcher) compare(a, b *v1alpha1.Workspace, orderBy string) bool { switch orderBy { - case "createTime": + case resources.CreateTime: return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time) - case "name": + case resources.Name: fallthrough default: return strings.Compare(a.Name, b.Name) <= 0 diff --git a/pkg/models/terminal/terminal.go b/pkg/models/terminal/terminal.go index 6a665ddc9ecb898f302e300362aa79f93eb2c050..67b2a21c1a350ed045c4b12c839fc58ebe7ee101 100644 --- a/pkg/models/terminal/terminal.go +++ b/pkg/models/terminal/terminal.go @@ -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 func WaitingForConnection(shell string, namespace, podName, containerName string, sessionId string) { glog.Infof("WaitingForConnection, ID:%s", sessionId) - session := terminalSessions[sessionId] select { - case <-session.bound: - close(session.bound) + case <-terminalSessions[sessionId].bound: + close(terminalSessions[sessionId].bound) defer delete(terminalSessions, sessionId) var err error validShells := []string{"sh", "bash"} if isValidShell(validShells, shell) { cmd := []string{shell} - err = startProcess(namespace, podName, containerName, cmd, session) + err = startProcess(namespace, podName, containerName, cmd, terminalSessions[sessionId]) } else { // 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 for _, testShell := range validShells { 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 } } } if err != nil { - session.Close(2, err.Error()) + terminalSessions[sessionId].Close(2, err.Error()) return } - session.Close(1, "Process exited") + terminalSessions[sessionId].Close(1, "Process exited") } } diff --git a/pkg/models/workspaces/workspaces.go b/pkg/models/workspaces/workspaces.go index 7a7ef15f9d777f078eb6087f7decc764d2964544..750af1fbe4f0a038cc2e41f1df99603fb42c5787 100644 --- a/pkg/models/workspaces/workspaces.go +++ b/pkg/models/workspaces/workspaces.go @@ -109,7 +109,7 @@ func RemoveUser(workspaceName string, username string) error { if err != nil { return err } - err = DeleteWorkspaceRoleBinding(workspaceName, username, workspaceRole.Labels[constants.DisplayNameLabelKey]) + err = DeleteWorkspaceRoleBinding(workspaceName, username, workspaceRole.Annotations[constants.DisplayNameAnnotationKey]) if err != nil { return err }