Skip to content

MON-4565: Add enableUserAlertmanagerConfig to ClusterMonitoring API#2855

Open
marioferh wants to merge 2 commits into
openshift:masterfrom
marioferh:alertmanager_enableUserAlertmanagerConfig
Open

MON-4565: Add enableUserAlertmanagerConfig to ClusterMonitoring API#2855
marioferh wants to merge 2 commits into
openshift:masterfrom
marioferh:alertmanager_enableUserAlertmanagerConfig

Conversation

@marioferh
Copy link
Copy Markdown
Contributor

Restore parity with the cluster-monitoring-config ConfigMap field that was removed from AlertmanagerConfig during API review (#2148). When true, the platform Alertmanager in openshift-monitoring discovers AlertmanagerConfig resources in user-defined namespaces; this only applies when user-workload Alertmanager is not enabled. Omitted means false, matching the ConfigMap default.

Includes CRD/OpenAPI codegen and an integration test for the new field.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

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 May 21, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented May 21, 2026

@marioferh: This pull request references MON-4565 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 the "5.0.0" version, but no target version was set.

Details

In response to this:

Restore parity with the cluster-monitoring-config ConfigMap field that was removed from AlertmanagerConfig during API review (#2148). When true, the platform Alertmanager in openshift-monitoring discovers AlertmanagerConfig resources in user-defined namespaces; this only applies when user-workload Alertmanager is not enabled. Omitted means false, matching the ConfigMap default.

Includes CRD/OpenAPI codegen and an integration test for the new field.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 0cbd85a7-d524-4697-8492-e34e612f5cb2

📥 Commits

Reviewing files that changed from the base of the PR and between 5c694c6 and 4d42991.

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

📝 Walkthrough

Walkthrough

This PR adds a UserAlertmanagerConfigSelection enum (Selectable, None) and an optional userAlertmanagerConfigSelection field on AlertmanagerCustomConfig, updates the ClusterMonitoring CRD to include the enum property and documentation, and adds creation tests: one verifying a Selectable value is preserved in generated manifests and one verifying an unsupported value (Enabled) is rejected with the expected validation error.

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title references the main change (adding enableUserAlertmanagerConfig to ClusterMonitoring API) but uses an older field name than what was actually implemented (userAlertmanagerConfigSelection enum instead of enableUserAlertmanagerConfig boolean). Verify whether the implementation intentionally uses userAlertmanagerConfigSelection enum instead of enableUserAlertmanagerConfig, and update the title to reflect the actual implementation approach.
✅ Passed checks (14 passed)
Check name Status Explanation
Description check ✅ Passed The description accurately explains the purpose (restoring parity with cluster-monitoring-config), the behavior, and includes test coverage, and is directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Test names are stable and deterministic. No dynamic values, timestamps, UUIDs, pod names, node names, or IP addresses in test titles.
Test Structure And Quality ✅ Passed PR contains no Ginkgo tests—only YAML-based CRD validation tests. Custom check is for Ginkgo test code quality and is not applicable here.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests were added in this PR. Changes are limited to Go type definitions, CRD schema updates, and declarative YAML validation test cases for the ClusterMonitoring API.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests were added. PR adds CRD/OpenAPI schema validation tests in YAML format and API type definitions, which are not subject to SNO compatibility checks.
Topology-Aware Scheduling Compatibility ✅ Passed PR adds only API configuration field (userAlertmanagerConfigSelection) for Alertmanager discovery behavior; no deployment manifests, Pod specs, or scheduling constraints are introduced.
Ote Binary Stdout Contract ✅ Passed PR only adds API type definitions, CRD schema, and YAML test cases. No process-level code, init functions, or stdout writes detected that would violate OTE Binary Stdout Contract.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed New tests validate Kubernetes API schema with no IPv4 assumptions, hardcoded IPs, external connectivity, or network logic. Compatible with IPv6-only disconnected environments.
No-Weak-Crypto ✅ Passed PR adds Alertmanager config enum type, struct field, tests, and CRD schema with no cryptographic algorithms, custom crypto, or unsafe comparisons.
Container-Privileges ✅ Passed PR contains only API type definitions and CRD schemas with no container workload manifests; no privileged container settings found.
No-Sensitive-Data-In-Logs ✅ Passed PR adds API type definitions, CRD schemas, and test specifications with zero logging statements or code that executes; changes are purely declarative and structural.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.12.2)

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.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 21, 2026

Hello @marioferh! 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 21, 2026
@openshift-ci openshift-ci Bot requested review from JoelSpeed and everettraven May 21, 2026 08:09
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 21, 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

@marioferh marioferh force-pushed the alertmanager_enableUserAlertmanagerConfig branch from cbaa523 to 5c694c6 Compare May 21, 2026 09:05
Restore parity with the cluster-monitoring-config ConfigMap field
enableUserAlertmanagerConfig that was removed from AlertmanagerConfig
during API review (openshift#2148). userAlertmanagerConfigSelection uses Selectable
and None enum values (kube-api-linter nobools) instead of a boolean:
Selectable matches enableUserAlertmanagerConfig: true, None matches false.

The platform Alertmanager in openshift-monitoring discovers
AlertmanagerConfig resources in user-defined namespaces only when set to
Selectable and user-workload Alertmanager is not enabled. Omitted defaults
to None.

Includes CRD/OpenAPI codegen and integration tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml`:
- Around line 21-39: Add a parallel test case for the other enum value by
duplicating the existing test named "Should accept
userAlertmanagerConfigSelection on alertmanagerConfig" and change the
alertmanagerConfig.userAlertmanagerConfigSelection value to "None" in both the
initial and expected YAML blocks; ensure the new test name reflects the change
(e.g., "Should accept userAlertmanagerConfigSelection None value on
alertmanagerConfig") and that the key userAlertmanagerConfigSelection appears
exactly as in the original so the test validates preservation of the "None"
enum.
- Around line 21-50: Add a new test case that verifies alertmanagerConfig can be
created without the optional field userAlertmanagerConfigSelection by adding an
entry named "Should accept alertmanagerConfig without
userAlertmanagerConfigSelection" that provides an initial ClusterMonitoring with
spec.alertmanagerConfig containing only deploymentMode: "DefaultConfig" and
expects the same object back; ensure you reference the alertmanagerConfig object
and the userAlertmanagerConfigSelection symbol so the test confirms omission is
accepted and defaults are handled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: bb30ad99-c017-46cc-b23f-ec272ba53b23

📥 Commits

Reviewing files that changed from the base of the PR and between cbaa523 and 5c694c6.

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

Comment on lines +21 to +39
- name: Should accept userAlertmanagerConfigSelection on alertmanagerConfig
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
userDefined:
mode: "Disabled"
alertmanagerConfig:
deploymentMode: "DefaultConfig"
userAlertmanagerConfigSelection: Selectable
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
userDefined:
mode: "Disabled"
alertmanagerConfig:
deploymentMode: "DefaultConfig"
userAlertmanagerConfigSelection: Selectable
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add test coverage for the "None" enum value.

The validation error on line 50 indicates that userAlertmanagerConfigSelection supports two values: "Selectable" and "None". Currently only "Selectable" is tested for acceptance. Add a similar test case that verifies "None" is also accepted and preserved.

📋 Proposed additional test case
    - name: Should accept userAlertmanagerConfigSelection None value on alertmanagerConfig
      initial: |
        apiVersion: config.openshift.io/v1alpha1
        kind: ClusterMonitoring
        spec:
          userDefined:
            mode: "Disabled"
          alertmanagerConfig:
            deploymentMode: "DefaultConfig"
            userAlertmanagerConfigSelection: None
      expected: |
        apiVersion: config.openshift.io/v1alpha1
        kind: ClusterMonitoring
        spec:
          userDefined:
            mode: "Disabled"
          alertmanagerConfig:
            deploymentMode: "DefaultConfig"
            userAlertmanagerConfigSelection: None
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml`
around lines 21 - 39, Add a parallel test case for the other enum value by
duplicating the existing test named "Should accept
userAlertmanagerConfigSelection on alertmanagerConfig" and change the
alertmanagerConfig.userAlertmanagerConfigSelection value to "None" in both the
initial and expected YAML blocks; ensure the new test name reflects the change
(e.g., "Should accept userAlertmanagerConfigSelection None value on
alertmanagerConfig") and that the key userAlertmanagerConfigSelection appears
exactly as in the original so the test validates preservation of the "None"
enum.

Comment on lines +21 to +50
- name: Should accept userAlertmanagerConfigSelection on alertmanagerConfig
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
userDefined:
mode: "Disabled"
alertmanagerConfig:
deploymentMode: "DefaultConfig"
userAlertmanagerConfigSelection: Selectable
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
userDefined:
mode: "Disabled"
alertmanagerConfig:
deploymentMode: "DefaultConfig"
userAlertmanagerConfigSelection: Selectable
- name: Should reject invalid userAlertmanagerConfigSelection on alertmanagerConfig
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
userDefined:
mode: "Disabled"
alertmanagerConfig:
deploymentMode: "DefaultConfig"
userAlertmanagerConfigSelection: Enabled
expectedError: 'spec.alertmanagerConfig.userAlertmanagerConfigSelection: Unsupported value: "Enabled": supported values: "Selectable", "None"'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add test coverage for optional field behavior.

Per the PR summary and AI-generated description, userAlertmanagerConfigSelection is an optional field. Add a test case that explicitly verifies an alertmanagerConfig object can be created without this field, confirming the optional behavior and default handling.

📋 Proposed additional test case
    - name: Should accept alertmanagerConfig without userAlertmanagerConfigSelection
      initial: |
        apiVersion: config.openshift.io/v1alpha1
        kind: ClusterMonitoring
        spec:
          userDefined:
            mode: "Disabled"
          alertmanagerConfig:
            deploymentMode: "DefaultConfig"
      expected: |
        apiVersion: config.openshift.io/v1alpha1
        kind: ClusterMonitoring
        spec:
          userDefined:
            mode: "Disabled"
          alertmanagerConfig:
            deploymentMode: "DefaultConfig"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml`
around lines 21 - 50, Add a new test case that verifies alertmanagerConfig can
be created without the optional field userAlertmanagerConfigSelection by adding
an entry named "Should accept alertmanagerConfig without
userAlertmanagerConfigSelection" that provides an initial ClusterMonitoring with
spec.alertmanagerConfig containing only deploymentMode: "DefaultConfig" and
expects the same object back; ensure you reference the alertmanagerConfig object
and the userAlertmanagerConfigSelection symbol so the test confirms omission is
accepted and defaults are handled.

// When omitted, the default value is None.
// +optional
// +kubebuilder:validation:Enum=Selectable;None
UserAlertmanagerConfigSelection UserAlertmanagerConfigSelection `json:"userAlertmanagerConfigSelection,omitempty"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should this be moved to AlertmanagerCustomConfig instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems reasonable to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, but not sure if this is the best option as this only applies when deploymentMode is CustomConfig, unlike the ConfigMap where enableUserAlertmanagerConfig: true can be set with otherwise default Alertmanager settings. CMO merge will need to map customConfig.userAlertmanagerConfigSelection: Selectable to the existing internal flag.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the migration, I expect that we always "convert" to CustomConfig deployment.

Comment on lines +801 to +803
// When set to Selectable, the platform Alertmanager discovers AlertmanagerConfig resources
// in user-defined namespaces. This is equivalent to `enableUserAlertmanagerConfig: true` in
// the cluster-monitoring-config ConfigMap.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How are these resources discovered? Is there any additional configuration options we may want to support for how these are discovered?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The (Prometheus) operator discovers all AlertmanagerConfig resources in all namespaces which are not labelled with openshift.io/cluster-monitoring: true (aka user namespaces).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any chance we would like to allow customers to have more fine grained control over what AlertmanagerConfig resources are discovered? For example, specifying label selectors?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think so.

Address API review feedback to colocate user-namespace AlertmanagerConfig
lookup settings with other Alertmanager deployment options in
AlertmanagerCustomConfig. The field is only valid when deploymentMode is
CustomConfig, matching the customConfig union semantics.

Update integration tests and regenerated CRD/OpenAPI artifacts.

Co-authored-by: Cursor <cursoragent@cursor.com>
@marioferh marioferh force-pushed the alertmanager_enableUserAlertmanagerConfig branch from 5c694c6 to 4d42991 Compare May 27, 2026 15:12
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 27, 2026

@marioferh: 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.

// on the platform Alertmanager. This is equivalent to `enableUserAlertmanagerConfig: false`
// in the cluster-monitoring-config ConfigMap.
// This setting only applies when the user-workload monitoring Alertmanager is not enabled.
// When omitted, the default value is None.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this follow the typical "no opinion" pattern?

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants