From 76b14dbd097b6848d86d5718bcf65d479ee6c7cb Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Wed, 6 Mar 2024 12:38:13 +0530 Subject: [PATCH] Add mechanism for adding tolerations on metrics exporter Signed-off-by: Nitin Goyal --- controllers/defaults/placements.go | 9 ++++++++- controllers/storagecluster/exporter.go | 2 ++ controllers/storagecluster/placement.go | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/controllers/defaults/placements.go b/controllers/defaults/placements.go index 4ac96508dd..81a9198748 100644 --- a/controllers/defaults/placements.go +++ b/controllers/defaults/placements.go @@ -7,7 +7,8 @@ import ( ) var ( - ProviderServerKey = "provider-server" + ProviderServerKey = "provider-server" + MetricsExporterKey = "metrics-exporter" // osdLabelSelector is the key in OSD pod. Used // as a label selector for topology spread constraints. @@ -134,6 +135,12 @@ var ( getOcsToleration(), }, }, + + MetricsExporterKey: { + Tolerations: []corev1.Toleration{ + getOcsToleration(), + }, + }, } ) diff --git a/controllers/storagecluster/exporter.go b/controllers/storagecluster/exporter.go index 90e95cedd8..fb23762917 100644 --- a/controllers/storagecluster/exporter.go +++ b/controllers/storagecluster/exporter.go @@ -7,6 +7,7 @@ import ( "github.com/imdario/mergo" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" + "github.com/red-hat-storage/ocs-operator/v4/controllers/defaults" "github.com/red-hat-storage/ocs-operator/v4/version" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -351,6 +352,7 @@ func deployMetricsExporter(ctx context.Context, r *StorageClusterReconciler, ins }, }, }}, + Tolerations: getPlacement(instance, defaults.MetricsExporterKey).Tolerations, }, } return nil diff --git a/controllers/storagecluster/placement.go b/controllers/storagecluster/placement.go index 7ee2f5cbec..6646834bcb 100644 --- a/controllers/storagecluster/placement.go +++ b/controllers/storagecluster/placement.go @@ -44,6 +44,12 @@ func getPlacement(sc *ocsv1.StorageCluster, component string) rookCephv1.Placeme return placement } + // if metrics-exporter placements are found in the storagecluster spec append the default ocs tolerations to it + if ok && component == defaults.MetricsExporterKey { + placement.Tolerations = append(placement.Tolerations, defaults.DaemonPlacements[component].Tolerations...) + return placement + } + // If no placement is specified for the given component and the // StorageCluster has no label selector, set the default node // affinity.