Skip to content

MON-4037: Add MonitoringPluginConfig to ClusterMonitoring API#2768

Open
danielmellado wants to merge 1 commit intoopenshift:masterfrom
danielmellado:mon_4037_monitoring_plugin_config
Open

MON-4037: Add MonitoringPluginConfig to ClusterMonitoring API#2768
danielmellado wants to merge 1 commit intoopenshift:masterfrom
danielmellado:mon_4037_monitoring_plugin_config

Conversation

@danielmellado
Copy link
Contributor

No description provided.

@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 17, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 17, 2026

@danielmellado: This pull request references MON-4037 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target either version "4.22." or "openshift-4.22.", but it targets "openshift-5.0" instead.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 17, 2026

Hello @danielmellado! Some important instructions when contributing to openshift/api:
API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

@openshift-ci openshift-ci bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 17, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 17, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign joelspeed for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

Adds a new MonitoringPluginConfig type and a monitoringPluginConfig field to ClusterMonitoring v1alpha1. The type includes nodeSelector, resources, tolerations, and topologySpreadConstraints with validation (e.g., MinProperties, per-field limits and cross-field checks). Generated deepcopy and Swagger docs were updated, the CRD schema now exposes the new field, and new onCreate tests covering accepted and rejected configurations were added.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

Error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented
The command is terminated due to an error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@config/v1alpha1/types_cluster_monitoring.go`:
- Around line 243-247: The Resources slice on the monitoring plugin config
currently only enforces MaxItems=10 (defined as the Resources
[]ContainerResource field) which allows an empty list; add a kubebuilder
validation tag to require at least one entry by adding
+kubebuilder:validation:MinItems=1 to the Resources field declaration so
monitoringPluginConfig.resources cannot be an empty array (update the Resources
[]ContainerResource json:"resources,omitempty,omitzero" field in
types_cluster_monitoring.go).

In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml`:
- Around line 1293-1294: The CRD currently allows an empty array for the
"resources" property even though the object requires non-empty content; update
the schema for the "resources" array(s) to include minItems: 1 (in addition to
the existing minProperties rule) so that resources: [] is rejected, and apply
the same change to all analogous "resources" schema blocks in this CRD to ensure
at least one item is required when the array is present.
- Around line 1614-1617: The CRD shows topologySpreadConstraints for
MonitoringPluginConfig using atomic list semantics; change the source markers
for MonitoringPluginConfig.TopologySpreadConstraints to use map-list semantics
by adding the kubebuilder markers +listType=map and two +listMapKey entries
(+listMapKey=topologyKey and +listMapKey=whenUnsatisfiable) so the generated CRD
replaces x-kubernetes-list-type: atomic with a keyed map list like its sibling
monitoring configs. Locate the MonitoringPluginConfig struct and update the
field tags/markers for TopologySpreadConstraints accordingly, then regenerate
the CRD.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4854f825-5c11-4ca8-bb89-52abfc00b13e

📥 Commits

Reviewing files that changed from the base of the PR and between 5c75e62 and 7590acb.

⛔ Files ignored due to path filters (3)
  • config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings.crd.yaml is excluded by !**/zz_generated.crd-manifests/*
  • config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • openapi/generated_openapi/zz_generated.openapi.go is excluded by !openapi/**
📒 Files selected for processing (5)
  • config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml
  • config/v1alpha1/types_cluster_monitoring.go
  • config/v1alpha1/zz_generated.deepcopy.go
  • config/v1alpha1/zz_generated.swagger_doc_generated.go
  • payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml

Comment on lines +1614 to +1617
maxItems: 10
minItems: 1
type: array
x-kubernetes-list-type: atomic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

crd='payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml'
types_file="$(fd 'types_cluster_monitoring\.go$' | head -n1)"

printf '== Generated topologySpreadConstraints list semantics across the CRD ==\n'
rg -n -C1 'topologySpreadConstraints:|x-kubernetes-list-map-keys:|x-kubernetes-list-type:' "$crd"

printf '\n== Source markers around MonitoringPluginConfig ==\n'
rg -n -C3 'type MonitoringPluginConfig|TopologySpreadConstraints|listType|listMapKey' "$types_file"

Repository: openshift/api

Length of output: 24894


Use map-list semantics for topologySpreadConstraints in MonitoringPluginConfig.

Line 1617 has x-kubernetes-list-type: atomic, while all other topologySpreadConstraints fields in the CRD use keyed map lists with topologyKey and whenUnsatisfiable keys. This inconsistency changes patch/apply behavior for just this field.

Expected fix
                    maxItems: 10
                    minItems: 1
                    type: array
-                    x-kubernetes-list-type: atomic
+                    x-kubernetes-list-map-keys:
+                    - topologyKey
+                    - whenUnsatisfiable
+                    x-kubernetes-list-type: map

Update MonitoringPluginConfig.TopologySpreadConstraints markers in the source to use +listType=map with +listMapKey=topologyKey and +listMapKey=whenUnsatisfiable, matching all sibling monitoring component configs.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
maxItems: 10
minItems: 1
type: array
x-kubernetes-list-type: atomic
maxItems: 10
minItems: 1
type: array
x-kubernetes-list-map-keys:
- topologyKey
- whenUnsatisfiable
x-kubernetes-list-type: map
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml`
around lines 1614 - 1617, The CRD shows topologySpreadConstraints for
MonitoringPluginConfig using atomic list semantics; change the source markers
for MonitoringPluginConfig.TopologySpreadConstraints to use map-list semantics
by adding the kubebuilder markers +listType=map and two +listMapKey entries
(+listMapKey=topologyKey and +listMapKey=whenUnsatisfiable) so the generated CRD
replaces x-kubernetes-list-type: atomic with a keyed map list like its sibling
monitoring configs. Locate the MonitoringPluginConfig struct and update the
field tags/markers for TopologySpreadConstraints accordingly, then regenerate
the CRD.

Signed-off-by: Daniel Mellado <dmellado@fedoraproject.org>
@danielmellado danielmellado force-pushed the mon_4037_monitoring_plugin_config branch from 7590acb to 30b1be2 Compare March 17, 2026 12:24
@danielmellado
Copy link
Contributor Author

@everettraven coming ere from #2753, I addressed your comments, as there was an issue wit GH and the branch and the PR was closed, thanks!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml (1)

1619-1622: ⚠️ Potential issue | 🟠 Major

topologySpreadConstraints still needs map-list semantics.

Line 1622 keeps this list atomic, so the uniqueness promise in Lines 1446-1447 is not enforced and server-side apply behavior diverges from the sibling monitoring configs. Please add +listType=map, +listMapKey=topologyKey, and +listMapKey=whenUnsatisfiable on MonitoringPluginConfig.TopologySpreadConstraints, then regenerate the CRD.

Expected generated shape
                     maxItems: 10
                     minItems: 1
                     type: array
-                    x-kubernetes-list-type: atomic
+                    x-kubernetes-list-map-keys:
+                    - topologyKey
+                    - whenUnsatisfiable
+                    x-kubernetes-list-type: map

Verify that metricsServerConfig.topologySpreadConstraints remains a keyed map list, monitoringPluginConfig.topologySpreadConstraints stops generating as atomic, and the source struct carries the matching kubebuilder markers.

#!/bin/bash
set -euo pipefail

crd='payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml'
types_file="$(fd 'types_cluster_monitoring\.go$' | head -n1)"
test -n "$types_file"

echo '== Generated CRD list semantics: metricsServerConfig vs monitoringPluginConfig =='
python - <<'PY'
from pathlib import Path

lines = Path("payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml").read_text().splitlines()

def show(section, next_section):
    start = next(i for i, l in enumerate(lines) if l.strip() == f"{section}:")
    end = next(i for i, l in enumerate(lines[start + 1:], start + 1) if l.strip() == f"{next_section}:")
    inside = False
    print(f"-- {section} --")
    for i in range(start, end):
        s = lines[i].strip()
        if s == "topologySpreadConstraints:":
            inside = True
        if not inside:
            continue
        if s in {
            "topologySpreadConstraints:",
            "maxItems: 10",
            "minItems: 1",
            "type: array",
            "x-kubernetes-list-map-keys:",
            "- topologyKey",
            "- whenUnsatisfiable",
            "x-kubernetes-list-type: atomic",
            "x-kubernetes-list-type: map",
        }:
            print(f"{i+1}:{lines[i]}")
        if s in {"x-kubernetes-list-type: atomic", "x-kubernetes-list-type: map"}:
            break

show("metricsServerConfig", "monitoringPluginConfig")
show("monitoringPluginConfig", "openShiftStateMetricsConfig")
PY

echo
echo '== Source markers for MonitoringPluginConfig =='
awk '
  /^type MonitoringPluginConfig struct/ {inblock=1}
  inblock {print NR ":" $0}
  inblock && /^}/ {exit}
' "$types_file"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml`
around lines 1619 - 1622, The CRD shows
MonitoringPluginConfig.topologySpreadConstraints as an atomic list; update the
source struct (MonitoringPluginConfig) field TopologySpreadConstraints to carry
the kubebuilder markers +listType=map and two +listMapKey entries
(+listMapKey=topologyKey and +listMapKey=whenUnsatisfiable), then regenerate the
CRD so monitoringPluginConfig.topologySpreadConstraints emits
x-kubernetes-list-type: map and x-kubernetes-list-map-keys matching
metricsServerConfig.topologySpreadConstraints.
🧹 Nitpick comments (1)
config/v1alpha1/types_cluster_monitoring.go (1)

274-277: Change MonitoringPluginConfig.TopologySpreadConstraints to map-style list semantics for API consistency.

MonitoringPluginConfig.TopologySpreadConstraints (lines 274–277) uses +listType=atomic, while all other TopologySpreadConstraints fields in this file (OpenShiftStateMetricsConfig, AlertmanagerConfig, MetricsServerConfig, PrometheusOperatorConfig, PrometheusOperatorAdmissionWebhookConfig, PrometheusConfig) use +listType=map keyed by topologyKey and whenUnsatisfiable. Aligning this field with map semantics would improve consistency across the API surface and provide better duplicate handling based on the naturally identifying fields of TopologySpreadConstraint.

Suggested change
-	// +listType=atomic
+	// +listType=map
+	// +listMapKey=topologyKey
+	// +listMapKey=whenUnsatisfiable
 	// +kubebuilder:validation:MinItems=1
 	// +kubebuilder:validation:MaxItems=10
 	TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@config/v1alpha1/types_cluster_monitoring.go` around lines 274 - 277, Change
the list semantics for MonitoringPluginConfig.TopologySpreadConstraints from
atomic to map to match the other types: replace the existing "+listType=atomic"
annotation with "+listType=map" and add a map key annotation listing the natural
identity fields (e.g. "+listMapKey=topologyKey,whenUnsatisfiable") so duplicates
are detected by those keys; update the comment block above the
TopologySpreadConstraints field in MonitoringPluginConfig to mirror the
annotations used on
OpenShiftStateMetricsConfig/AlertmanagerConfig/MetricsServerConfig/PrometheusOperatorConfig/PrometheusOperatorAdmissionWebhookConfig/PrometheusConfig.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml`:
- Around line 1619-1622: The CRD shows
MonitoringPluginConfig.topologySpreadConstraints as an atomic list; update the
source struct (MonitoringPluginConfig) field TopologySpreadConstraints to carry
the kubebuilder markers +listType=map and two +listMapKey entries
(+listMapKey=topologyKey and +listMapKey=whenUnsatisfiable), then regenerate the
CRD so monitoringPluginConfig.topologySpreadConstraints emits
x-kubernetes-list-type: map and x-kubernetes-list-map-keys matching
metricsServerConfig.topologySpreadConstraints.

---

Nitpick comments:
In `@config/v1alpha1/types_cluster_monitoring.go`:
- Around line 274-277: Change the list semantics for
MonitoringPluginConfig.TopologySpreadConstraints from atomic to map to match the
other types: replace the existing "+listType=atomic" annotation with
"+listType=map" and add a map key annotation listing the natural identity fields
(e.g. "+listMapKey=topologyKey,whenUnsatisfiable") so duplicates are detected by
those keys; update the comment block above the TopologySpreadConstraints field
in MonitoringPluginConfig to mirror the annotations used on
OpenShiftStateMetricsConfig/AlertmanagerConfig/MetricsServerConfig/PrometheusOperatorConfig/PrometheusOperatorAdmissionWebhookConfig/PrometheusConfig.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: d7a946f8-66f3-4667-8902-9c89aca1b367

📥 Commits

Reviewing files that changed from the base of the PR and between 7590acb and 30b1be2.

⛔ Files ignored due to path filters (3)
  • config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings.crd.yaml is excluded by !**/zz_generated.crd-manifests/*
  • config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • openapi/generated_openapi/zz_generated.openapi.go is excluded by !openapi/**
📒 Files selected for processing (5)
  • config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml
  • config/v1alpha1/types_cluster_monitoring.go
  • config/v1alpha1/zz_generated.deepcopy.go
  • config/v1alpha1/zz_generated.swagger_doc_generated.go
  • payload-manifests/crds/0000_10_config-operator_01_clustermonitorings.crd.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml
  • config/v1alpha1/zz_generated.deepcopy.go

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 17, 2026

@danielmellado: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants