This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
instance.go
121 lines (102 loc) · 3.06 KB
/
instance.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
// Copyright (C) 2020, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
package instance
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/golang/glog"
clusterPkg "github.com/verrazzano/verrazzano-operator/pkg/api/clusters"
)
// Instance details of instance returned in API calls.
type Instance struct {
ID string `json:"id"`
Name string `json:"name"`
MgmtCluster string `json:"mgmtCluster"`
MgmtPlatform string `json:"mgmtPlatform"`
Status string `json:"status"`
Version string `json:"version"`
KeyCloakURL string `json:"keyCloakUrl"`
RancherURL string `json:"rancherUrl"`
VzAPIURL string `json:"vzApiUri"`
ElasticURL string `json:"elasticUrl"`
KibanaURL string `json:"kibanaUrl"`
GrafanaURL string `json:"grafanaUrl"`
PrometheusURL string `json:"prometheusUrl"`
}
// This is global for the operator
var verrazzanoURI string
// SetVerrazzanoURI set the verrazzanoURI variable
func SetVerrazzanoURI(s string) {
verrazzanoURI = s
}
// ReturnSingleInstance returns a single instance identified by the secret Kubernetes UID.
func ReturnSingleInstance(w http.ResponseWriter, r *http.Request) {
glog.V(4).Info("GET /instance")
clusters, err := clusterPkg.GetClusters()
if err != nil {
msg := fmt.Sprintf("Error getting clusters : %s", err.Error())
glog.Error(msg)
http.Error(w, msg, http.StatusInternalServerError)
return
}
var mgmtCluster clusterPkg.Cluster
for _, c := range clusters {
if c.Name == "local" {
mgmtCluster = c
break
}
}
instance := Instance{
ID: "0",
Name: GetVerrazzanoName(),
MgmtCluster: mgmtCluster.Name,
MgmtPlatform: mgmtCluster.Type,
Status: mgmtCluster.Status,
Version: getVersion(),
VzAPIURL: deriveURL("api"),
RancherURL: deriveURL("rancher"),
ElasticURL: GetElasticURL(),
KibanaURL: GetKibanaURL(),
GrafanaURL: GetGrafanaURL(),
PrometheusURL: GetPrometheusURL(),
KeyCloakURL: GetKeyCloakURL(),
}
json.NewEncoder(w).Encode(instance)
}
func getVersion() string {
return "0.1.0"
}
// Derive the URL from the verrazzano URI by replacing the 'api' segment
func deriveURL(s string) string {
return "https://" + s + "." + verrazzanoURI
}
// GetVerrazzanoName returns the environment name portion of the verrazzanoUri
func GetVerrazzanoName() string {
segs := strings.Split(verrazzanoURI, ".")
if len(segs) > 1 {
return segs[0]
}
return ""
}
// GetKeyCloakURL returns Keycloak URL
func GetKeyCloakURL() string {
return deriveURL("keycloak")
}
// GetKibanaURL returns Kibana URL
func GetKibanaURL() string {
return deriveURL("kibana.vmi.system")
}
// GetGrafanaURL returns Grafana URL
func GetGrafanaURL() string {
return deriveURL("grafana.vmi.system")
}
// GetPrometheusURL returns Prometheus URL
func GetPrometheusURL() string {
return deriveURL("prometheus.vmi.system")
}
// GetElasticURL returns Elasticsearch URL
func GetElasticURL() string {
return deriveURL("elasticsearch.vmi.system")
}