diff --git a/Documentation/ceph-cluster-crd.md b/Documentation/ceph-cluster-crd.md index 94dfbd24d..d00db80d5 100755 --- a/Documentation/ceph-cluster-crd.md +++ b/Documentation/ceph-cluster-crd.md @@ -187,6 +187,8 @@ If this value is empty, each pod will get an ephemeral directory to store their * `ssl`: Whether to serve the dashboard via SSL, ignored on Ceph versions older than `13.2.2` * `monitoring`: Settings for monitoring Ceph using Prometheus. To enable monitoring on your cluster see the [monitoring guide](ceph-monitoring.md#prometheus-alerts). * `enabled`: Whether to enable prometheus based monitoring for this cluster + * `externalMgrEndpoints`: external cluster manager endpoints + * `externalMgrPrometheusPort`: external prometheus manager module port. See [external cluster configuration](#external-cluster) for more details. * `rulesNamespace`: Namespace to deploy prometheusRule. If empty, namespace of the cluster will be used. Recommended: * If you have a single Rook Ceph cluster, set the `rulesNamespace` to the same namespace as the cluster or keep it empty. @@ -1238,6 +1240,7 @@ spec: #rulesNamespace: rook-ceph #externalMgrEndpoints: #- ip: 192.168.39.182 + #externalMgrPrometheusPort: 9283 ``` Choose the namespace carefully, if you have an existing cluster managed by Rook, you have likely already injected `common.yaml`. diff --git a/cluster/charts/rook-ceph/templates/resources.yaml b/cluster/charts/rook-ceph/templates/resources.yaml index 1903153c2..c37bd4094 100644 --- a/cluster/charts/rook-ceph/templates/resources.yaml +++ b/cluster/charts/rook-ceph/templates/resources.yaml @@ -282,6 +282,10 @@ spec: properties: ip: type: string + externalMgrPrometheusPort: + type: integer + minimum: 0 + maximum: 65535 removeOSDsIfOutAndSafeToRemove: type: boolean external: diff --git a/cluster/examples/kubernetes/ceph/cluster-external.yaml b/cluster/examples/kubernetes/ceph/cluster-external.yaml index 2db7c31f8..d1ea40f66 100644 --- a/cluster/examples/kubernetes/ceph/cluster-external.yaml +++ b/cluster/examples/kubernetes/ceph/cluster-external.yaml @@ -30,3 +30,4 @@ spec: # rulesNamespace: rook-ceph # externalMgrEndpoints: #- ip: ip + # externalMgrPrometheusPort: 9283 diff --git a/cluster/examples/kubernetes/ceph/crds.yaml b/cluster/examples/kubernetes/ceph/crds.yaml index 1b2c2a6e2..67a92465c 100644 --- a/cluster/examples/kubernetes/ceph/crds.yaml +++ b/cluster/examples/kubernetes/ceph/crds.yaml @@ -284,6 +284,10 @@ spec: properties: ip: type: string + externalMgrPrometheusPort: + type: integer + minimum: 0 + maximum: 65535 removeOSDsIfOutAndSafeToRemove: type: boolean external: diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index 17b5181d3..59002fa13 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -206,6 +206,9 @@ type MonitoringSpec struct { // ExternalMgrEndpoints points to an existing Ceph prometheus exporter endpoint ExternalMgrEndpoints []v1.EndpointAddress `json:"externalMgrEndpoints,omitempty"` + + // ExternalMgrPrometheusPort Prometheus exporter port + ExternalMgrPrometheusPort uint16 `json:"externalMgrPrometheusPort,omitempty"` } type ClusterStatus struct { diff --git a/pkg/operator/ceph/cluster/cluster_external.go b/pkg/operator/ceph/cluster/cluster_external.go index 0f561b147..bcc875941 100644 --- a/pkg/operator/ceph/cluster/cluster_external.go +++ b/pkg/operator/ceph/cluster/cluster_external.go @@ -183,11 +183,17 @@ func validateExternalClusterSpec(cluster *cluster) error { } } + // Validate external services port + if cluster.Spec.Monitoring.Enabled { + if cluster.Spec.Monitoring.ExternalMgrPrometheusPort == 0 { + cluster.Spec.Monitoring.ExternalMgrPrometheusPort = mgr.DefaultMetricsPort + } + } + return nil } func (c *ClusterController) configureExternalClusterMonitoring(cluster *cluster) error { - ctx := context.TODO() // Initialize manager object manager := mgr.New( c.context, @@ -199,18 +205,14 @@ func (c *ClusterController) configureExternalClusterMonitoring(cluster *cluster) // Create external monitoring Service service := manager.MakeMetricsService(mgr.ExternalMgrAppName, mgr.ServiceExternalMetricName) logger.Info("creating mgr external monitoring service") - _, err := c.context.Clientset.CoreV1().Services(c.namespacedName.Namespace).Create(ctx, service, metav1.CreateOptions{}) - if err != nil { - if !kerrors.IsAlreadyExists(err) { - return errors.Wrap(err, "failed to create mgr service") - } - logger.Debug("mgr external metrics service already exists") - } else { - logger.Info("mgr external metrics service created") + _, err := k8sutil.CreateOrUpdateService(c.context.Clientset, cluster.Namespace, service) + if err != nil && !kerrors.IsAlreadyExists(err) { + return errors.Wrap(err, "failed to create or update mgr service") } + logger.Info("mgr external metrics service created") // Create external monitoring Endpoints - endpoint := mgr.CreateExternalMetricsEndpoints(cluster.Namespace, cluster.Spec.Monitoring.ExternalMgrEndpoints, cluster.ownerRef) + endpoint := mgr.CreateExternalMetricsEndpoints(cluster.Namespace, cluster.Spec.Monitoring, cluster.ownerRef) logger.Info("creating mgr external monitoring endpoints") _, err = k8sutil.CreateOrUpdateEndpoint(c.context.Clientset, c.namespacedName.Namespace, endpoint) if err != nil { diff --git a/pkg/operator/ceph/cluster/cluster_external_test.go b/pkg/operator/ceph/cluster/cluster_external_test.go index 9b3be288a..8bc4039cb 100644 --- a/pkg/operator/ceph/cluster/cluster_external_test.go +++ b/pkg/operator/ceph/cluster/cluster_external_test.go @@ -36,4 +36,11 @@ func TestValidateExternalClusterSpec(t *testing.T) { c.Spec.DataDirHostPath = "path" err = validateExternalClusterSpec(c) assert.NoError(t, err, err) + assert.Equal(t, uint16(0), c.Spec.Monitoring.ExternalMgrPrometheusPort) + + c.Spec.Monitoring.Enabled = true + err = validateExternalClusterSpec(c) + assert.NoError(t, err, err) + assert.Equal(t, uint16(9283), c.Spec.Monitoring.ExternalMgrPrometheusPort) + } diff --git a/pkg/operator/ceph/cluster/mgr/mgr.go b/pkg/operator/ceph/cluster/mgr/mgr.go index 28e410944..605492fc1 100644 --- a/pkg/operator/ceph/cluster/mgr/mgr.go +++ b/pkg/operator/ceph/cluster/mgr/mgr.go @@ -53,16 +53,17 @@ const ( // AppName is the ceph mgr application name AppName = "rook-ceph-mgr" serviceAccountName = "rook-ceph-mgr" - prometheusModuleName = "prometheus" + PrometheusModuleName = "prometheus" crashModuleName = "crash" PgautoscalerModuleName = "pg_autoscaler" balancerModuleName = "balancer" balancerModuleMode = "upmap" - metricsPort = 9283 monitoringPath = "/etc/ceph-monitoring/" serviceMonitorFile = "service-monitor.yaml" // minimum amount of memory in MB to run the pod cephMgrPodMinimumMemory uint64 = 512 + // DefaultMetricsPort prometheus exporter port + DefaultMetricsPort uint16 = 9283 ) // Cluster represents the Rook and environment configuration settings needed to set up Ceph mgrs. @@ -231,7 +232,7 @@ func startModuleConfiguration(description string, configureModules func() error) // Ceph docs about the prometheus module: http://docs.ceph.com/docs/master/mgr/prometheus/ func (c *Cluster) enablePrometheusModule() error { - if err := client.MgrEnableModule(c.context, c.clusterInfo, prometheusModuleName, true); err != nil { + if err := client.MgrEnableModule(c.context, c.clusterInfo, PrometheusModuleName, true); err != nil { return errors.Wrap(err, "failed to enable mgr prometheus module") } return nil @@ -331,7 +332,7 @@ func (c *Cluster) moduleMeetsMinVersion(name string) (*cephver.CephVersion, bool } func wellKnownModule(name string) bool { - knownModules := []string{dashboardModuleName, prometheusModuleName, crashModuleName} + knownModules := []string{dashboardModuleName, PrometheusModuleName, crashModuleName} for _, known := range knownModules { if name == known { return true diff --git a/pkg/operator/ceph/cluster/mgr/spec.go b/pkg/operator/ceph/cluster/mgr/spec.go index c755b7d27..98a352ade 100644 --- a/pkg/operator/ceph/cluster/mgr/spec.go +++ b/pkg/operator/ceph/cluster/mgr/spec.go @@ -238,7 +238,7 @@ func (c *Cluster) makeMgrDaemonContainer(mgrConfig *mgrConfig) v1.Container { }, { Name: "http-metrics", - ContainerPort: int32(metricsPort), + ContainerPort: int32(DefaultMetricsPort), Protocol: v1.ProtocolTCP, }, { @@ -275,7 +275,7 @@ func getDefaultMgrLivenessProbe() *v1.Probe { Handler: v1.Handler{ HTTPGet: &v1.HTTPGetAction{ Path: "/", - Port: intstr.FromInt(metricsPort), + Port: intstr.FromInt(int(DefaultMetricsPort)), }, }, InitialDelaySeconds: 60, @@ -296,7 +296,7 @@ func (c *Cluster) MakeMetricsService(name, servicePortMetricName string) *v1.Ser Ports: []v1.ServicePort{ { Name: servicePortMetricName, - Port: int32(metricsPort), + Port: int32(DefaultMetricsPort), Protocol: v1.ProtocolTCP, }, }, @@ -351,7 +351,7 @@ func (c *Cluster) applyPrometheusAnnotations(objectMeta *metav1.ObjectMeta) { if len(cephv1.GetMgrAnnotations(c.spec.Annotations)) == 0 { t := rookv1.Annotations{ "prometheus.io/scrape": "true", - "prometheus.io/port": strconv.Itoa(metricsPort), + "prometheus.io/port": strconv.Itoa(int(DefaultMetricsPort)), } t.ApplyToObjectMeta(objectMeta) @@ -370,7 +370,7 @@ func (c *Cluster) cephMgrOrchestratorModuleEnvs() []v1.EnvVar { } // CreateExternalMetricsEndpoints creates external metric endpoint -func CreateExternalMetricsEndpoints(namespace string, externalMgrEndpoints []v1.EndpointAddress, ownerRef metav1.OwnerReference) *v1.Endpoints { +func CreateExternalMetricsEndpoints(namespace string, monitoringSpec cephv1.MonitoringSpec, ownerRef metav1.OwnerReference) *v1.Endpoints { labels := controller.AppLabels(AppName, namespace) endpoints := &v1.Endpoints{ @@ -381,11 +381,11 @@ func CreateExternalMetricsEndpoints(namespace string, externalMgrEndpoints []v1. }, Subsets: []v1.EndpointSubset{ { - Addresses: externalMgrEndpoints, + Addresses: monitoringSpec.ExternalMgrEndpoints, Ports: []v1.EndpointPort{ { Name: ServiceExternalMetricName, - Port: int32(metricsPort), + Port: int32(monitoringSpec.ExternalMgrPrometheusPort), Protocol: v1.ProtocolTCP, }, }, diff --git a/tests/framework/installer/ceph_manifests.go b/tests/framework/installer/ceph_manifests.go index f3ce40e44..f67c96762 100644 --- a/tests/framework/installer/ceph_manifests.go +++ b/tests/framework/installer/ceph_manifests.go @@ -377,6 +377,10 @@ spec: properties: ip: type: string + externalMgrPrometheusPort: + type: integer + minimum: 0 + maximum: 65535 removeOSDsIfOutAndSafeToRemove: type: boolean external: