未验证 提交 6f7e59ca 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #3045 from zackzhangkai/ks-kiali-support-out-cluster

kiali k8s client support out-cluster
......@@ -18,10 +18,13 @@ package app
import (
"fmt"
"github.com/kiali/kiali/business"
kconfig "github.com/kiali/kiali/config"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/prometheus"
"github.com/spf13/cobra"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog"
......@@ -115,4 +118,16 @@ func initializeServicemeshConfig(s *options.ServerRunOptions) {
config.ExternalServices.Istio.UrlServiceVersion = s.ServiceMeshOptions.IstioPilotHost
kconfig.Set(config)
// Set kiali config
kubeconfig, err := clientcmd.BuildConfigFromFlags("", s.KubernetesOptions.KubeConfig)
if err != nil {
fmt.Println(err)
}
k8sClient, err := kubernetes.NewClientFromConfig(kubeconfig)
if err != nil {
fmt.Println(err)
}
prometheusClient, _ := prometheus.NewClient()
business.SetWithBackends(k8sClient, prometheusClient)
}
......@@ -47,7 +47,7 @@ require (
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/json-iterator/go v1.1.9
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/kiali/kiali v0.15.1-0.20200520152915-769a61d75460
github.com/kiali/kiali v1.25.0
github.com/kubernetes-csi/external-snapshotter/v2 v2.1.0
github.com/kubesphere/sonargo v0.0.2
github.com/lib/pq v1.2.0 // indirect
......@@ -283,7 +283,7 @@ replace (
github.com/kelseyhightower/envconfig => github.com/kelseyhightower/envconfig v1.4.0
github.com/kevinburke/ssh_config => github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e
github.com/keybase/go-ps => github.com/keybase/go-ps v0.0.0-20161005175911-668c8856d999
github.com/kiali/kiali => github.com/kubesphere/kiali v0.15.1-0.20200520152915-769a61d75460
github.com/kiali/kiali => github.com/kubesphere/kiali v0.15.1-0.20201030070213-04b6506d6c7d
github.com/kisielk/errcheck => github.com/kisielk/errcheck v1.2.0
github.com/kisielk/gotool => github.com/kisielk/gotool v1.0.0
github.com/koding/multiconfig => github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
......
......@@ -37,9 +37,8 @@ func validateURL(serviceURL string) (*url.URL, error) {
return url.ParseRequestURI(serviceURL)
}
func checkNamespaceAccess(w http.ResponseWriter, k8s kubernetes.IstioClientInterface, prom prometheus.ClientInterface, namespace string) *models.Namespace {
layer := business.NewWithBackends(k8s, prom)
func checkNamespaceAccess(w http.ResponseWriter, prom prometheus.ClientInterface, namespace string) *models.Namespace {
layer, _ := business.Get()
if nsInfo, err := layer.Namespace.GetNamespace(namespace); err != nil {
RespondWithError(w, http.StatusForbidden, "Cannot access namespace data: "+err.Error())
return nil
......@@ -49,22 +48,15 @@ func checkNamespaceAccess(w http.ResponseWriter, k8s kubernetes.IstioClientInter
}
func initClientsForMetrics(w http.ResponseWriter, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier, namespace string) (*prometheus.Client, kubernetes.IstioClientInterface, *models.Namespace) {
k8s, err := k8sSupplier()
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusServiceUnavailable, "Kubernetes client error: "+err.Error())
return nil, nil, nil
}
prom, err := promSupplier()
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusServiceUnavailable, "Prometheus client error: "+err.Error())
return nil, nil, nil
}
nsInfo := checkNamespaceAccess(w, k8s, prom, namespace)
nsInfo := checkNamespaceAccess(w, prom, namespace)
if nsInfo == nil {
return nil, nil, nil
}
return prom, k8s, nsInfo
return prom, nil, nsInfo
}
......@@ -136,9 +136,9 @@ github.com/elastic/go-elasticsearch/v7/estransport
github.com/elastic/go-elasticsearch/v7/internal/version
# github.com/emicklei/go-restful v2.14.3+incompatible => github.com/emicklei/go-restful v2.14.3+incompatible
github.com/emicklei/go-restful
github.com/emicklei/go-restful/log
# github.com/emicklei/go-restful-openapi v1.4.1 => github.com/emicklei/go-restful-openapi v1.4.1
github.com/emicklei/go-restful-openapi
github.com/emicklei/go-restful/log
# github.com/emirpasic/gods v1.12.0 => github.com/emirpasic/gods v1.12.0
github.com/emirpasic/gods/containers
github.com/emirpasic/gods/lists
......@@ -304,7 +304,7 @@ github.com/jmespath/go-jmespath
github.com/json-iterator/go
# github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e => github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e
github.com/kevinburke/ssh_config
# github.com/kiali/kiali v0.15.1-0.20200520152915-769a61d75460 => github.com/kubesphere/kiali v0.15.1-0.20200520152915-769a61d75460
# github.com/kiali/kiali v1.25.0 => github.com/kubesphere/kiali v0.15.1-0.20201030070213-04b6506d6c7d
github.com/kiali/kiali/business
github.com/kiali/kiali/business/checkers
github.com/kiali/kiali/business/checkers/destinationrules
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册