-
Notifications
You must be signed in to change notification settings - Fork 474
/
versions.go
311 lines (264 loc) · 11 KB
/
versions.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
package status
import (
"encoding/json"
"fmt"
"regexp"
"strings"
"time"
kversion "k8s.io/apimachinery/pkg/version"
kube "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"github.com/kiali/kiali/config"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/log"
"github.com/kiali/kiali/util/httputil"
)
type externalService func() (*ExternalServiceInfo, error)
var (
// Example Maistra product version is:
// redhat@redhat-docker.io/maistra-0.1.0-1-3a136c90ec5e308f236e0d7ebb5c4c5e405217f4-unknown
// Example Maistra upstream project version is:
// redhat@redhat-pulp.abc.xyz.redhat.com:8888/openshift-istio-tech-preview-0.1.0-1-3a136c90ec5e308f236e0d7ebb5c4c5e405217f4-Custom
// Maistra_1.1.0-291c5419cf19d2b015e7e5dee970c458fb8f1982-Clean
// Example OpenShift Service Mesh 1.1 product version is:
// OSSM_1.1.0-291c5419cf19d2b015e7e5dee970c458fb8f1982-Clean
// Example Istio snapshot version is:
// root@f72e3d3ef3c2-docker.io/istio-release-1.0-20180927-21-10-cbe9c05c470ec1924f7bcf02334b183e7e6175cb-Clean
// Example Istio alpha RC version is:
// 1.7.0-alpha.1-cd46a166947eac363380c3aa3523b26a8c391f98-dirty-Modified
// Example Istio dev version is:
// 1.5-alpha.dbd2aca8887fb42c2bb358417621a78de372f906-dbd2aca8887fb42c2bb358417621a78de372f906-Clean
// 1.10-dev-65a124dc2ab69f91331298fbf6d9b4335abcf0fd-Clean
maistraProductVersionExpr = regexp.MustCompile(`maistra-([0-9]+\.[0-9]+\.[0-9]+)`)
ossmVersionExpr = regexp.MustCompile(`(?:OSSM_|openshift-service-mesh-)([0-9]+\.[0-9]+\.[0-9]+)`)
maistraProjectVersionExpr = regexp.MustCompile(`(?:Maistra_|openshift-istio.*-)([0-9]+\.[0-9]+\.[0-9]+)`)
istioDevVersionExpr = regexp.MustCompile(`(\d+\.\d+)-alpha\.([[:alnum:]]+)-.*|(\d+\.\d+)-dev-([[:alnum:]]+)-.*`)
istioRCVersionExpr = regexp.MustCompile(`(\d+\.\d+.\d+)-((?:alpha|beta|rc|RC)\.\d+)`)
istioSnapshotVersionExpr = regexp.MustCompile(`istio-release-([0-9]+\.[0-9]+)(-[0-9]{8})`)
istioVersionExpr = regexp.MustCompile(`([0-9]+\.[0-9]+\.[0-9]+)`)
)
const (
istioProductNameMaistra = "Maistra"
istioProductNameMaistraProject = "Maistra Project"
istioProductNameOSSM = "OpenShift Service Mesh"
istioProductNameUpstream = "Istio"
istioProductNameUpstreamSnapshot = "Istio Snapshot"
istioProductNameUpstreamRC = "Istio RC"
istioProductNameUpstreamDev = "Istio Dev"
istioProductNameUnknown = "Unknown Istio Implementation"
)
func getVersions() {
components := []externalService{
istioVersion,
prometheusVersion,
kubernetesVersion,
}
if config.Get().ExternalServices.Grafana.Enabled {
components = append(components, grafanaVersion)
} else {
log.Debugf("Grafana is disabled in Kiali by configuration")
}
if config.Get().ExternalServices.Tracing.Enabled {
components = append(components, jaegerVersion)
} else {
log.Debugf("Jaeger is disabled in Kiali by configuration")
}
for _, comp := range components {
getVersionComponent(comp)
}
}
func getVersionComponent(serviceComponent externalService) {
componentInfo, err := serviceComponent()
if err == nil {
info.ExternalServices = append(info.ExternalServices, *componentInfo)
}
}
// istioVersion returns the current istio version information
func istioVersion() (*ExternalServiceInfo, error) {
istioConfig := config.Get().ExternalServices.Istio
body, code, _, err := httputil.HttpGet(istioConfig.UrlServiceVersion, nil, 10*time.Second, nil, nil)
configWarnings := "failed to get mesh version, please check if url_service_version is configured correctly."
if err != nil {
AddWarningMessages(configWarnings)
return nil, fmt.Errorf(configWarnings)
}
if code >= 400 {
return nil, fmt.Errorf("getting istio version returned error code [%d]", code)
}
rawVersion := string(body)
istioInfo := parseIstioRawVersion(rawVersion)
meshName, meshVersion := istioInfo.Name, istioInfo.Version
Put(MeshVersion, meshVersion)
Put(MeshName, meshName)
return istioInfo, nil
}
func parseIstioRawVersion(rawVersion string) *ExternalServiceInfo {
product := ExternalServiceInfo{Name: "Unknown", Version: "Unknown"}
// First see if we detect Maistra (either product or upstream project).
// If it is not Maistra, see if it is upstream Istio (either a release or snapshot).
// If it is neither then it is some unknown Istio implementation that we do not support.
maistraVersionStringArr := maistraProductVersionExpr.FindStringSubmatch(rawVersion)
if maistraVersionStringArr != nil {
log.Debugf("Detected Maistra product version [%v]", rawVersion)
if len(maistraVersionStringArr) > 1 {
product.Name = istioProductNameMaistra
product.Version = maistraVersionStringArr[1] // get regex group #1 ,which is the "#.#.#" version string
// we know this is Maistra - either a supported or unsupported version - return now
return &product
}
}
maistraVersionStringArr = maistraProjectVersionExpr.FindStringSubmatch(rawVersion)
if maistraVersionStringArr != nil {
log.Debugf("Detected Maistra project version [%v]", rawVersion)
if len(maistraVersionStringArr) > 1 {
product.Name = istioProductNameMaistraProject
product.Version = maistraVersionStringArr[1] // get regex group #1 ,which is the "#.#.#" version string
// we know this is Maistra - either a supported or unsupported version - return now
return &product
}
}
// OpenShift Service Mesh
ossmStringArr := ossmVersionExpr.FindStringSubmatch(rawVersion)
if ossmStringArr != nil {
log.Debugf("Detected OpenShift Service Mesh version [%v]", rawVersion)
if len(ossmStringArr) > 1 {
product.Name = istioProductNameOSSM
product.Version = ossmStringArr[1] // get regex group #1 ,which is the "#.#.#" version string
// we know this is OpenShift Service Mesh - either a supported or unsupported version - return now
return &product
}
}
// see if it is a snapshot version of Istio
istioVersionStringArr := istioSnapshotVersionExpr.FindStringSubmatch(rawVersion)
if istioVersionStringArr != nil {
log.Debugf("Detected Istio snapshot version [%v]", rawVersion)
if len(istioVersionStringArr) > 2 {
product.Name = istioProductNameUpstreamSnapshot
majorMinor := istioVersionStringArr[1] // regex group #1 is the "#.#" version numbers
snapshotStr := istioVersionStringArr[2] // regex group #2 is the date/time stamp
product.Version = majorMinor + snapshotStr
// we know this is Istio upstream - either a supported or unsupported version - return now
return &product
}
}
// see if it is an RC version of Istio
istioVersionStringArr = istioRCVersionExpr.FindStringSubmatch(rawVersion)
if istioVersionStringArr != nil {
log.Debugf("Detected Istio RC version [%v]", rawVersion)
if len(istioVersionStringArr) > 2 {
product.Name = istioProductNameUpstreamRC
majorMinor := istioVersionStringArr[1] // regex group #1 is the "#.#.#" version numbers
rc := istioVersionStringArr[2] // regex group #2 is the alpha or beta version
product.Version = fmt.Sprintf("%s (%s)", majorMinor, rc)
// we know this is Istio upstream - either a supported or unsupported version - return now
return &product
}
}
// see if it is a dev version of Istio
istioVersionStringArr = istioDevVersionExpr.FindStringSubmatch(rawVersion)
if istioVersionStringArr != nil {
log.Debugf("Detected Istio dev version [%v]", rawVersion)
if strings.Contains(istioVersionStringArr[0], "alpha") && len(istioVersionStringArr) > 2 {
product.Name = istioProductNameUpstreamDev
majorMinor := istioVersionStringArr[1] // regex group #1 is the "#.#" version numbers
buildHash := istioVersionStringArr[2] // regex group #2 is the build hash
product.Version = fmt.Sprintf("%s (dev %s)", majorMinor, buildHash)
// we know this is Istio upstream - either a supported or unsupported version - return now
return &product
} else if strings.Contains(istioVersionStringArr[0], "dev") && len(istioVersionStringArr) > 4 {
product.Name = istioProductNameUpstreamDev
majorMinor := istioVersionStringArr[3] // regex group #3 is the "#.#" version numbers
buildHash := istioVersionStringArr[4] // regex group #4 is the build hash
product.Version = fmt.Sprintf("%s (dev %s)", majorMinor, buildHash)
// we know this is Istio upstream - either a supported or unsupported version - return now
return &product
}
}
// see if it is a released version of Istio
istioVersionStringArr = istioVersionExpr.FindStringSubmatch(rawVersion)
if istioVersionStringArr != nil {
log.Debugf("Detected Istio version [%v]", rawVersion)
if len(istioVersionStringArr) > 1 {
product.Name = istioProductNameUpstream
product.Version = istioVersionStringArr[1] // get regex group #1 ,which is the "#.#.#" version string
// we know this is Istio upstream - either a supported or unsupported version - return now
return &product
}
}
log.Debugf("Detected unknown Istio implementation version [%v]", rawVersion)
product.Name = istioProductNameUnknown
product.Version = rawVersion
return &product
}
type p8sResponseVersion struct {
Version string `json:"version"`
Revision string `json:"revision"`
}
func jaegerVersion() (*ExternalServiceInfo, error) {
jaegerConfig := config.Get().ExternalServices.Tracing
if !jaegerConfig.Enabled {
return nil, nil
}
product := ExternalServiceInfo{}
product.Name = "Jaeger"
product.Url = jaegerConfig.URL
return &product, nil
}
func grafanaVersion() (*ExternalServiceInfo, error) {
product := ExternalServiceInfo{}
product.Name = "Grafana"
product.Url = DiscoverGrafana()
return &product, nil
}
func prometheusVersion() (*ExternalServiceInfo, error) {
product := ExternalServiceInfo{}
prometheusV := new(p8sResponseVersion)
cfg := config.Get().ExternalServices.Prometheus
// Be sure to copy config.Auth and not modify the existing
auth := cfg.Auth
if auth.UseKialiToken {
token, err := kubernetes.GetKialiTokenForHomeCluster()
if err != nil {
log.Errorf("Could not read the Kiali Service Account token: %v", err)
return nil, err
}
auth.Token = token
}
body, _, _, err := httputil.HttpGet(cfg.URL+"/version", &auth, 10*time.Second, nil, nil)
if err == nil {
err = json.Unmarshal(body, &prometheusV)
if err == nil {
product.Name = "Prometheus"
product.Version = prometheusV.Version
return &product, nil
}
}
return nil, err
}
func kubernetesVersion() (*ExternalServiceInfo, error) {
var (
err error
k8sConfig *rest.Config
k8s *kube.Clientset
serverVersion *kversion.Info
)
product := ExternalServiceInfo{}
k8sConfig, err = kubernetes.GetConfigForLocalCluster()
if err == nil {
k8sConfig.QPS = config.Get().KubernetesConfig.QPS
k8sConfig.Burst = config.Get().KubernetesConfig.Burst
k8s, err = kube.NewForConfig(k8sConfig)
if err == nil {
serverVersion, err = k8s.Discovery().ServerVersion()
if err == nil {
product.Name = "Kubernetes"
product.Version = serverVersion.GitVersion
return &product, nil
}
}
}
return nil, err
}
func isMaistraExternalService(esi *ExternalServiceInfo) bool {
return esi.Name == istioProductNameOSSM || esi.Name == istioProductNameMaistra || esi.Name == istioProductNameMaistraProject
}