From 96752c7bce37230cf239c0cfb43111a0a2770112 Mon Sep 17 00:00:00 2001 From: Mario Fernandez Date: Fri, 17 Jul 2026 13:06:47 +0200 Subject: [PATCH 1/2] Add configurationSource selector to ClusterMonitoring API. Allow choosing between the cluster-monitoring-config ConfigMap and the ClusterMonitoring CRD as the configuration source, defaulting to CRD. Co-authored-by: Cursor --- .../ClusterMonitoringConfig.yaml | 29 +++++++++++++++++++ config/v1alpha1/types_cluster_monitoring.go | 26 +++++++++++++++++ ...ig-operator_01_clustermonitorings.crd.yaml | 15 ++++++++++ .../ClusterMonitoringConfig.yaml | 15 ++++++++++ .../zz_generated.swagger_doc_generated.go | 1 + .../generated_openapi/zz_generated.openapi.go | 8 +++++ openapi/openapi.json | 8 +++++ ...ig-operator_01_clustermonitorings.crd.yaml | 15 ++++++++++ 8 files changed, 117 insertions(+) diff --git a/config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml b/config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml index 59f2e353175..5ace5bd83cd 100644 --- a/config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml +++ b/config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml @@ -18,6 +18,35 @@ tests: spec: userDefined: mode: "Disabled" + - name: Should accept configurationSource ConfigMap + initial: | + apiVersion: config.openshift.io/v1alpha1 + kind: ClusterMonitoring + spec: + configurationSource: ConfigMap + expected: | + apiVersion: config.openshift.io/v1alpha1 + kind: ClusterMonitoring + spec: + configurationSource: ConfigMap + - name: Should accept configurationSource CRD + initial: | + apiVersion: config.openshift.io/v1alpha1 + kind: ClusterMonitoring + spec: + configurationSource: CRD + expected: | + apiVersion: config.openshift.io/v1alpha1 + kind: ClusterMonitoring + spec: + configurationSource: CRD + - name: Should reject invalid configurationSource + initial: | + apiVersion: config.openshift.io/v1alpha1 + kind: ClusterMonitoring + spec: + configurationSource: Invalid + expectedError: 'spec.configurationSource: Unsupported value: "Invalid": supported values: "ConfigMap", "CRD"' - name: Should accept userAlertmanagerConfigSelection on alertmanagerConfig customConfig initial: | apiVersion: config.openshift.io/v1alpha1 diff --git a/config/v1alpha1/types_cluster_monitoring.go b/config/v1alpha1/types_cluster_monitoring.go index d4846fd1cdb..d2196fda3ad 100644 --- a/config/v1alpha1/types_cluster_monitoring.go +++ b/config/v1alpha1/types_cluster_monitoring.go @@ -76,6 +76,18 @@ type ClusterMonitoringList struct { // ClusterMonitoringSpec defines the desired state of Cluster Monitoring Operator // +kubebuilder:validation:MinProperties=1 type ClusterMonitoringSpec struct { + // configurationSource is an optional field that selects whether the Cluster Monitoring Operator + // reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. + // Valid values are "ConfigMap" and "CRD". + // When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the + // openshift-monitoring namespace as the configuration source. + // When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. + // When omitted, this means no opinion and the platform is left to choose a reasonable default, + // which is subject to change over time. + // The current default value is CRD. + // +optional + // +kubebuilder:validation:Enum=ConfigMap;CRD + ConfigurationSource ConfigurationSource `json:"configurationSource,omitempty"` // userDefined set the deployment mode for user-defined monitoring in addition to the default platform monitoring. // userDefined is optional. // When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. @@ -757,6 +769,20 @@ type MonitoringPluginConfig struct { TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` } +// ConfigurationSource selects the configuration source for the Cluster Monitoring Operator. +// +kubebuilder:validation:Enum=ConfigMap;CRD +// +enum +type ConfigurationSource string + +const ( + // ConfigurationSourceConfigMap means the operator reads configuration from the + // cluster-monitoring-config ConfigMap in the openshift-monitoring namespace. + ConfigurationSourceConfigMap ConfigurationSource = "ConfigMap" + // ConfigurationSourceCRD means the operator reads configuration from this + // ClusterMonitoring custom resource. + ConfigurationSourceCRD ConfigurationSource = "CRD" +) + // UserDefinedMonitoring config for user-defined projects. type UserDefinedMonitoring struct { // mode defines the different configurations of UserDefinedMonitoring diff --git a/config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings.crd.yaml b/config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings.crd.yaml index bb427426d04..136e8e3511f 100644 --- a/config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings.crd.yaml +++ b/config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings.crd.yaml @@ -915,6 +915,21 @@ spec: and forbidden otherwise rule: 'self.deploymentMode == ''CustomConfig'' ? has(self.customConfig) : !has(self.customConfig)' + configurationSource: + description: |- + configurationSource is an optional field that selects whether the Cluster Monitoring Operator + reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. + Valid values are "ConfigMap" and "CRD". + When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the + openshift-monitoring namespace as the configuration source. + When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. + When omitted, this means no opinion and the platform is left to choose a reasonable default, + which is subject to change over time. + The current default value is CRD. + enum: + - ConfigMap + - CRD + type: string kubeStateMetricsConfig: description: |- kubeStateMetricsConfig is an optional field that can be used to configure the kube-state-metrics diff --git a/config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml b/config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml index af278ae490c..aeab9f9450a 100644 --- a/config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml +++ b/config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml @@ -915,6 +915,21 @@ spec: and forbidden otherwise rule: 'self.deploymentMode == ''CustomConfig'' ? has(self.customConfig) : !has(self.customConfig)' + configurationSource: + description: |- + configurationSource is an optional field that selects whether the Cluster Monitoring Operator + reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. + Valid values are "ConfigMap" and "CRD". + When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the + openshift-monitoring namespace as the configuration source. + When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. + When omitted, this means no opinion and the platform is left to choose a reasonable default, + which is subject to change over time. + The current default value is CRD. + enum: + - ConfigMap + - CRD + type: string kubeStateMetricsConfig: description: |- kubeStateMetricsConfig is an optional field that can be used to configure the kube-state-metrics diff --git a/config/v1alpha1/zz_generated.swagger_doc_generated.go b/config/v1alpha1/zz_generated.swagger_doc_generated.go index 8f6cda1915a..7c2b771d275 100644 --- a/config/v1alpha1/zz_generated.swagger_doc_generated.go +++ b/config/v1alpha1/zz_generated.swagger_doc_generated.go @@ -173,6 +173,7 @@ func (ClusterMonitoringList) SwaggerDoc() map[string]string { var map_ClusterMonitoringSpec = map[string]string{ "": "ClusterMonitoringSpec defines the desired state of Cluster Monitoring Operator", + "configurationSource": "configurationSource is an optional field that selects whether the Cluster Monitoring Operator reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. Valid values are \"ConfigMap\" and \"CRD\". When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the openshift-monitoring namespace as the configuration source. When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The current default value is CRD.", "userDefined": "userDefined set the deployment mode for user-defined monitoring in addition to the default platform monitoring. userDefined is optional. When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The current default value is `Disabled`.", "alertmanagerConfig": "alertmanagerConfig allows users to configure how the default Alertmanager instance should be deployed in the `openshift-monitoring` namespace. alertmanagerConfig is optional. When omitted, this means no opinion and the platform is left to choose a reasonable default, that is subject to change over time. The current default value is `DefaultConfig`.", "prometheusConfig": "prometheusConfig provides configuration options for the default platform Prometheus instance that runs in the `openshift-monitoring` namespace. This configuration applies only to the platform Prometheus instance; user-workload Prometheus instances are configured separately.\n\nThis field allows you to customize how the platform Prometheus is deployed and operated, including:\n - Pod scheduling (node selectors, tolerations, topology spread constraints)\n - Resource allocation (CPU, memory requests/limits)\n - Retention policies (how long metrics are stored)\n - External integrations (remote write, additional alertmanagers)\n\nThis field is optional. When omitted, the platform chooses reasonable defaults, which may change over time.", diff --git a/openapi/generated_openapi/zz_generated.openapi.go b/openapi/generated_openapi/zz_generated.openapi.go index 9f78f6c321f..903dd6cc7cb 100644 --- a/openapi/generated_openapi/zz_generated.openapi.go +++ b/openapi/generated_openapi/zz_generated.openapi.go @@ -24072,6 +24072,14 @@ func schema_openshift_api_config_v1alpha1_ClusterMonitoringSpec(ref common.Refer Description: "ClusterMonitoringSpec defines the desired state of Cluster Monitoring Operator", Type: []string{"object"}, Properties: map[string]spec.Schema{ + "configurationSource": { + SchemaProps: spec.SchemaProps{ + Description: "configurationSource is an optional field that selects whether the Cluster Monitoring Operator reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. Valid values are \"ConfigMap\" and \"CRD\". When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the openshift-monitoring namespace as the configuration source. When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The current default value is CRD.\n\nPossible enum values:\n - `\"CRD\"` means the operator reads configuration from this ClusterMonitoring custom resource.\n - `\"ConfigMap\"` means the operator reads configuration from the cluster-monitoring-config ConfigMap in the openshift-monitoring namespace.", + Type: []string{"string"}, + Format: "", + Enum: []interface{}{"CRD", "ConfigMap"}, + }, + }, "userDefined": { SchemaProps: spec.SchemaProps{ Description: "userDefined set the deployment mode for user-defined monitoring in addition to the default platform monitoring. userDefined is optional. When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The current default value is `Disabled`.", diff --git a/openapi/openapi.json b/openapi/openapi.json index d94f372b2ee..a58258d47f4 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -13110,6 +13110,14 @@ "default": {}, "$ref": "#/definitions/com.github.openshift.api.config.v1alpha1.AlertmanagerConfig" }, + "configurationSource": { + "description": "configurationSource is an optional field that selects whether the Cluster Monitoring Operator reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. Valid values are \"ConfigMap\" and \"CRD\". When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the openshift-monitoring namespace as the configuration source. When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The current default value is CRD.\n\nPossible enum values:\n - `\"CRD\"` means the operator reads configuration from this ClusterMonitoring custom resource.\n - `\"ConfigMap\"` means the operator reads configuration from the cluster-monitoring-config ConfigMap in the openshift-monitoring namespace.", + "type": "string", + "enum": [ + "CRD", + "ConfigMap" + ] + }, "kubeStateMetricsConfig": { "description": "kubeStateMetricsConfig is an optional field that can be used to configure the kube-state-metrics agent that runs in the openshift-monitoring namespace. kube-state-metrics generates metrics about the state of Kubernetes objects such as Deployments, Nodes, and Pods. When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time.", "default": {}, diff --git a/payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml b/payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml index bb427426d04..136e8e3511f 100644 --- a/payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml +++ b/payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml @@ -915,6 +915,21 @@ spec: and forbidden otherwise rule: 'self.deploymentMode == ''CustomConfig'' ? has(self.customConfig) : !has(self.customConfig)' + configurationSource: + description: |- + configurationSource is an optional field that selects whether the Cluster Monitoring Operator + reads its configuration from the cluster-monitoring-config ConfigMap or from this ClusterMonitoring CRD. + Valid values are "ConfigMap" and "CRD". + When set to ConfigMap, the operator uses the cluster-monitoring-config ConfigMap in the + openshift-monitoring namespace as the configuration source. + When set to CRD, the operator uses this ClusterMonitoring custom resource as the configuration source. + When omitted, this means no opinion and the platform is left to choose a reasonable default, + which is subject to change over time. + The current default value is CRD. + enum: + - ConfigMap + - CRD + type: string kubeStateMetricsConfig: description: |- kubeStateMetricsConfig is an optional field that can be used to configure the kube-state-metrics From 37cb690cbfaba49311d4cbd5fdd47df49da1adc3 Mon Sep 17 00:00:00 2001 From: Mario Fernandez Date: Mon, 20 Jul 2026 15:42:50 +0200 Subject: [PATCH 2/2] fix lint Signed-off-by: Mario Fernandez --- config/v1alpha1/types_cluster_monitoring.go | 1 - 1 file changed, 1 deletion(-) diff --git a/config/v1alpha1/types_cluster_monitoring.go b/config/v1alpha1/types_cluster_monitoring.go index d2196fda3ad..633e0b07e44 100644 --- a/config/v1alpha1/types_cluster_monitoring.go +++ b/config/v1alpha1/types_cluster_monitoring.go @@ -86,7 +86,6 @@ type ClusterMonitoringSpec struct { // which is subject to change over time. // The current default value is CRD. // +optional - // +kubebuilder:validation:Enum=ConfigMap;CRD ConfigurationSource ConfigurationSource `json:"configurationSource,omitempty"` // userDefined set the deployment mode for user-defined monitoring in addition to the default platform monitoring. // userDefined is optional.