/
mesh.go
113 lines (93 loc) · 3.43 KB
/
mesh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package handlers
import (
"fmt"
"net/http"
"github.com/kiali/kiali/business"
"github.com/kiali/kiali/config"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/kubernetes/cache"
"github.com/kiali/kiali/mesh"
"github.com/kiali/kiali/mesh/api"
"github.com/kiali/kiali/prometheus"
"github.com/kiali/kiali/tracing"
)
// GetClusters writes to the HTTP response a JSON document with the
// list of clusters that are part of the mesh when multi-cluster is enabled. If
// multi-cluster is not enabled in the control plane, this handler may provide
// erroneous data.
func GetClusters(conf *config.Config, kialiCache cache.KialiCache, clientFactory kubernetes.ClientFactory, prom prometheus.ClientInterface, traceClientLoader func() tracing.ClientInterface, cpm business.ControlPlaneMonitor) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
authInfo, err := getAuthInfo(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
layer, err := business.NewLayer(conf, kialiCache, clientFactory, prom, traceClientLoader(), cpm, authInfo)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
meshClusters, err := layer.Mesh.GetClusters()
if err != nil {
RespondWithError(w, http.StatusServiceUnavailable, "Cannot fetch mesh clusters: "+err.Error())
return
}
RespondWithJSON(w, http.StatusOK, meshClusters)
}
}
func OutboundTrafficPolicyMode(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
otp, _ := business.Mesh.OutboundTrafficPolicy()
RespondWithJSON(w, http.StatusOK, otp)
}
func IstiodResourceThresholds(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
irt, _ := business.Mesh.IstiodResourceThresholds()
RespondWithJSON(w, http.StatusOK, irt)
}
func IstiodCanariesStatus(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
irt, _ := business.Mesh.CanaryUpgradeStatus()
RespondWithJSON(w, http.StatusOK, irt)
}
func GetMesh(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
conf := config.Get()
// Ensure user has access to the istio system namespace on the home cluster at least.
// There is no access check in GetMesh.
if _, err := business.Namespace.GetClusterNamespace(r.Context(), conf.IstioNamespace, conf.KubernetesConfig.ClusterName); err != nil {
RespondWithError(w, http.StatusForbidden, fmt.Sprintf("Unable to access '%s' namespace. You need access to this to get mesh info. Error: %s ", conf.IstioNamespace, err))
return
}
mesh, err := business.Mesh.GetMesh(r.Context())
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
RespondWithJSON(w, http.StatusOK, mesh)
}
// MeshGraph is a REST http.HandlerFunc handling graph generation for the mesh
func MeshGraph(w http.ResponseWriter, r *http.Request) {
defer handlePanic(w)
o := mesh.NewOptions(r)
business, err := getBusiness(r)
mesh.CheckError(err)
code, payload := api.GraphMesh(r.Context(), business, o)
respond(w, code, payload)
}