From addf11c38b51f0924791d6920755178166b5bc86 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 23 Apr 2019 19:41:18 +0800 Subject: [PATCH] fix nodeport router --- pkg/apiserver/routers/routers.go | 5 ++--- pkg/constants/constants.go | 24 +++++++++++++----------- pkg/models/components/components.go | 11 +++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/apiserver/routers/routers.go b/pkg/apiserver/routers/routers.go index 471e2a7f..af1df5c5 100644 --- a/pkg/apiserver/routers/routers.go +++ b/pkg/apiserver/routers/routers.go @@ -144,9 +144,8 @@ func parseParameter(router Router) (routerType v1.ServiceType, annotationMap map routerType = v1.ServiceTypeNodePort if strings.Compare(strings.ToLower(router.RouterType), "loadbalancer") == 0 { - return v1.ServiceTypeLoadBalancer, router.Annotations, nil - } else { - return v1.ServiceTypeNodePort, make(map[string]string, 0), nil + routerType = v1.ServiceTypeLoadBalancer } + return routerType, router.Annotations, nil } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 40ebc7f2..41d713e0 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -20,16 +20,18 @@ package constants const ( APIVersion = "v1alpha1" - KubeSystemNamespace = "kube-system" - OpenPitrixNamespace = "openpitrix-system" - IstioNamespace = "istio-system" - KubeSphereNamespace = "kubesphere-system" - KubeSphereControlNamespace = "kubesphere-controls-system" - IngressControllerNamespace = KubeSphereControlNamespace - AdminUserName = "admin" - DataHome = "/etc/kubesphere" - IngressControllerFolder = DataHome + "/ingress-controller" - IngressControllerPrefix = "kubesphere-router-" + KubeSystemNamespace = "kube-system" + OpenPitrixNamespace = "openpitrix-system" + IstioNamespace = "istio-system" + KubeSphereMonitoringNamespace = "kubesphere-monitoring-system" + KubeSphereLoggingNamespace = "kubesphere-logging-system" + KubeSphereNamespace = "kubesphere-system" + KubeSphereControlNamespace = "kubesphere-controls-system" + IngressControllerNamespace = KubeSphereControlNamespace + AdminUserName = "admin" + DataHome = "/etc/kubesphere" + IngressControllerFolder = DataHome + "/ingress-controller" + IngressControllerPrefix = "kubesphere-router-" WorkspaceLabelKey = "kubesphere.io/workspace" DisplayNameAnnotationKey = "displayName" @@ -47,5 +49,5 @@ const ( var ( WorkSpaceRoles = []string{WorkspaceAdmin, WorkspaceRegular, WorkspaceViewer} - SystemNamespaces = []string{KubeSphereNamespace, OpenPitrixNamespace, KubeSystemNamespace} + SystemNamespaces = []string{KubeSphereNamespace, KubeSphereLoggingNamespace, KubeSphereMonitoringNamespace, OpenPitrixNamespace, KubeSystemNamespace, IstioNamespace} ) diff --git a/pkg/models/components/components.go b/pkg/models/components/components.go index 6cccff62..e9c274a0 100644 --- a/pkg/models/components/components.go +++ b/pkg/models/components/components.go @@ -18,6 +18,7 @@ package components import ( + "fmt" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "kubesphere.io/kubesphere/pkg/models" "kubesphere.io/kubesphere/pkg/simple/client/k8s" @@ -49,6 +50,10 @@ func GetComponentStatus(name string) (interface{}, error) { return nil, err } + if len(service.Spec.Selector) == 0 { + return nil, fmt.Errorf("component %s has no selector", name) + } + podLister := informers.SharedInformerFactory().Core().V1().Pods().Lister() pods, err := podLister.Pods(service.Namespace).List(labels.SelectorFromValidatedSet(service.Spec.Selector)) @@ -148,6 +153,12 @@ func GetAllComponentsStatus() (map[string]interface{}, error) { } for _, service := range services { + + // skip services without a selector + if len(service.Spec.Selector) == 0 { + continue + } + component := models.Component{ Name: service.Name, Namespace: service.Namespace, -- GitLab