代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。