From 41b69d549bdfdf0ea7e649149b57c5402344183b Mon Sep 17 00:00:00 2001 From: orangedeng Date: Thu, 29 Nov 2018 01:35:29 +0800 Subject: [PATCH] Enable monitoring --- apis/management.cattle.io/v3/authz_types.go | 3 ++ apis/management.cattle.io/v3/cluster_types.go | 22 ++++++++---- .../v3/monitoring_types.go | 35 +++++++++++++++++++ apis/management.cattle.io/v3/schema/schema.go | 15 ++++++-- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 apis/management.cattle.io/v3/monitoring_types.go diff --git a/apis/management.cattle.io/v3/authz_types.go b/apis/management.cattle.io/v3/authz_types.go index 91169412..838f63fa 100644 --- a/apis/management.cattle.io/v3/authz_types.go +++ b/apis/management.cattle.io/v3/authz_types.go @@ -14,6 +14,7 @@ var ( CreatorMadeOwner condition.Cond = "CreatorMadeOwner" DefaultNetworkPolicyCreated condition.Cond = "DefaultNetworkPolicyCreated" ProjectConditionInitialRolesPopulated condition.Cond = "InitialRolesPopulated" + ProjectConditionMonitoringEnabled condition.Cond = "MonitoringEnabled" ) type Project struct { @@ -29,6 +30,7 @@ type Project struct { type ProjectStatus struct { Conditions []ProjectCondition `json:"conditions"` PodSecurityPolicyTemplateName string `json:"podSecurityPolicyTemplateId"` + MonitoringStatus *MonitoringStatus `json:"monitoringStatus,omitempty" norman:"nocreate,noupdate"` } type ProjectCondition struct { @@ -52,6 +54,7 @@ type ProjectSpec struct { ClusterName string `json:"clusterName,omitempty" norman:"required,type=reference[cluster]"` ResourceQuota *ProjectResourceQuota `json:"resourceQuota,omitempty"` NamespaceDefaultResourceQuota *NamespaceResourceQuota `json:"namespaceDefaultResourceQuota,omitempty"` + EnableProjectMonitoring bool `json:"enableProjectMonitoring" norman:"default=false"` } type GlobalRole struct { diff --git a/apis/management.cattle.io/v3/cluster_types.go b/apis/management.cattle.io/v3/cluster_types.go index ad083126..f1c69fe1 100644 --- a/apis/management.cattle.io/v3/cluster_types.go +++ b/apis/management.cattle.io/v3/cluster_types.go @@ -41,13 +41,15 @@ const ( ClusterConditionDefaultNamespaceAssigned condition.Cond = "DefaultNamespaceAssigned" // ClusterConditionSystemNamespacesAssigned true when cluster's system namespaces has been initially assigned to // a system project - ClusterConditionSystemNamespacesAssigned condition.Cond = "SystemNamespacesAssigned" - ClusterConditionAddonDeploy condition.Cond = "AddonDeploy" - ClusterConditionSystemAccountCreated condition.Cond = "SystemAccountCreated" - ClusterConditionAgentDeployed condition.Cond = "AgentDeployed" - ClusterConditionGlobalAdminsSynced condition.Cond = "GlobalAdminsSynced" - ClusterConditionInitialRolesPopulated condition.Cond = "InitialRolesPopulated" - ClusterConditionAlertingEnabled condition.Cond = "AlertingEnabled" + ClusterConditionSystemNamespacesAssigned condition.Cond = "SystemNamespacesAssigned" + ClusterConditionAddonDeploy condition.Cond = "AddonDeploy" + ClusterConditionSystemAccountCreated condition.Cond = "SystemAccountCreated" + ClusterConditionAgentDeployed condition.Cond = "AgentDeployed" + ClusterConditionGlobalAdminsSynced condition.Cond = "GlobalAdminsSynced" + ClusterConditionInitialRolesPopulated condition.Cond = "InitialRolesPopulated" + ClusterConditionPrometheusOperatorDeployed condition.Cond = "PrometheusOperatorDeployed" + ClusterConditionMonitoringEnabled condition.Cond = "MonitoringEnabled" + ClusterConditionAlertingEnabled condition.Cond = "AlertingEnabled" ClusterDriverImported = "imported" ClusterDriverLocal = "local" @@ -86,6 +88,7 @@ type ClusterSpec struct { DockerRootDir string `json:"dockerRootDir,omitempty" norman:"default=/var/lib/docker"` EnableNetworkPolicy *bool `json:"enableNetworkPolicy" norman:"default=false"` EnableClusterAlerting bool `json:"enableClusterAlerting" norman:"default=false"` + EnableClusterMonitoring bool `json:"enableClusterMonitoring" norman:"default=false"` } type ImportedConfig struct { @@ -114,6 +117,7 @@ type ClusterStatus struct { AppliedPodSecurityPolicyTemplateName string `json:"appliedPodSecurityPolicyTemplateId"` AppliedEnableNetworkPolicy bool `json:"appliedEnableNetworkPolicy" norman:"nocreate,noupdate,default=false"` Capabilities Capabilities `json:"capabilities,omitempty"` + MonitoringStatus *MonitoringStatus `json:"monitoringStatus,omitempty" norman:"nocreate,noupdate"` } type ClusterComponentStatus struct { @@ -223,3 +227,7 @@ type IngressCapabilities struct { IngressProvider string `json:"ingressProvider,omitempty"` CustomDefaultBackend bool `json:"customDefaultBackend,omitempty"` } + +type MonitoringInput struct { + Answers map[string]string `json:"answers,omitempty"` +} diff --git a/apis/management.cattle.io/v3/monitoring_types.go b/apis/management.cattle.io/v3/monitoring_types.go new file mode 100644 index 00000000..39563a02 --- /dev/null +++ b/apis/management.cattle.io/v3/monitoring_types.go @@ -0,0 +1,35 @@ +package v3 + +import ( + "github.com/rancher/norman/condition" + "k8s.io/api/core/v1" +) + +type MonitoringStatus struct { + GrafanaEndpoint string `json:"grafanaEndpoint,omitempty"` + Conditions []MonitoringCondition `json:"conditions,omitempty"` +} + +type MonitoringCondition struct { + // Type of cluster condition. + Type ClusterConditionType `json:"type"` + // Status of the condition, one of True, False, Unknown. + Status v1.ConditionStatus `json:"status"` + // The last time this condition was updated. + LastUpdateTime string `json:"lastUpdateTime,omitempty"` + // Last time the condition transitioned from one status to another. + LastTransitionTime string `json:"lastTransitionTime,omitempty"` + // The reason for the condition's last transition. + Reason string `json:"reason,omitempty"` + // Human-readable message indicating details about last transition + Message string `json:"message,omitempty"` +} + +const ( + MonitoringConditionGrafanaDeployed condition.Cond = "GrafanaDeployed" + MonitoringConditionPrometheusDeployed condition.Cond = "PrometheusDeployed" + MonitoringConditionAlertmaanagerDeployed condition.Cond = "AlertmanagerDeployed" + MonitoringConditionNodeExporterDeployed condition.Cond = "NodeExporterDeployed" + MonitoringConditionKubeStateExporterDeployed condition.Cond = "KubeStateExporterDeployed" + MonitoringConditionMetricExpressionDeployed condition.Cond = "MetricExpressionDeployed" +) diff --git a/apis/management.cattle.io/v3/schema/schema.go b/apis/management.cattle.io/v3/schema/schema.go index 294e46c7..bbe1e380 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -145,6 +145,7 @@ func clusterTypes(schemas *types.Schemas) *types.Schemas { MustImport(&Version, v3.ImportClusterYamlInput{}). MustImport(&Version, v3.ImportYamlOutput{}). MustImport(&Version, v3.ExportOutput{}). + MustImport(&Version, v3.MonitoringInput{}). MustImportAndCustomize(&Version, v3.ETCDService{}, func(schema *types.Schema) { schema.MustCustomizeField("extraArgs", func(field types.Field) types.Field { field.Default = map[string]interface{}{ @@ -170,14 +171,20 @@ func clusterTypes(schemas *types.Schemas) *types.Schemas { schema.ResourceActions["exportYaml"] = types.Action{ Output: "exportOutput", } + schema.ResourceActions["enableMonitoring"] = types.Action{ + Input: "monitoringInput", + } + schema.ResourceActions["disableMonitoring"] = types.Action{} }) } func authzTypes(schemas *types.Schemas) *types.Schemas { return schemas. MustImport(&Version, v3.ProjectStatus{}). - AddMapperForType(&Version, v3.Project{}, m.DisplayName{}, - &m.Embed{Field: "status"}). + AddMapperForType(&Version, v3.Project{}, + m.DisplayName{}, + &m.Embed{Field: "status"}, + ). AddMapperForType(&Version, v3.GlobalRole{}, m.DisplayName{}). AddMapperForType(&Version, v3.RoleTemplate{}, m.DisplayName{}). AddMapperForType(&Version, @@ -195,6 +202,10 @@ func authzTypes(schemas *types.Schemas) *types.Schemas { Output: "project", }, "exportYaml": {}, + "enableMonitoring": { + Input: "monitoringInput", + }, + "disableMonitoring": {}, } }). MustImportAndCustomize(&Version, v3.GlobalRole{}, func(schema *types.Schema) {