kiali k8s client support out-cluster
Signed-off-by: zackzhangkai <zackzhang@yunify.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
4
go.mod
4
go.mod
@@ -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
|
||||
|
||||
4
go.sum
4
go.sum
@@ -296,8 +296,8 @@ github.com/kubernetes-csi/csi-lib-utils v0.7.0/go.mod h1:bze+2G9+cmoHxN6+WyG1qT4
|
||||
github.com/kubernetes-csi/csi-test v2.0.0+incompatible/go.mod h1:YxJ4UiuPWIhMBkxUKY5c267DyA0uDZ/MtAimhx/2TA0=
|
||||
github.com/kubernetes-csi/external-snapshotter/v2 v2.1.0 h1:a1cpbNAdOTHO7Lk5UO5tjcbYPEEamIxmzATt+pKoDhc=
|
||||
github.com/kubernetes-csi/external-snapshotter/v2 v2.1.0/go.mod h1:dV5oB3U62KBdlf9ADWkMmjGd3USauqQtwIm2OZb5mqI=
|
||||
github.com/kubesphere/kiali v0.15.1-0.20200520152915-769a61d75460 h1:EcC/7blefyiDDDq3xfBlQj/vHL2ytz/JEpgHkeXKbpc=
|
||||
github.com/kubesphere/kiali v0.15.1-0.20200520152915-769a61d75460/go.mod h1:Y1EqeixoXkKkU8I+yvOfhdh21+8+etFE6wYOVT2XFdI=
|
||||
github.com/kubesphere/kiali v0.15.1-0.20201030070213-04b6506d6c7d h1:/q8KYXKrLMfK4izrP3dzy6Uq8dQF8IbowRWDKiI1/Rg=
|
||||
github.com/kubesphere/kiali v0.15.1-0.20201030070213-04b6506d6c7d/go.mod h1:Y1EqeixoXkKkU8I+yvOfhdh21+8+etFE6wYOVT2XFdI=
|
||||
github.com/kubesphere/sonargo v0.0.2 h1:hsSRE3sv3mkPcUAeSABdp7rtfcNW2zzeHXzFa01CTkU=
|
||||
github.com/kubesphere/sonargo v0.0.2/go.mod h1:ww8n9ANlDXhX5PBZ18iaRnCgEkXN0GMml3/KZXOZ11w=
|
||||
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
|
||||
|
||||
16
vendor/github.com/kiali/kiali/handlers/utils.go
generated
vendored
16
vendor/github.com/kiali/kiali/handlers/utils.go
generated
vendored
@@ -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
|
||||
}
|
||||
|
||||
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user