forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handleComponents.go
99 lines (76 loc) · 3.63 KB
/
handleComponents.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
package monitoring
import (
"fmt"
"github.com/pkg/errors"
appsv1beta2 "github.com/rancher/types/apis/apps/v1beta2"
mgmtv3 "github.com/rancher/types/apis/management.cattle.io/v3"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var (
ConditionGrafanaDeployed = condition(mgmtv3.MonitoringConditionGrafanaDeployed)
ConditionPrometheusDeployed = condition(mgmtv3.MonitoringConditionPrometheusDeployed)
ConditionMetricExpressionDeployed = condition(mgmtv3.MonitoringConditionMetricExpressionDeployed)
)
// All component names base on rancher-monitoring chart
func isGrafanaDeployed(agentDeploymentClient appsv1beta2.DeploymentInterface, appNamespace, appNameSuffix string, monitoringStatus *mgmtv3.MonitoringStatus, clusterName string) error {
_, err := ConditionGrafanaDeployed.DoUntilTrue(monitoringStatus, func() (*mgmtv3.MonitoringStatus, error) {
obj, err := agentDeploymentClient.GetNamespaced(appNamespace, "grafana-"+appNameSuffix, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return nil, errors.New("Grafana Deployment isn't deployed")
}
return nil, errors.Wrap(err, "failed to get Grafana Deployment information")
}
status := obj.Status
if status.Replicas != status.ReadyReplicas {
return nil, errors.New("Grafana Deployment is deploying")
}
monitoringStatus.GrafanaEndpoint = fmt.Sprintf("/k8s/clusters/%s/api/v1/namespaces/%s/services/http:access-grafana:80/proxy/", clusterName, appNamespace)
return monitoringStatus, nil
})
return err
}
func isGrafanaWithdrew(agentDeploymentClient appsv1beta2.DeploymentInterface, appNamespace, appNameSuffix string, monitoringStatus *mgmtv3.MonitoringStatus) error {
_, err := ConditionGrafanaDeployed.DoUntilFalse(monitoringStatus, func() (*mgmtv3.MonitoringStatus, error) {
_, err := agentDeploymentClient.GetNamespaced(appNamespace, "grafana-"+appNameSuffix, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
monitoringStatus.GrafanaEndpoint = ""
return monitoringStatus, nil
}
return nil, errors.Wrap(err, "failed to get Grafana Deployment information")
}
return nil, errors.New("Grafana Deployment is withdrawing")
})
return err
}
func isPrometheusDeployed(agentStatefulSetClient appsv1beta2.StatefulSetInterface, appNamespace, appNameSuffix string, monitoringStatus *mgmtv3.MonitoringStatus) error {
_, err := ConditionPrometheusDeployed.DoUntilTrue(monitoringStatus, func() (*mgmtv3.MonitoringStatus, error) {
obj, err := agentStatefulSetClient.GetNamespaced(appNamespace, "prometheus-"+appNameSuffix, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return nil, errors.New("Prometheus StatefulSet isn't deployed")
}
return nil, errors.Wrap(err, "failed to get Prometheus StatefulSet information")
}
if obj.Status.Replicas != obj.Status.ReadyReplicas {
return nil, errors.New("Prometheus StatefulSet is deploying")
}
return monitoringStatus, nil
})
return err
}
func isPrometheusWithdrew(agentStatefulSetClient appsv1beta2.StatefulSetInterface, appNamespace, appNameSuffix string, monitoringStatus *mgmtv3.MonitoringStatus) error {
_, err := ConditionPrometheusDeployed.DoUntilFalse(monitoringStatus, func() (*mgmtv3.MonitoringStatus, error) {
_, err := agentStatefulSetClient.GetNamespaced(appNamespace, "prometheus-"+appNameSuffix, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return monitoringStatus, nil
}
return nil, errors.Wrap(err, "failed to get Prometheus StatefulSet information")
}
return nil, errors.New("Prometheus StatefulSet is withdrawing")
})
return err
}