Merge pull request #11317 from avanthakkar/introduce-ceph-exporter
core: introduce ceph-exporter
This commit is contained in:
30 files changed
+623
-86
No files matched your search
@@ -34,7 +34,13 @@ Once the Prometheus operator is in the `Running` state, proceed to the next sect
|
||||
|
||||
## Prometheus Instances
|
||||
|
||||
With the Prometheus operator running, we can create a service monitor that will watch the Rook cluster and collect metrics regularly.
|
||||
With the Prometheus operator running, we can create service monitors that will watch the Rook cluster.
|
||||
|
||||
There are two sources for metrics collection:
|
||||
|
||||
- Prometheus manager module: It is responsible for exposing all metrics other than ceph daemons performance counters.
|
||||
- Ceph exporter: It is responsible for exposing only ceph daemons performance counters as prometheus metrics.
|
||||
|
||||
From the root of your locally cloned Rook repo, go the monitoring directory:
|
||||
|
||||
```console
|
||||
@@ -46,6 +52,7 @@ Create the service monitor as well as the Prometheus server pod and service:
|
||||
|
||||
```console
|
||||
kubectl create -f service-monitor.yaml
|
||||
kubectl create -f exporter-service-monitor.yaml
|
||||
kubectl create -f prometheus.yaml
|
||||
kubectl create -f prometheus-service.yaml
|
||||
```
|
||||
@@ -194,9 +201,9 @@ The dashboards have been created by [@galexrt](https://github.com/galexrt). For
|
||||
|
||||
The following Grafana dashboards are available:
|
||||
|
||||
* [Ceph - Cluster](https://grafana.com/grafana/dashboards/2842)
|
||||
* [Ceph - OSD (Single)](https://grafana.com/grafana/dashboards/5336)
|
||||
* [Ceph - Pools](https://grafana.com/grafana/dashboards/5342)
|
||||
- [Ceph - Cluster](https://grafana.com/grafana/dashboards/2842)
|
||||
- [Ceph - OSD (Single)](https://grafana.com/grafana/dashboards/5336)
|
||||
- [Ceph - Pools](https://grafana.com/grafana/dashboards/5342)
|
||||
|
||||
## Updates and Upgrades
|
||||
|
||||
|
||||
@@ -14,3 +14,4 @@
|
||||
- Change `pspEnable` default value to `false` in helm charts, and remove documentation for enabling PSP since the min supported K8s version is 1.21 where PSPs were deprecated.
|
||||
- [Bucket notifications and topics](https://rook.io/docs/rook/latest/Storage-Configuration/Object-Storage-RGW/ceph-object-bucket-notifications/)
|
||||
for object stores moved to stable from experimental.
|
||||
- Introduce [Ceph exporter](https://github.com/rook/rook/blob/master/design/ceph/ceph-exporter.md) as the new source of metrics based on performance counters coming from every Ceph daemon.
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
metadata:
|
||||
name: rook-ceph-exporter
|
||||
namespace: rook-ceph
|
||||
labels:
|
||||
team: rook
|
||||
spec:
|
||||
namespaceSelector:
|
||||
matchNames:
|
||||
- rook-ceph
|
||||
selector:
|
||||
matchLabels:
|
||||
app: rook-ceph-exporter
|
||||
rook_cluster: rook-ceph
|
||||
ceph_daemon_id: exporter
|
||||
endpoints:
|
||||
- port: ceph-exporter-http-metrics
|
||||
path: /metrics
|
||||
interval: 5s
|
||||
@@ -57,6 +57,11 @@ func GetCleanupAnnotations(a AnnotationsSpec) Annotations {
|
||||
return mergeAllAnnotationsWithKey(a, KeyCleanup)
|
||||
}
|
||||
|
||||
// GetCephExporterAnnotations returns the Annotations for the MGR service
|
||||
func GetCephExporterAnnotations(a AnnotationsSpec) Annotations {
|
||||
return mergeAllAnnotationsWithKey(a, KeyCephExporter)
|
||||
}
|
||||
|
||||
func GetClusterMetadataAnnotations(a AnnotationsSpec) Annotations {
|
||||
return a[KeyClusterMetadata]
|
||||
}
|
||||
|
||||
@@ -29,4 +29,5 @@ const (
|
||||
KeyMonitoring KeyType = "monitoring"
|
||||
KeyCrashCollector KeyType = "crashcollector"
|
||||
KeyClusterMetadata KeyType = "clusterMetadata"
|
||||
KeyCephExporter KeyType = "exporter"
|
||||
)
|
||||
@@ -73,6 +73,10 @@ func GetCrashCollectorLabels(a LabelsSpec) Labels {
|
||||
return mergeAllLabelsWithKey(a, KeyCrashCollector)
|
||||
}
|
||||
|
||||
func GetCephExporterLabels(a LabelsSpec) Labels {
|
||||
return mergeAllLabelsWithKey(a, KeyCephExporter)
|
||||
}
|
||||
|
||||
func mergeAllLabelsWithKey(a LabelsSpec, name KeyType) Labels {
|
||||
all := a.All()
|
||||
if all != nil {
|
||||
|
||||
@@ -63,3 +63,11 @@ func GetCrashCollectorPriorityClassName(p PriorityClassNamesSpec) string {
|
||||
}
|
||||
return p[KeyCrashCollector]
|
||||
}
|
||||
|
||||
// GetCephExporterPriorityClassName returns the priority class name for the ceph-exporter
|
||||
func GetCephExporterPriorityClassName(p PriorityClassNamesSpec) string {
|
||||
if _, ok := p[KeyCephExporter]; !ok {
|
||||
return p.All()
|
||||
}
|
||||
return p[KeyCephExporter]
|
||||
}
|
||||
@@ -43,6 +43,8 @@ const (
|
||||
ResourcesKeyFilesystemMirror = "fsmirror"
|
||||
// ResourcesKeyCleanup represents the name of resource in the CR for the cleanup
|
||||
ResourcesKeyCleanup = "cleanup"
|
||||
// ResourcesKeyCleanup represents the name of resource in the CR for ceph-exporter
|
||||
ResourcesKeyCephExporter = "exporter"
|
||||
)
|
||||
|
||||
// GetMgrResources returns the placement for the MGR service
|
||||
@@ -97,3 +99,8 @@ func GetLogCollectorResources(p ResourceSpec) v1.ResourceRequirements {
|
||||
func GetCleanupResources(p ResourceSpec) v1.ResourceRequirements {
|
||||
return p[ResourcesKeyCleanup]
|
||||
}
|
||||
|
||||
// GetCleanupResources returns the placement for the cleanup job
|
||||
func GetCephExporterResources(p ResourceSpec) v1.ResourceRequirements {
|
||||
return p[ResourcesKeyCephExporter]
|
||||
}
|
||||
@@ -43,7 +43,7 @@ const (
|
||||
func (c *Cluster) makeDeployment(mgrConfig *mgrConfig) (*apps.Deployment, error) {
|
||||
logger.Debugf("mgrConfig: %+v", mgrConfig)
|
||||
|
||||
volumes := controller.DaemonVolumes(mgrConfig.DataPathMap, mgrConfig.ResourceName)
|
||||
volumes := controller.DaemonVolumes(mgrConfig.DataPathMap, mgrConfig.ResourceName, c.spec.DataDirHostPath)
|
||||
if c.spec.Network.IsMultus() {
|
||||
adminKeyringVol, _ := keyring.Volume().Admin(), keyring.VolumeMount().Admin()
|
||||
volumes = append(volumes, adminKeyringVol)
|
||||
@@ -141,9 +141,10 @@ func (c *Cluster) makeChownInitContainer(mgrConfig *mgrConfig) v1.Container {
|
||||
*mgrConfig.DataPathMap,
|
||||
c.spec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(mgrConfig.DataPathMap, mgrConfig.ResourceName),
|
||||
controller.DaemonVolumeMounts(mgrConfig.DataPathMap, mgrConfig.ResourceName, c.spec.DataDirHostPath),
|
||||
cephv1.GetMgrResources(c.spec.Resources),
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ func (c *Cluster) makeMgrDaemonContainer(mgrConfig *mgrConfig) v1.Container {
|
||||
),
|
||||
Image: c.spec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(mgrConfig.DataPathMap, mgrConfig.ResourceName),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(mgrConfig.DataPathMap, mgrConfig.ResourceName, c.spec.DataDirHostPath),
|
||||
Ports: []v1.ContainerPort{
|
||||
{
|
||||
Name: "mgr",
|
||||
@@ -245,7 +246,7 @@ func (c *Cluster) makeCmdProxySidecarContainer(mgrConfig *mgrConfig) v1.Containe
|
||||
Args: []string{"infinity"},
|
||||
Image: c.spec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: append(controller.DaemonVolumeMounts(mgrConfig.DataPathMap, mgrConfig.ResourceName), adminKeyringVolMount),
|
||||
VolumeMounts: append(controller.DaemonVolumeMounts(mgrConfig.DataPathMap, mgrConfig.ResourceName, c.spec.DataDirHostPath), adminKeyringVolMount),
|
||||
Env: append(controller.DaemonEnvVars(c.spec.CephVersion.Image), v1.EnvVar{Name: "CEPH_ARGS", Value: fmt.Sprintf("-m $(ROOK_CEPH_MON_HOST) -k %s", keyring.VolumeMount().AdminKeyringFilePath())}),
|
||||
Resources: cephv1.GetMgrResources(c.spec.Resources),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestPodSpec(t *testing.T) {
|
||||
"my-priority-class", "test", "cephclusters.ceph.rook.io", "ceph-mgr")
|
||||
assert.Equal(t, 2, len(d.Spec.Template.Annotations))
|
||||
assert.Equal(t, 1, len(d.Spec.Template.Spec.Containers))
|
||||
assert.Equal(t, 5, len(d.Spec.Template.Spec.Containers[0].VolumeMounts))
|
||||
assert.Equal(t, 6, len(d.Spec.Template.Spec.Containers[0].VolumeMounts))
|
||||
})
|
||||
|
||||
t.Run("deployment with multus with new sidecar proxy command container", func(t *testing.T) {
|
||||
@@ -88,7 +88,7 @@ func TestPodSpec(t *testing.T) {
|
||||
assert.Equal(t, 3, len(d.Spec.Template.Annotations)) // Multus annotations
|
||||
assert.Equal(t, 2, len(d.Spec.Template.Spec.Containers)) // mgr pod + sidecar
|
||||
assert.Equal(t, cephclient.CommandProxyInitContainerName, d.Spec.Template.Spec.Containers[1].Name) // sidecar pod
|
||||
assert.Equal(t, 6, len(d.Spec.Template.Spec.Containers[1].VolumeMounts)) // + admin keyring
|
||||
assert.Equal(t, 7, len(d.Spec.Template.Spec.Containers[1].VolumeMounts)) // + admin keyring
|
||||
assert.Equal(t, "CEPH_ARGS", d.Spec.Template.Spec.Containers[1].Env[len(d.Spec.Template.Spec.Containers[1].Env)-1].Name) // connection info to the cluster
|
||||
assert.Equal(t, "-m $(ROOK_CEPH_MON_HOST) -k /etc/ceph/admin-keyring-store/keyring", d.Spec.Template.Spec.Containers[1].Env[len(d.Spec.Template.Spec.Containers[1].Env)-1].Value) // connection info to the cluster
|
||||
})
|
||||
|
||||
@@ -181,7 +181,7 @@ func (c *Cluster) makeMonPod(monConfig *monConfig, canary bool) (*corev1.Pod, er
|
||||
RestartPolicy: corev1.RestartPolicyAlways,
|
||||
// we decide later whether to use a PVC volume or host volumes for mons, so only populate
|
||||
// the base volumes at this point.
|
||||
Volumes: controller.DaemonVolumesBase(monConfig.DataPathMap, keyringStoreName),
|
||||
Volumes: controller.DaemonVolumesBase(monConfig.DataPathMap, keyringStoreName, c.spec.DataDirHostPath),
|
||||
HostNetwork: monConfig.UseHostNetwork,
|
||||
PriorityClassName: cephv1.GetMonPriorityClassName(c.spec.PriorityClassNames),
|
||||
}
|
||||
@@ -239,9 +239,10 @@ func (c *Cluster) makeChownInitContainer(monConfig *monConfig) corev1.Container
|
||||
*monConfig.DataPathMap,
|
||||
c.spec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName),
|
||||
controller.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName, c.spec.DataDirHostPath),
|
||||
cephv1.GetMonResources(c.spec.Resources),
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -260,7 +261,7 @@ func (c *Cluster) makeMonFSInitContainer(monConfig *monConfig) corev1.Container
|
||||
),
|
||||
Image: c.spec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName, c.spec.DataDirHostPath),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
// filesystem creation does not require ports to be exposed
|
||||
Env: controller.DaemonEnvVars(c.spec.CephVersion.Image),
|
||||
@@ -301,7 +302,7 @@ func (c *Cluster) makeMonDaemonContainer(monConfig *monConfig) corev1.Container
|
||||
),
|
||||
Image: c.spec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(monConfig.DataPathMap, keyringStoreName, c.spec.DataDirHostPath),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
|
||||
@@ -53,6 +53,7 @@ func testPodSpec(t *testing.T, monID string, pvc bool) {
|
||||
setCommonMonProperties(c, 0, cephv1.MonSpec{Count: 3, AllowMultiplePerNode: true}, "rook/rook:myversion")
|
||||
c.spec.CephVersion = cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:myceph"}
|
||||
c.spec.Resources = map[string]v1.ResourceRequirements{}
|
||||
c.spec.DataDirHostPath = "/var/lib/rook"
|
||||
c.spec.Resources["mon"] = v1.ResourceRequirements{
|
||||
Limits: v1.ResourceList{
|
||||
v1.ResourceCPU: *resource.NewQuantity(200.0, resource.BinarySI),
|
||||
|
||||
@@ -43,6 +43,7 @@ const (
|
||||
controllerName = "ceph-nodedaemon-controller"
|
||||
// AppName is the value to the "app" label for the ceph-crash pods
|
||||
crashCollectorAppName = "rook-ceph-crashcollector"
|
||||
cephExporterAppName = "rook-ceph-exporter"
|
||||
prunerName = "rook-ceph-crashcollector-pruner"
|
||||
// NodeNameLabel is a node name label
|
||||
NodeNameLabel = "node_name"
|
||||
|
||||
@@ -59,7 +59,7 @@ func (r *ReconcileNode) createOrUpdateCephCrash(node corev1.Node, tolerations []
|
||||
return controllerutil.OperationResultNone, errors.Errorf("failed to set owner reference of crashcollector deployment %q", deploy.Name)
|
||||
}
|
||||
|
||||
volumes := controller.DaemonVolumesBase(config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath), "")
|
||||
volumes := controller.DaemonVolumesBase(config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath), "", cephCluster.Spec.DataDirHostPath)
|
||||
volumes = append(volumes, keyring.Volume().CrashCollector())
|
||||
|
||||
mutateFunc := func() error {
|
||||
@@ -140,7 +140,7 @@ func getCrashDirInitContainer(cephCluster cephv1.CephCluster) corev1.Container {
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(cephCluster.Spec.CephVersion.ImagePullPolicy),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
Resources: cephv1.GetCrashCollectorResources(cephCluster.Spec.Resources),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(dataPathMap, ""),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(dataPathMap, "", cephCluster.Spec.DataDirHostPath),
|
||||
}
|
||||
return container
|
||||
}
|
||||
@@ -152,9 +152,10 @@ func getCrashChownInitContainer(cephCluster cephv1.CephCluster) corev1.Container
|
||||
*dataPathMap,
|
||||
cephCluster.Spec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(cephCluster.Spec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(dataPathMap, ""),
|
||||
controller.DaemonVolumeMounts(dataPathMap, "", cephCluster.Spec.DataDirHostPath),
|
||||
cephv1.GetCrashCollectorResources(cephCluster.Spec.Resources),
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ func getCrashDaemonContainer(cephCluster cephv1.CephCluster, cephVersion cephver
|
||||
dataPathMap := config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath)
|
||||
crashEnvVar := generateCrashEnvVar()
|
||||
envVars := append(controller.DaemonEnvVars(cephImage), crashEnvVar)
|
||||
volumeMounts := controller.DaemonVolumeMounts(dataPathMap, "")
|
||||
volumeMounts := controller.DaemonVolumeMounts(dataPathMap, "", cephCluster.Spec.DataDirHostPath)
|
||||
volumeMounts = append(volumeMounts, keyring.VolumeMount().CrashCollector())
|
||||
|
||||
container := corev1.Container{
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
Copyright 2023 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package nodedaemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/operator/ceph/config"
|
||||
"github.com/rook/rook/pkg/operator/ceph/controller"
|
||||
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
)
|
||||
|
||||
const (
|
||||
monitoringPath = "/etc/ceph-monitoring/"
|
||||
serviceMonitorFile = "exporter-service-monitor.yaml"
|
||||
sockDir = "/run/ceph"
|
||||
perfCountersPrioLimit = "5"
|
||||
statsPeriod = "5"
|
||||
DefaultMetricsPort uint16 = 9926
|
||||
exporterServiceMetricName = "ceph-exporter-http-metrics"
|
||||
)
|
||||
|
||||
// createOrUpdateCephExporter is a wrapper around controllerutil.CreateOrUpdate
|
||||
func (r *ReconcileNode) createOrUpdateCephExporter(node corev1.Node, tolerations []corev1.Toleration, cephCluster cephv1.CephCluster, cephVersion *cephver.CephVersion) (controllerutil.OperationResult, error) {
|
||||
if !cephVersion.IsAtLeast(cephver.CephVersion{Major: 17, Minor: 2, Extra: 5}) {
|
||||
logger.Infof("Skipping exporter reconcile on ceph version %q", cephVersion.String())
|
||||
return controllerutil.OperationResultNone, nil
|
||||
}
|
||||
|
||||
nodeHostnameLabel, ok := node.Labels[corev1.LabelHostname]
|
||||
if !ok {
|
||||
return controllerutil.OperationResultNone, errors.Errorf("label key %q does not exist on node %q", corev1.LabelHostname, node.GetName())
|
||||
}
|
||||
deploy := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: k8sutil.TruncateNodeName(fmt.Sprintf("%s-%%s", cephExporterAppName), nodeHostnameLabel),
|
||||
Namespace: cephCluster.GetNamespace(),
|
||||
},
|
||||
}
|
||||
err := controllerutil.SetControllerReference(&cephCluster, deploy, r.scheme)
|
||||
if err != nil {
|
||||
return controllerutil.OperationResultNone, errors.Errorf("failed to set owner reference of ceph-exporter deployment %q", deploy.Name)
|
||||
}
|
||||
|
||||
configDir := path.Join(cephCluster.Spec.DataDirHostPath, cephCluster.Namespace)
|
||||
configHostPathType := v1.HostPathDirectory
|
||||
src := v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: configDir, Type: &configHostPathType}}
|
||||
volumes := append(controller.DaemonVolumesBase(config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath), "", cephCluster.Spec.DataDirHostPath), v1.Volume{Name: "ceph-conf-dir", VolumeSource: src})
|
||||
|
||||
mutateFunc := func() error {
|
||||
|
||||
// labels for the pod, the deployment, and the deploymentSelector
|
||||
deploymentLabels := map[string]string{
|
||||
corev1.LabelHostname: nodeHostnameLabel,
|
||||
k8sutil.AppAttr: cephExporterAppName,
|
||||
NodeNameLabel: node.GetName(),
|
||||
}
|
||||
|
||||
selectorLabels := map[string]string{
|
||||
corev1.LabelHostname: nodeHostnameLabel,
|
||||
k8sutil.AppAttr: cephExporterAppName,
|
||||
NodeNameLabel: node.GetName(),
|
||||
}
|
||||
|
||||
nodeSelector := map[string]string{corev1.LabelHostname: nodeHostnameLabel}
|
||||
|
||||
// Deployment selector is immutable so we set this value only if
|
||||
// a new object is going to be created
|
||||
if deploy.ObjectMeta.CreationTimestamp.IsZero() {
|
||||
deploy.Spec.Selector = &metav1.LabelSelector{
|
||||
MatchLabels: selectorLabels,
|
||||
}
|
||||
}
|
||||
|
||||
deploy.ObjectMeta.Labels = deploymentLabels
|
||||
cephv1.GetCephExporterLabels(cephCluster.Spec.Labels).ApplyToObjectMeta(&deploy.ObjectMeta)
|
||||
k8sutil.AddRookVersionLabelToDeployment(deploy)
|
||||
if cephVersion != nil {
|
||||
controller.AddCephVersionLabelToDeployment(*cephVersion, deploy)
|
||||
}
|
||||
deploy.Spec.Template = corev1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: deploymentLabels,
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeSelector,
|
||||
InitContainers: []corev1.Container{
|
||||
getCephExporterChownInitContainer(cephCluster),
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
getCephExporterDaemonContainer(cephCluster, *cephVersion),
|
||||
},
|
||||
Tolerations: tolerations,
|
||||
RestartPolicy: corev1.RestartPolicyAlways,
|
||||
HostNetwork: cephCluster.Spec.Network.IsHost(),
|
||||
Volumes: volumes,
|
||||
PriorityClassName: cephv1.GetCephExporterPriorityClassName(cephCluster.Spec.PriorityClassNames),
|
||||
},
|
||||
}
|
||||
cephv1.GetCephExporterAnnotations(cephCluster.Spec.Annotations).ApplyToObjectMeta(&deploy.Spec.Template.ObjectMeta)
|
||||
applyPrometheusAnnotations(cephCluster, &deploy.Spec.Template.ObjectMeta)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return controllerutil.CreateOrUpdate(r.opManagerContext, r.client, deploy, mutateFunc)
|
||||
}
|
||||
|
||||
func getCephExporterChownInitContainer(cephCluster cephv1.CephCluster) corev1.Container {
|
||||
dataPathMap := config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath)
|
||||
configDir := path.Join(cephCluster.Spec.DataDirHostPath, cephCluster.Namespace)
|
||||
mounts := append(controller.DaemonVolumeMounts(dataPathMap, "", cephCluster.Spec.DataDirHostPath), v1.VolumeMount{Name: "ceph-conf-dir", MountPath: configDir})
|
||||
|
||||
return controller.ChownCephDataDirsInitContainer(
|
||||
*dataPathMap,
|
||||
cephCluster.Spec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(cephCluster.Spec.CephVersion.ImagePullPolicy),
|
||||
mounts,
|
||||
cephv1.GetCephExporterResources(cephCluster.Spec.Resources),
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
func getCephExporterDaemonContainer(cephCluster cephv1.CephCluster, cephVersion cephver.CephVersion) corev1.Container {
|
||||
cephImage := cephCluster.Spec.CephVersion.Image
|
||||
dataPathMap := config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath)
|
||||
configDir := path.Join(cephCluster.Spec.DataDirHostPath, cephCluster.Namespace)
|
||||
cephConfFile := path.Join(configDir, fmt.Sprintf("%s.config", cephCluster.Namespace))
|
||||
volumeMounts := append(controller.DaemonVolumeMounts(dataPathMap, "", cephCluster.Spec.DataDirHostPath), v1.VolumeMount{Name: "ceph-conf-dir", MountPath: configDir})
|
||||
|
||||
container := corev1.Container{
|
||||
Name: "ceph-exporter",
|
||||
Command: []string{"ceph-exporter"},
|
||||
Args: []string{"--conf", cephConfFile, "--sock-dir", sockDir, "--port", strconv.Itoa(int(DefaultMetricsPort)), "--prio-limit", perfCountersPrioLimit, "--stats-period", statsPeriod},
|
||||
Image: cephImage,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(cephCluster.Spec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: volumeMounts,
|
||||
Resources: cephv1.GetCephExporterResources(cephCluster.Spec.Resources),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
}
|
||||
|
||||
return container
|
||||
}
|
||||
|
||||
// MakeCephExporterMetricsService generates the Kubernetes service object for the exporter monitoring service
|
||||
func MakeCephExporterMetricsService(cephCluster cephv1.CephCluster, servicePortMetricName string, scheme *runtime.Scheme) (*v1.Service, error) {
|
||||
labels := controller.AppLabels(cephExporterAppName, cephCluster.Namespace)
|
||||
|
||||
svc := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: cephExporterAppName,
|
||||
Namespace: cephCluster.Namespace,
|
||||
Labels: labels,
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
Type: v1.ServiceTypeClusterIP,
|
||||
Ports: []v1.ServicePort{
|
||||
{
|
||||
Name: servicePortMetricName,
|
||||
Port: int32(DefaultMetricsPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
Selector: labels,
|
||||
},
|
||||
}
|
||||
|
||||
err := controllerutil.SetControllerReference(&cephCluster, svc, scheme)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to set owner reference to monitoring service %q", svc.Name)
|
||||
}
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
// EnableCephExporterServiceMonitor add a servicemonitor that allows prometheus to scrape from the monitoring endpoint of the exporter
|
||||
func EnableCephExporterServiceMonitor(cephCluster cephv1.CephCluster, scheme *runtime.Scheme, opManagerContext context.Context) error {
|
||||
serviceMonitor, err := k8sutil.GetServiceMonitor(path.Join(monitoringPath, serviceMonitorFile))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "service monitor could not be enabled")
|
||||
}
|
||||
serviceMonitor.SetName(cephExporterAppName)
|
||||
serviceMonitor.SetNamespace(cephCluster.Namespace)
|
||||
cephv1.GetCephExporterLabels(cephCluster.Spec.Labels).OverwriteApplyToObjectMeta(&serviceMonitor.ObjectMeta)
|
||||
|
||||
err = controllerutil.SetControllerReference(&cephCluster, serviceMonitor, scheme)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to set owner reference to service monitor %q", serviceMonitor.Name)
|
||||
}
|
||||
serviceMonitor.Spec.NamespaceSelector.MatchNames = []string{cephCluster.Namespace}
|
||||
serviceMonitor.Spec.Selector.MatchLabels = controller.AppLabels(cephExporterAppName, cephCluster.Namespace)
|
||||
applyCephExporterLabels(cephCluster, serviceMonitor)
|
||||
|
||||
if _, err = k8sutil.CreateOrUpdateServiceMonitor(opManagerContext, serviceMonitor); err != nil {
|
||||
return errors.Wrap(err, "service monitor could not be enabled")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyCephExporterLabels(cephCluster cephv1.CephCluster, serviceMonitor *monitoringv1.ServiceMonitor) {
|
||||
if cephCluster.Spec.Labels != nil {
|
||||
if cephExporterLabels, ok := cephCluster.Spec.Labels["exporter"]; ok {
|
||||
if managedBy, ok := cephExporterLabels["rook.io/managedBy"]; ok {
|
||||
relabelConfig := monitoringv1.RelabelConfig{
|
||||
TargetLabel: "managedBy",
|
||||
Replacement: managedBy,
|
||||
}
|
||||
serviceMonitor.Spec.Endpoints[0].RelabelConfigs = append(
|
||||
serviceMonitor.Spec.Endpoints[0].RelabelConfigs, &relabelConfig)
|
||||
} else {
|
||||
logger.Info("rook.io/managedBy not specified in ceph-exporter labels")
|
||||
}
|
||||
} else {
|
||||
logger.Info("ceph-exporter labels not specified")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applyPrometheusAnnotations(cephCluster cephv1.CephCluster, objectMeta *metav1.ObjectMeta) {
|
||||
if len(cephv1.GetCephExporterAnnotations(cephCluster.Spec.Annotations)) == 0 {
|
||||
t := cephv1.Annotations{
|
||||
"prometheus.io/scrape": "true",
|
||||
"prometheus.io/port": strconv.Itoa(int(DefaultMetricsPort)),
|
||||
}
|
||||
|
||||
t.ApplyToObjectMeta(objectMeta)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
Copyright 2023 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package nodedaemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake"
|
||||
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
"github.com/rook/rook/pkg/operator/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
)
|
||||
|
||||
func TestCreateOrUpdateCephExporter(t *testing.T) {
|
||||
cephCluster := cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "rook-ceph"},
|
||||
}
|
||||
cephCluster.Spec.Labels = cephv1.LabelsSpec{}
|
||||
cephCluster.Spec.PriorityClassNames = cephv1.PriorityClassNamesSpec{}
|
||||
cephVersion := &cephver.CephVersion{Major: 17, Minor: 2, Extra: 5}
|
||||
ctx := context.TODO()
|
||||
context := &clusterd.Context{
|
||||
Clientset: test.New(t, 1),
|
||||
RookClientset: rookclient.NewSimpleClientset(),
|
||||
}
|
||||
|
||||
s := scheme.Scheme
|
||||
err := appsv1.AddToScheme(s)
|
||||
if err != nil {
|
||||
assert.Fail(t, "failed to build scheme")
|
||||
}
|
||||
r := &ReconcileNode{
|
||||
scheme: s,
|
||||
client: fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects().Build(),
|
||||
context: context,
|
||||
}
|
||||
|
||||
node := corev1.Node{}
|
||||
nodeSelector := map[string]string{corev1.LabelHostname: "testnode"}
|
||||
node.SetLabels(nodeSelector)
|
||||
tolerations := []corev1.Toleration{{}}
|
||||
res, err := r.createOrUpdateCephExporter(node, tolerations, cephCluster, cephVersion)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, controllerutil.OperationResult("created"), res)
|
||||
name := k8sutil.TruncateNodeName(fmt.Sprintf("%s-%%s", cephExporterAppName), "testnode")
|
||||
deploy := appsv1.Deployment{}
|
||||
err = r.client.Get(ctx, types.NamespacedName{Namespace: "rook-ceph", Name: name}, &deploy)
|
||||
assert.NoError(t, err)
|
||||
podSpec := deploy.Spec.Template
|
||||
assert.Equal(t, nodeSelector, podSpec.Spec.NodeSelector)
|
||||
assert.Equal(t, "", podSpec.ObjectMeta.Labels["foo"])
|
||||
assert.Equal(t, tolerations, podSpec.Spec.Tolerations)
|
||||
assert.Equal(t, false, podSpec.Spec.HostNetwork)
|
||||
assert.Equal(t, "", podSpec.Spec.PriorityClassName)
|
||||
|
||||
cephCluster.Spec.Labels[cephv1.KeyCephExporter] = map[string]string{"foo": "bar"}
|
||||
cephCluster.Spec.Network.HostNetwork = true
|
||||
cephCluster.Spec.PriorityClassNames[cephv1.KeyCephExporter] = "test-priority-class"
|
||||
tolerations = []corev1.Toleration{{Key: "key", Operator: "Equal", Value: "value", Effect: "NoSchedule"}}
|
||||
res, err = r.createOrUpdateCephExporter(node, tolerations, cephCluster, cephVersion)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, controllerutil.OperationResult("updated"), res)
|
||||
err = r.client.Get(ctx, types.NamespacedName{Namespace: "rook-ceph", Name: name}, &deploy)
|
||||
assert.NoError(t, err)
|
||||
podSpec = deploy.Spec.Template
|
||||
assert.Equal(t, "bar", podSpec.ObjectMeta.Labels["foo"])
|
||||
assert.Equal(t, tolerations, podSpec.Spec.Tolerations)
|
||||
assert.Equal(t, true, podSpec.Spec.HostNetwork)
|
||||
assert.Equal(t, "test-priority-class", podSpec.Spec.PriorityClassName)
|
||||
}
|
||||
|
||||
func TestServiceSpec(t *testing.T) {
|
||||
cephCluster := cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "rook-ceph"},
|
||||
}
|
||||
cephCluster.Spec.Labels = cephv1.LabelsSpec{}
|
||||
cephCluster.Spec.PriorityClassNames = cephv1.PriorityClassNamesSpec{}
|
||||
|
||||
s, err := MakeCephExporterMetricsService(cephCluster, exporterServiceMetricName, scheme.Scheme)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, s)
|
||||
assert.Equal(t, "rook-ceph-exporter", s.Name)
|
||||
assert.Equal(t, 1, len(s.Spec.Ports))
|
||||
assert.Equal(t, 2, len(s.Labels))
|
||||
assert.Equal(t, 2, len(s.Spec.Selector))
|
||||
}
|
||||
|
||||
func TestApplyCephExporterLabels(t *testing.T) {
|
||||
cephCluster := cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "rook-ceph"},
|
||||
}
|
||||
cephCluster.Spec.Labels = cephv1.LabelsSpec{}
|
||||
cephCluster.Spec.PriorityClassNames = cephv1.PriorityClassNamesSpec{}
|
||||
|
||||
sm := &monitoringv1.ServiceMonitor{Spec: monitoringv1.ServiceMonitorSpec{
|
||||
Endpoints: []monitoringv1.Endpoint{{}}}}
|
||||
|
||||
// Service Monitor RelabelConfigs updated when 'rook.io/managedBy' monitoring label is found
|
||||
monitoringLabels := cephv1.LabelsSpec{
|
||||
cephv1.KeyCephExporter: map[string]string{
|
||||
"rook.io/managedBy": "storagecluster"},
|
||||
}
|
||||
cephCluster.Spec.Labels = monitoringLabels
|
||||
applyCephExporterLabels(cephCluster, sm)
|
||||
fmt.Printf("Hello1")
|
||||
assert.Equal(t, "managedBy", sm.Spec.Endpoints[0].RelabelConfigs[0].TargetLabel)
|
||||
assert.Equal(t, "storagecluster", sm.Spec.Endpoints[0].RelabelConfigs[0].Replacement)
|
||||
|
||||
// Service Monitor RelabelConfigs not updated when the required monitoring label is not found
|
||||
monitoringLabels = cephv1.LabelsSpec{
|
||||
cephv1.KeyCephExporter: map[string]string{
|
||||
"wrongLabelKey": "storagecluster"},
|
||||
}
|
||||
cephCluster.Spec.Labels = monitoringLabels
|
||||
sm.Spec.Endpoints[0].RelabelConfigs = nil
|
||||
applyCephExporterLabels(cephCluster, sm)
|
||||
assert.Nil(t, sm.Spec.Endpoints[0].RelabelConfigs)
|
||||
|
||||
// Service Monitor RelabelConfigs not updated when no monitoring labels are found
|
||||
cephCluster.Spec.Labels = cephv1.LabelsSpec{}
|
||||
sm.Spec.Endpoints[0].RelabelConfigs = nil
|
||||
applyCephExporterLabels(cephCluster, sm)
|
||||
assert.Nil(t, sm.Spec.Endpoints[0].RelabelConfigs)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func (r *ReconcileNode) createOrUpdateCephCron(cephCluster cephv1.CephCluster, c
|
||||
Namespace: cephCluster.GetNamespace(),
|
||||
}
|
||||
// Adding volumes to pods containing data needed to connect to the ceph cluster.
|
||||
volumes := controller.DaemonVolumesBase(config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath), "")
|
||||
volumes := controller.DaemonVolumesBase(config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath), "", cephCluster.Spec.DataDirHostPath)
|
||||
volumes = append(volumes, keyring.Volume().CrashCollector())
|
||||
|
||||
// labels for the pod, the deployment, and the deploymentSelector
|
||||
@@ -173,7 +173,7 @@ func getCrashPruneContainer(cephCluster cephv1.CephCluster, cephVersion cephver.
|
||||
cephImage := cephCluster.Spec.CephVersion.Image
|
||||
envVars := append(controller.DaemonEnvVars(cephImage), generateCrashEnvVar())
|
||||
dataPathMap := config.NewDatalessDaemonDataPathMap(cephCluster.GetNamespace(), cephCluster.Spec.DataDirHostPath)
|
||||
volumeMounts := controller.DaemonVolumeMounts(dataPathMap, "")
|
||||
volumeMounts := controller.DaemonVolumeMounts(dataPathMap, "", cephCluster.Spec.DataDirHostPath)
|
||||
volumeMounts = append(volumeMounts, keyring.VolumeMount().CrashCollector())
|
||||
|
||||
container := corev1.Container{
|
||||
|
||||
@@ -96,7 +96,7 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
// if a node is not present, check if there are any node daemons to remove
|
||||
err := r.listNodeDaemonsAndDelete(request.Name, "")
|
||||
if err != nil {
|
||||
logger.Errorf("failed to list and delete crash collector deployment on node %q; user should delete them manually. %v", request.Name, err)
|
||||
logger.Errorf("failed to list and delete deployment on node %q; user should delete them manually. %v", request.Name, err)
|
||||
}
|
||||
} else {
|
||||
return reconcile.Result{}, errors.Wrapf(err, "could not get node %q", request.Name)
|
||||
@@ -144,7 +144,7 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
logger.Errorf("more than one CephCluster found in the namespace %q, choosing the first one %q", namespace, cephCluster.GetName())
|
||||
}
|
||||
|
||||
allDisabled := r.removeDisabledNodeDaemons(cephCluster.Spec, namespace)
|
||||
allDisabled := r.removeDisabledCrashCollectorDaemons(cephCluster.Spec, namespace) && r.removeDisabledCephExporterDaemons(cephCluster.Spec, namespace)
|
||||
if allDisabled {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
@@ -189,11 +189,11 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
return reconcile.Result{}, errors.Wrap(err, "node reconcile failed")
|
||||
}
|
||||
} else {
|
||||
// If there are no Ceph pods, check that there are no crash collector pods in case Ceph pods moved to another node
|
||||
// Thus the crash collector must be removed from that node
|
||||
// If there are no Ceph pods, check that there are no crash collector or ceph-exporter pods in case Ceph pods moved to another node
|
||||
// Thus the crash collector and ceph-exporter must be removed from that node
|
||||
err := r.listNodeDaemonsAndDelete(request.Name, namespace)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, errors.Wrapf(err, "failed to list and delete crash collector deployments in namespace %q on node %q", namespace, request.Name)
|
||||
return reconcile.Result{}, errors.Wrapf(err, "failed to list and delete deployments in namespace %q on node %q", namespace, request.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,20 +218,52 @@ func (r *ReconcileNode) createOrUpdateNodeDaemons(node corev1.Node, tolerations
|
||||
logger.Debugf("crash collector successfully reconciled for node %q. operation: %q", node.Name, op)
|
||||
}
|
||||
}
|
||||
if cephCluster.Spec.Monitoring.Enabled {
|
||||
op, err := r.createOrUpdateCephExporter(node, tolerations, cephCluster, cephVersion)
|
||||
if err != nil {
|
||||
if op == "unchanged" {
|
||||
logger.Debugf("ceph exporter unchanged on node %q", node.Name)
|
||||
} else {
|
||||
return errors.Wrapf(err, "ceph exporter reconcile failed on op %q", op)
|
||||
}
|
||||
} else {
|
||||
logger.Debugf("ceph exporter successfully reconciled for node %q. operation: %q", node.Name, op)
|
||||
// create the metrics service
|
||||
service, err := MakeCephExporterMetricsService(cephCluster, exporterServiceMetricName, r.scheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := k8sutil.CreateOrUpdateService(r.opManagerContext, r.context.Clientset, cephCluster.Namespace, service); err != nil {
|
||||
return errors.Wrap(err, "failed to create ceph-exporter metrics service")
|
||||
}
|
||||
|
||||
if err := EnableCephExporterServiceMonitor(cephCluster, r.scheme, r.opManagerContext); err != nil {
|
||||
return errors.Wrap(err, "failed to enable service monitor")
|
||||
}
|
||||
logger.Debug("service monitor for ceph exporter was enabled successfully")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ReconcileNode) removeDisabledNodeDaemons(spec cephv1.ClusterSpec, namespace string) bool {
|
||||
// If the daemons are disabled in the spec let's remove them
|
||||
allDisabled := true
|
||||
func (r *ReconcileNode) removeDisabledCrashCollectorDaemons(spec cephv1.ClusterSpec, namespace string) bool {
|
||||
// If the crash daemons are disabled in the spec let's remove them
|
||||
if spec.CrashCollector.Disable {
|
||||
r.deleteNodeDaemon(crashCollectorAppName, namespace)
|
||||
} else {
|
||||
allDisabled = false
|
||||
}
|
||||
|
||||
return allDisabled
|
||||
return spec.CrashCollector.Disable
|
||||
}
|
||||
|
||||
func (r *ReconcileNode) removeDisabledCephExporterDaemons(spec cephv1.ClusterSpec, namespace string) bool {
|
||||
// If the ceph-exporter daemons are disabled in the spec let's remove them
|
||||
if !spec.Monitoring.Enabled {
|
||||
r.deleteNodeDaemon(cephExporterAppName, namespace)
|
||||
}
|
||||
|
||||
return !spec.Monitoring.Enabled
|
||||
}
|
||||
|
||||
func (r *ReconcileNode) listDeploymentAndDelete(appName, nodeName, ns string) error {
|
||||
@@ -239,15 +271,15 @@ func (r *ReconcileNode) listDeploymentAndDelete(appName, nodeName, ns string) er
|
||||
namespaceListOpts := client.InNamespace(ns)
|
||||
err := r.client.List(r.opManagerContext, deploymentList, client.MatchingLabels{k8sutil.AppAttr: appName, NodeNameLabel: nodeName}, namespaceListOpts)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to list crash collector deployments in namespace %q", ns)
|
||||
return errors.Wrapf(err, "failed to list deployments in namespace %q", ns)
|
||||
}
|
||||
for _, d := range deploymentList.Items {
|
||||
logger.Infof("deleting deployment %q for node %q", d.ObjectMeta.Name, nodeName)
|
||||
err := r.deleteDeployment(d)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete crash collector deployment %q in namespace %q", d.Name, d.Namespace)
|
||||
return errors.Wrapf(err, "failed to delete deployment %q in namespace %q", d.Name, d.Namespace)
|
||||
}
|
||||
logger.Infof("successfully removed crash collector deployment %q in namespace %q from node %q", d.Name, d.Namespace, nodeName)
|
||||
logger.Infof("successfully removed deployment %q in namespace %q from node %q", d.Name, d.Namespace, nodeName)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -260,7 +292,7 @@ func (r *ReconcileNode) deleteNodeDaemon(appName, namespace string) {
|
||||
// Try to fetch the list of existing deployment and remove them
|
||||
err := r.client.List(r.opManagerContext, deploymentList, client.MatchingLabels{k8sutil.AppAttr: appName}, namespaceListOpts)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to list crash collector deployments in namespace %q, delete it/them manually. %v", namespace, err)
|
||||
logger.Errorf("failed to list deployments in namespace %q, delete it/them manually. %v", namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -268,10 +300,10 @@ func (r *ReconcileNode) deleteNodeDaemon(appName, namespace string) {
|
||||
for _, d := range deploymentList.Items {
|
||||
err := r.deleteDeployment(d)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to delete crash collector deployment %q in namespace %q, delete it manually. %v", d.Name, d.Namespace, err)
|
||||
logger.Errorf("failed to delete deployment %q in namespace %q, delete it manually. %v", d.Name, d.Namespace, err)
|
||||
continue
|
||||
}
|
||||
logger.Infof("crash collector deployment %q in namespace %q successfully removed", d.Name, d.Namespace)
|
||||
logger.Infof("Deployments %q in namespace %q successfully removed", d.Name, d.Namespace)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,6 +330,11 @@ func (r *ReconcileNode) listNodeDaemonsAndDelete(nodeName, ns string) error {
|
||||
return errors.Wrap(err, "failed to delete crash collector")
|
||||
}
|
||||
|
||||
// delete the ceph-exporter daemons on the given node
|
||||
if err := r.listDeploymentAndDelete(cephExporterAppName, nodeName, ns); err != nil {
|
||||
return errors.Wrap(err, "failed to delete ceph-exporter")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -544,6 +544,7 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC
|
||||
volumeMounts,
|
||||
osdProps.resources,
|
||||
securityContext,
|
||||
"",
|
||||
))
|
||||
|
||||
podTemplateSpec := v1.PodTemplateSpec{
|
||||
|
||||
@@ -104,6 +104,7 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
"TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES": "134217728",
|
||||
},
|
||||
},
|
||||
DataDirHostPath: "/var/lib/rook/",
|
||||
}
|
||||
c := New(context, clusterInfo, spec, "rook/rook:myversion")
|
||||
|
||||
@@ -142,10 +143,10 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, corev1.RestartPolicyAlways, deployment.Spec.Template.Spec.RestartPolicy)
|
||||
assert.Equal(t, "my-priority-class", deployment.Spec.Template.Spec.PriorityClassName)
|
||||
if devMountNeeded && len(dataDir) > 0 {
|
||||
assert.Equal(t, 8, len(deployment.Spec.Template.Spec.Volumes))
|
||||
assert.Equal(t, 9, len(deployment.Spec.Template.Spec.Volumes))
|
||||
}
|
||||
if devMountNeeded && len(dataDir) == 0 {
|
||||
assert.Equal(t, 8, len(deployment.Spec.Template.Spec.Volumes))
|
||||
assert.Equal(t, 9, len(deployment.Spec.Template.Spec.Volumes))
|
||||
}
|
||||
if !devMountNeeded && len(dataDir) > 0 {
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Volumes))
|
||||
@@ -171,12 +172,12 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
initCont = deployment.Spec.Template.Spec.InitContainers[2]
|
||||
assert.Equal(t, "quay.io/ceph/ceph:v15", initCont.Image)
|
||||
assert.Equal(t, "chown-container-data-dir", initCont.Name)
|
||||
assert.Equal(t, 7, len(initCont.VolumeMounts))
|
||||
assert.Equal(t, 8, len(initCont.VolumeMounts))
|
||||
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont := deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, spec.CephVersion.Image, cont.Image)
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts))
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts))
|
||||
assert.Equal(t, "ceph-osd", cont.Command[0])
|
||||
verifyEnvVar(t, cont.Env, "TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES", "134217728", true)
|
||||
|
||||
@@ -204,11 +205,11 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[3].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
initCont = deployment.Spec.Template.Spec.InitContainers[0]
|
||||
assert.Equal(t, 4, len(initCont.VolumeMounts), initCont.VolumeMounts)
|
||||
assert.Equal(t, 5, len(initCont.VolumeMounts), initCont.VolumeMounts)
|
||||
blkInitCont := deployment.Spec.Template.Spec.InitContainers[2]
|
||||
assert.Equal(t, 1, len(blkInitCont.VolumeDevices))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 9, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
|
||||
// Test OSD on PVC with RAW
|
||||
osd = OSDInfo{
|
||||
@@ -225,7 +226,7 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[3].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 6, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
|
||||
// Test with encrypted OSD on PVC with RAW
|
||||
osdProp.encrypted = true
|
||||
@@ -245,9 +246,9 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[7].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
osdProp.encrypted = false
|
||||
assert.Equal(t, 9, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
assert.Equal(t, 10, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
|
||||
// // Test OSD on PVC with RAW and metadata device
|
||||
osd = OSDInfo{
|
||||
@@ -266,12 +267,12 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[4].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 6, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
blkInitCont = deployment.Spec.Template.Spec.InitContainers[1]
|
||||
assert.Equal(t, 1, len(blkInitCont.VolumeDevices))
|
||||
blkMetaInitCont := deployment.Spec.Template.Spec.InitContainers[2]
|
||||
assert.Equal(t, 1, len(blkMetaInitCont.VolumeDevices))
|
||||
assert.Equal(t, 9, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
assert.Equal(t, 10, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
|
||||
// // Test encrypted OSD on PVC with RAW and metadata device
|
||||
osd = OSDInfo{
|
||||
@@ -297,13 +298,13 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[10].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
blkInitCont = deployment.Spec.Template.Spec.InitContainers[1]
|
||||
assert.Equal(t, 1, len(blkInitCont.VolumeDevices))
|
||||
blkMetaInitCont = deployment.Spec.Template.Spec.InitContainers[8]
|
||||
assert.Equal(t, 1, len(blkMetaInitCont.VolumeDevices))
|
||||
osdProp.encrypted = false
|
||||
assert.Equal(t, 11, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
assert.Equal(t, 12, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
|
||||
// // Test OSD on PVC with RAW / metadata and wal device
|
||||
osd = OSDInfo{
|
||||
@@ -324,12 +325,12 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[5].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 6, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
blkInitCont = deployment.Spec.Template.Spec.InitContainers[1]
|
||||
assert.Equal(t, 1, len(blkInitCont.VolumeDevices))
|
||||
blkMetaInitCont = deployment.Spec.Template.Spec.InitContainers[2]
|
||||
assert.Equal(t, 1, len(blkMetaInitCont.VolumeDevices))
|
||||
assert.Equal(t, 11, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
assert.Equal(t, 12, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
|
||||
// // Test encrypted OSD on PVC with RAW / metadata and wal device
|
||||
osd = OSDInfo{
|
||||
@@ -359,12 +360,12 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[13].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
blkInitCont = deployment.Spec.Template.Spec.InitContainers[1]
|
||||
assert.Equal(t, 1, len(blkInitCont.VolumeDevices))
|
||||
blkMetaInitCont = deployment.Spec.Template.Spec.InitContainers[11]
|
||||
assert.Equal(t, 1, len(blkMetaInitCont.VolumeDevices))
|
||||
assert.Equal(t, 13, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
assert.Equal(t, 14, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
|
||||
// Test with encrypted OSD on PVC with RAW with KMS
|
||||
osdProp.encrypted = true
|
||||
@@ -387,8 +388,8 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[8].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 9, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes) // One more than the encryption with k8s for the kek get init container
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 10, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes) // One more than the encryption with k8s for the kek get init container
|
||||
|
||||
// Test with encrypted OSD on PVC with RAW with KMS
|
||||
osdProp.encrypted = true
|
||||
@@ -411,8 +412,8 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
assert.Equal(t, "chown-container-data-dir", deployment.Spec.Template.Spec.InitContainers[8].Name)
|
||||
assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Containers))
|
||||
cont = deployment.Spec.Template.Spec.Containers[0]
|
||||
assert.Equal(t, 7, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 10, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
assert.Equal(t, 8, len(cont.VolumeMounts), cont.VolumeMounts)
|
||||
assert.Equal(t, 11, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes)
|
||||
|
||||
// Test with encrypted OSD on PVC with RAW with KMS with TLS
|
||||
osdProp.encrypted = true
|
||||
@@ -423,8 +424,8 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) {
|
||||
deployment, err = c.makeDeployment(osdProp, osd, dataPathMap)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, deployment)
|
||||
assert.Equal(t, 10, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes) // One more than the encryption with k8s for the kek get init container
|
||||
assert.Equal(t, 3, len(deployment.Spec.Template.Spec.Volumes[7].VolumeSource.Projected.Sources), deployment.Spec.Template.Spec.Volumes[0]) // 3 more since we have the tls secrets
|
||||
assert.Equal(t, 11, len(deployment.Spec.Template.Spec.Volumes), deployment.Spec.Template.Spec.Volumes) // One more than the encryption with k8s for the kek get init container
|
||||
assert.Equal(t, 3, len(deployment.Spec.Template.Spec.Volumes[8].VolumeSource.Projected.Sources), deployment.Spec.Template.Spec.Volumes[0]) // 3 more since we have the tls secrets
|
||||
osdProp.encrypted = false
|
||||
|
||||
// Test tune Fast settings when OSD on PVC
|
||||
|
||||
@@ -40,7 +40,7 @@ func (r *ReconcileCephRBDMirror) makeDeployment(daemonConfig *daemonConfig, rbdM
|
||||
r.makeMirroringDaemonContainer(daemonConfig, rbdMirror),
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyAlways,
|
||||
Volumes: controller.DaemonVolumes(daemonConfig.DataPathMap, daemonConfig.ResourceName),
|
||||
Volumes: controller.DaemonVolumes(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
||||
HostNetwork: r.cephClusterSpec.Network.IsHost(),
|
||||
PriorityClassName: rbdMirror.Spec.PriorityClassName,
|
||||
},
|
||||
@@ -101,9 +101,10 @@ func (r *ReconcileCephRBDMirror) makeChownInitContainer(daemonConfig *daemonConf
|
||||
*daemonConfig.DataPathMap,
|
||||
r.cephClusterSpec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(r.cephClusterSpec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
|
||||
controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
||||
rbdMirror.Spec.Resources,
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ func (r *ReconcileCephRBDMirror) makeMirroringDaemonContainer(daemonConfig *daem
|
||||
),
|
||||
Image: r.cephClusterSpec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(r.cephClusterSpec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
||||
Env: controller.DaemonEnvVars(r.cephClusterSpec.CephVersion.Image),
|
||||
Resources: rbdMirror.Spec.Resources,
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
|
||||
@@ -50,6 +50,7 @@ func TestPodSpec(t *testing.T) {
|
||||
CephVersion: cephv1.CephVersionSpec{
|
||||
Image: "quay.io/ceph/ceph:v15",
|
||||
},
|
||||
DataDirHostPath: "/var/lib/rook",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -87,9 +88,9 @@ func TestPodSpec(t *testing.T) {
|
||||
d, err := r.makeDeployment(&daemonConf, rbdMirror)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "rook-ceph-rbd-mirror-a", d.Name)
|
||||
assert.Equal(t, 4, len(d.Spec.Template.Spec.Volumes))
|
||||
assert.Equal(t, 5, len(d.Spec.Template.Spec.Volumes))
|
||||
assert.Equal(t, 1, len(d.Spec.Template.Spec.Volumes[0].Projected.Sources))
|
||||
assert.Equal(t, 4, len(d.Spec.Template.Spec.Containers[0].VolumeMounts))
|
||||
assert.Equal(t, 5, len(d.Spec.Template.Spec.Containers[0].VolumeMounts))
|
||||
|
||||
// Deployment should have Ceph labels
|
||||
test.AssertLabelsContainCephRequirements(t, d.ObjectMeta.Labels,
|
||||
|
||||
@@ -49,10 +49,12 @@ const (
|
||||
volumeMountSubPath = "data"
|
||||
crashVolumeName = "rook-ceph-crash"
|
||||
daemonSocketDir = "/run/ceph"
|
||||
daemonSocketsSubPath = "/exporter"
|
||||
logCollector = "log-collector"
|
||||
DaemonIDLabel = "ceph_daemon_id"
|
||||
daemonTypeLabel = "ceph_daemon_type"
|
||||
ExternalMgrAppName = "rook-ceph-mgr-external"
|
||||
ExternalCephExporterName = "rook-ceph-exporter-external"
|
||||
ServiceExternalMetricName = "http-external-metrics"
|
||||
CephUserID = 167
|
||||
livenessProbeTimeoutSeconds int32 = 5
|
||||
@@ -170,8 +172,11 @@ func ConfGeneratedInPodVolumeAndMount() (v1.Volume, v1.VolumeMount) {
|
||||
func PodVolumes(dataPaths *config.DataPathMap, dataDirHostPath string, confGeneratedInPod bool) []v1.Volume {
|
||||
|
||||
dataDirSource := v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}
|
||||
sockDirSource := v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}
|
||||
if dataDirHostPath != "" {
|
||||
dataDirSource = v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: dataDirHostPath}}
|
||||
hostPathType := v1.HostPathDirectoryOrCreate
|
||||
sockDirSource = v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: path.Join(dataDirHostPath, daemonSocketsSubPath), Type: &hostPathType}}
|
||||
}
|
||||
configVolume, _ := configOverrideConfigMapVolumeAndMount()
|
||||
if confGeneratedInPod {
|
||||
@@ -182,6 +187,7 @@ func PodVolumes(dataPaths *config.DataPathMap, dataDirHostPath string, confGener
|
||||
{Name: k8sutil.DataDirVolume, VolumeSource: dataDirSource},
|
||||
configVolume,
|
||||
}
|
||||
v = append(v, v1.Volume{Name: "ceph-daemons-sock-dir", VolumeSource: sockDirSource})
|
||||
v = append(v, StoredLogAndCrashVolume(dataPaths.HostLogDir(), dataPaths.HostCrashDir())...)
|
||||
|
||||
return v
|
||||
@@ -200,6 +206,7 @@ func CephVolumeMounts(dataPaths *config.DataPathMap, confGeneratedInPod bool) []
|
||||
configMount,
|
||||
// Rook doesn't run in ceph containers, so it doesn't need the config override mounted
|
||||
}
|
||||
v = append(v, v1.VolumeMount{Name: "ceph-daemons-sock-dir", MountPath: daemonSocketDir})
|
||||
v = append(v, StoredLogAndCrashVolumeMount(dataPaths.ContainerLogDir(), dataPaths.ContainerCrashDir())...)
|
||||
|
||||
return v
|
||||
@@ -213,7 +220,7 @@ func RookVolumeMounts(dataPaths *config.DataPathMap, confGeneratedInPod bool) []
|
||||
}
|
||||
|
||||
// DaemonVolumesBase returns the common / static set of volumes.
|
||||
func DaemonVolumesBase(dataPaths *config.DataPathMap, keyringResourceName string) []v1.Volume {
|
||||
func DaemonVolumesBase(dataPaths *config.DataPathMap, keyringResourceName string, dataDirHostPath string) []v1.Volume {
|
||||
configOverrideVolume, _ := configOverrideConfigMapVolumeAndMount()
|
||||
vols := []v1.Volume{
|
||||
configOverrideVolume,
|
||||
@@ -221,6 +228,12 @@ func DaemonVolumesBase(dataPaths *config.DataPathMap, keyringResourceName string
|
||||
if keyringResourceName != "" {
|
||||
vols = append(vols, keyring.Volume().Resource(keyringResourceName))
|
||||
}
|
||||
// data is persisted to host
|
||||
if dataDirHostPath != "" {
|
||||
hostPathType := v1.HostPathDirectoryOrCreate
|
||||
src := v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: path.Join(dataDirHostPath, daemonSocketsSubPath), Type: &hostPathType}}
|
||||
vols = append(vols, v1.Volume{Name: "ceph-daemons-sock-dir", VolumeSource: src})
|
||||
}
|
||||
if dataPaths.HostLogAndCrashDir != "" {
|
||||
// logs are not persisted to host
|
||||
vols = append(vols, StoredLogAndCrashVolume(dataPaths.HostLogDir(), dataPaths.HostCrashDir())...)
|
||||
@@ -270,8 +283,8 @@ func DaemonVolumesContainsPVC(volumes []v1.Volume) bool {
|
||||
|
||||
// DaemonVolumes returns the pod volumes used by all Ceph daemons. If keyring resource name is
|
||||
// empty, there will be no keyring volume created from a secret.
|
||||
func DaemonVolumes(dataPaths *config.DataPathMap, keyringResourceName string) []v1.Volume {
|
||||
vols := DaemonVolumesBase(dataPaths, keyringResourceName)
|
||||
func DaemonVolumes(dataPaths *config.DataPathMap, keyringResourceName string, dataDirHostPath string) []v1.Volume {
|
||||
vols := DaemonVolumesBase(dataPaths, keyringResourceName, dataDirHostPath)
|
||||
vols = append(vols, DaemonVolumesDataHostPath(dataPaths)...)
|
||||
return vols
|
||||
}
|
||||
@@ -279,11 +292,14 @@ func DaemonVolumes(dataPaths *config.DataPathMap, keyringResourceName string) []
|
||||
// DaemonVolumeMounts returns volume mounts which correspond to the DaemonVolumes. These
|
||||
// volume mounts are shared by most all Ceph daemon containers, both init and standard. If keyring
|
||||
// resource name is empty, there will be no keyring mounted in the container.
|
||||
func DaemonVolumeMounts(dataPaths *config.DataPathMap, keyringResourceName string) []v1.VolumeMount {
|
||||
func DaemonVolumeMounts(dataPaths *config.DataPathMap, keyringResourceName string, dataDirHostPath string) []v1.VolumeMount {
|
||||
_, configOverrideMount := configOverrideConfigMapVolumeAndMount()
|
||||
mounts := []v1.VolumeMount{
|
||||
configOverrideMount,
|
||||
}
|
||||
if dataDirHostPath != "" {
|
||||
mounts = append(mounts, v1.VolumeMount{Name: "ceph-daemons-sock-dir", MountPath: daemonSocketDir})
|
||||
}
|
||||
if keyringResourceName != "" {
|
||||
mounts = append(mounts, keyring.VolumeMount().Resource(keyringResourceName))
|
||||
}
|
||||
@@ -466,6 +482,7 @@ func ChownCephDataDirsInitContainer(
|
||||
volumeMounts []v1.VolumeMount,
|
||||
resources v1.ResourceRequirements,
|
||||
securityContext *v1.SecurityContext,
|
||||
configDir string,
|
||||
) v1.Container {
|
||||
args := make([]string, 0, 5)
|
||||
args = append(args,
|
||||
@@ -474,7 +491,12 @@ func ChownCephDataDirsInitContainer(
|
||||
"ceph:ceph",
|
||||
config.VarLogCephDir,
|
||||
config.VarLibCephCrashDir,
|
||||
daemonSocketDir,
|
||||
)
|
||||
if configDir != "" {
|
||||
args = append(args, configDir)
|
||||
}
|
||||
|
||||
if dpm.ContainerDataDir != "" {
|
||||
args = append(args, dpm.ContainerDataDir)
|
||||
}
|
||||
@@ -767,7 +789,7 @@ func LogCollectorContainer(daemonID, ns string, c cephv1.ClusterSpec) *v1.Contai
|
||||
},
|
||||
Image: c.CephVersion.Image,
|
||||
ImagePullPolicy: GetContainerImagePullPolicy(c.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: DaemonVolumeMounts(config.NewDatalessDaemonDataPathMap(ns, c.DataDirHostPath), ""),
|
||||
VolumeMounts: DaemonVolumeMounts(config.NewDatalessDaemonDataPathMap(ns, c.DataDirHostPath), "", c.DataDirHostPath),
|
||||
SecurityContext: PodSecurityContext(),
|
||||
Resources: cephv1.GetLogCollectorResources(c.Resources),
|
||||
// We need a TTY for the bash job control (enabled by -m)
|
||||
|
||||
@@ -60,7 +60,7 @@ func (c *Cluster) makeDeployment(mdsConfig *mdsConfig, namespace string) (*apps.
|
||||
mdsContainer,
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyAlways,
|
||||
Volumes: controller.DaemonVolumes(mdsConfig.DataPathMap, mdsConfig.ResourceName),
|
||||
Volumes: controller.DaemonVolumes(mdsConfig.DataPathMap, mdsConfig.ResourceName, c.clusterSpec.DataDirHostPath),
|
||||
HostNetwork: c.clusterSpec.Network.IsHost(),
|
||||
PriorityClassName: c.fs.Spec.MetadataServer.PriorityClassName,
|
||||
},
|
||||
@@ -120,9 +120,10 @@ func (c *Cluster) makeChownInitContainer(mdsConfig *mdsConfig) v1.Container {
|
||||
*mdsConfig.DataPathMap,
|
||||
c.clusterSpec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(c.clusterSpec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName),
|
||||
controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName, c.clusterSpec.DataDirHostPath),
|
||||
c.fs.Spec.MetadataServer.Resources,
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ func (c *Cluster) makeMdsDaemonContainer(mdsConfig *mdsConfig) v1.Container {
|
||||
Args: args,
|
||||
Image: c.clusterSpec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(c.clusterSpec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName, c.clusterSpec.DataDirHostPath),
|
||||
Env: append(controller.DaemonEnvVars(c.clusterSpec.CephVersion.Image), k8sutil.PodIPEnvVar(podIPEnvVar)),
|
||||
Resources: c.fs.Spec.MetadataServer.Resources,
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
|
||||
@@ -68,8 +68,9 @@ func testDeploymentObject(t *testing.T, network cephv1.NetworkSpec) (*apps.Deplo
|
||||
clusterInfo,
|
||||
&clusterd.Context{Clientset: clientset},
|
||||
&cephv1.ClusterSpec{
|
||||
CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:testversion"},
|
||||
Network: network,
|
||||
CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:testversion"},
|
||||
Network: network,
|
||||
DataDirHostPath: "/var/lib/rook/",
|
||||
},
|
||||
fs,
|
||||
&k8sutil.OwnerInfo{},
|
||||
|
||||
@@ -43,7 +43,7 @@ func (r *ReconcileFilesystemMirror) makeDeployment(daemonConfig *daemonConfig, f
|
||||
r.makeFsMirroringDaemonContainer(daemonConfig, fsMirror),
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyAlways,
|
||||
Volumes: controller.DaemonVolumes(daemonConfig.DataPathMap, daemonConfig.ResourceName),
|
||||
Volumes: controller.DaemonVolumes(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
||||
HostNetwork: r.cephClusterSpec.Network.IsHost(),
|
||||
PriorityClassName: fsMirror.Spec.PriorityClassName,
|
||||
},
|
||||
@@ -98,9 +98,10 @@ func (r *ReconcileFilesystemMirror) makeChownInitContainer(daemonConfig *daemonC
|
||||
*daemonConfig.DataPathMap,
|
||||
r.cephClusterSpec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(r.cephClusterSpec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
|
||||
controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
||||
fsMirror.Spec.Resources,
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ func (r *ReconcileFilesystemMirror) makeFsMirroringDaemonContainer(daemonConfig
|
||||
),
|
||||
Image: r.cephClusterSpec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(r.cephClusterSpec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName),
|
||||
VolumeMounts: controller.DaemonVolumeMounts(daemonConfig.DataPathMap, daemonConfig.ResourceName, r.cephClusterSpec.DataDirHostPath),
|
||||
Env: controller.DaemonEnvVars(r.cephClusterSpec.CephVersion.Image),
|
||||
Resources: fsMirror.Spec.Resources,
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
|
||||
@@ -48,6 +48,7 @@ func TestPodSpec(t *testing.T) {
|
||||
CephVersion: cephv1.CephVersionSpec{
|
||||
Image: "quay.io/ceph/ceph:v16",
|
||||
},
|
||||
DataDirHostPath: "/var/lib/rook/",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -84,9 +85,9 @@ func TestPodSpec(t *testing.T) {
|
||||
d, err := r.makeDeployment(&daemonConf, fsMirror)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "rook-ceph-fs-mirror", d.Name)
|
||||
assert.Equal(t, 4, len(d.Spec.Template.Spec.Volumes))
|
||||
assert.Equal(t, 5, len(d.Spec.Template.Spec.Volumes))
|
||||
assert.Equal(t, 1, len(d.Spec.Template.Spec.Volumes[0].Projected.Sources))
|
||||
assert.Equal(t, 4, len(d.Spec.Template.Spec.Containers[0].VolumeMounts))
|
||||
assert.Equal(t, 5, len(d.Spec.Template.Spec.Containers[0].VolumeMounts))
|
||||
|
||||
// Deployment should have Ceph labels
|
||||
test.AssertLabelsContainCephRequirements(t, d.ObjectMeta.Labels,
|
||||
|
||||
@@ -146,7 +146,7 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec
|
||||
Containers: []v1.Container{rgwDaemonContainer},
|
||||
RestartPolicy: v1.RestartPolicyAlways,
|
||||
Volumes: append(
|
||||
controller.DaemonVolumes(c.DataPathMap, rgwConfig.ResourceName),
|
||||
controller.DaemonVolumes(c.DataPathMap, rgwConfig.ResourceName, c.clusterSpec.DataDirHostPath),
|
||||
c.mimeTypesVolume(),
|
||||
),
|
||||
HostNetwork: hostNetwork,
|
||||
@@ -258,7 +258,7 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec
|
||||
|
||||
func (c *clusterConfig) createCaBundleUpdateInitContainer(rgwConfig *rgwConfig) v1.Container {
|
||||
caBundleMount := v1.VolumeMount{Name: caBundleVolumeName, MountPath: caBundleSourceCustomDir, ReadOnly: true}
|
||||
volumeMounts := append(controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName), caBundleMount)
|
||||
volumeMounts := append(controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName, c.clusterSpec.DataDirHostPath), caBundleMount)
|
||||
updatedCaBundleDir := "/tmp/new-ca-bundle/"
|
||||
updatedBundleMount := v1.VolumeMount{Name: caBundleUpdatedVolumeName, MountPath: updatedCaBundleDir, ReadOnly: false}
|
||||
volumeMounts = append(volumeMounts, updatedBundleMount)
|
||||
@@ -308,7 +308,7 @@ func (c *clusterConfig) vaultTokenInitContainer(rgwConfig *rgwConfig, kmsEnabled
|
||||
Image: c.clusterSpec.CephVersion.Image,
|
||||
ImagePullPolicy: controller.GetContainerImagePullPolicy(c.clusterSpec.CephVersion.ImagePullPolicy),
|
||||
VolumeMounts: append(
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName), vaultVolMounts...),
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName, c.clusterSpec.DataDirHostPath), vaultVolMounts...),
|
||||
Resources: c.store.Spec.Gateway.Resources,
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
}
|
||||
@@ -319,9 +319,10 @@ func (c *clusterConfig) makeChownInitContainer(rgwConfig *rgwConfig) v1.Containe
|
||||
*c.DataPathMap,
|
||||
c.clusterSpec.CephVersion.Image,
|
||||
controller.GetContainerImagePullPolicy(c.clusterSpec.CephVersion.ImagePullPolicy),
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName),
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName, c.clusterSpec.DataDirHostPath),
|
||||
c.store.Spec.Gateway.Resources,
|
||||
controller.PodSecurityContext(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -355,7 +356,7 @@ func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) (v1.Container,
|
||||
cephconfig.NewFlag("rgw zone", rgwConfig.Zone),
|
||||
),
|
||||
VolumeMounts: append(
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName),
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName, c.clusterSpec.DataDirHostPath),
|
||||
c.mimeTypesVolumeMount(),
|
||||
),
|
||||
Env: controller.DaemonEnvVars(c.clusterSpec.CephVersion.Image),
|
||||
|
||||
@@ -93,6 +93,7 @@ func TestPodSpecs(t *testing.T) {
|
||||
Network: cephv1.NetworkSpec{
|
||||
HostNetwork: true,
|
||||
},
|
||||
DataDirHostPath: "/var/lib/rook",
|
||||
},
|
||||
DataPathMap: data,
|
||||
}
|
||||
@@ -163,6 +164,7 @@ func TestSSLPodSpec(t *testing.T) {
|
||||
Network: cephv1.NetworkSpec{
|
||||
HostNetwork: true,
|
||||
},
|
||||
DataDirHostPath: "/var/lib/rook",
|
||||
},
|
||||
DataPathMap: data,
|
||||
}
|
||||
@@ -529,7 +531,8 @@ func TestCheckRGWSSES3Enabled(t *testing.T) {
|
||||
store: store,
|
||||
clusterInfo: &client.ClusterInfo{Context: ctx, CephVersion: cephver.CephVersion{Major: 17, Minor: 2, Extra: 3}},
|
||||
clusterSpec: &cephv1.ClusterSpec{
|
||||
CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:v17.2.5"},
|
||||
CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:v17.2.5"},
|
||||
DataDirHostPath: "/var/lib/rook",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ func (ps *PodSpecTester) AssertVolumesMeetCephRequirements(
|
||||
if daemonType != config.RbdMirrorType && daemonType != config.FilesystemMirrorType {
|
||||
requiredVols = append(requiredVols, "ceph-daemon-data")
|
||||
}
|
||||
requiredVols = append(requiredVols, "ceph-daemons-sock-dir")
|
||||
vols := []string{}
|
||||
|
||||
for _, v := range ps.spec.Volumes {
|
||||
|
||||
Reference in new issue
Block a user