kiali k8s client support out-cluster

Signed-off-by: zackzhangkai <zackzhang@yunify.com>
This commit is contained in:
zackzhangkai
2020-10-30 14:41:39 +08:00
parent 675823b978
commit e4049e4e66
5 changed files with 26 additions and 19 deletions

View File

@@ -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
View File

@@ -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