Skip to content

[WIP] Adding unit tests for the extend recommended alerts#2213

Open
JianLi-RH wants to merge 1 commit intoopenshift:mainfrom
JianLi-RH:test_for_extend-update-recommend-precheck-alerts
Open

[WIP] Adding unit tests for the extend recommended alerts#2213
JianLi-RH wants to merge 1 commit intoopenshift:mainfrom
JianLi-RH:test_for_extend-update-recommend-precheck-alerts

Conversation

@JianLi-RH
Copy link

@JianLi-RH JianLi-RH commented Feb 28, 2026

This is the follow up to #2210

This is the JIRA card: https://issues.redhat.com/browse/OTA-1817

In this PR I added two test file:

  1. 4.22.0-extend-recommended-alert-cv.yaml
    This file covers:
  • VirtHandlerDaemonSetRolloutFailing + warning + precheck + firing
  • VMCannotBeEvicted + warning + not precheck + firing
  • Custom alert + warning + precheck + firing
  1. 4.22.0-extend-recommended-critical-alert-cv.yaml
    This file covers:
  • VirtHandlerDaemonSetRolloutFailing + critical + precheck + firing
  • VMCannotBeEvicted + critical + precheck + pending

These tests do not need specific version, so I updated examples_test.go then these cases will be skipped when the test files do not exist in variant versions.

Summary by CodeRabbit

  • Tests

    • Added example scenarios covering extended and critical upgrade alerts and cluster-version snapshots.
    • Improved test handling to skip the "specific version" variant when no mapped version exists.
  • Chores

    • Added static example outputs and cluster-version manifest examples illustrating alert states and upgrade recommendations.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 28, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 261f317 and 626e1c5.

📒 Files selected for processing (9)
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-alerts.json
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json

Walkthrough

Added multiple example data files (JSON, YAML, and text outputs) for upgrade recommendation scenarios—both standard and critical alert cases—and a small test guard to skip a "specific version" variant when no ClusterVersion mapping exists.

Changes

Cohort / File(s) Summary
Extended Recommended Alert Examples
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json, pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-cv.yaml, pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.output, pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output
Added static example payloads and expected outputs for a standard recommended-alert scenario: alerts JSON (three alerts), ClusterVersion manifest snapshot, and two textual output examples documenting upgrade recommendation output.
Extended Recommended Critical Alert Examples
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-alerts.json, pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml, pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.output, pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.show-outdated-releases-output
Added static example payloads and expected outputs for a critical-alert scenario: alerts JSON (two alerts with firing/pending states), ClusterVersion manifest snapshot, and two textual output examples showing a flagged critical alert.
Test Updates
pkg/cli/admin/upgrade/recommend/examples_test.go
Added a guard in TestExamples to skip the "specific version" variant when no version mapping exists for the ClusterVersion, preventing running that variant with an empty value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[WIP] Adding unit tests for the extend recommended alerts' clearly describes the main change of adding test files and configuration examples for extended recommended alerts.
Stable And Deterministic Test Names ✅ Passed Test names use hardcoded variant names and static example filenames with no dynamic content, timestamps, or random identifiers.
Test Structure And Quality ✅ Passed The test code follows all specified quality requirements, maintains single responsibility per test, includes meaningful diagnostic messages in assertions, and all required fixture files are present.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 28, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JianLi-RH
Once this PR has been reviewed and has the lgtm label, please assign wking 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

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: 1

🧹 Nitpick comments (1)
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output (1)

21-21: Verify whitespace consistency in the runbook annotation.

This line has extra leading whitespace (3 spaces) before <alert does not have a runbook_url annotation>, while the same annotation on lines 8 and 13 has no such leading whitespace.

If the actual output includes this extra spacing, the test fixture is correct. However, if this is unintentional, consider normalizing the whitespace for consistency across alerts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output`
at line 21, The test fixture contains an inconsistent leading whitespace for the
annotation "<alert does not have a runbook_url annotation>" (it has three
leading spaces on the shown line while identical annotations earlier do not);
locate that annotation string in the example content and remove the extra
leading spaces so all occurrences are normalized to the same no-leading-space
format to ensure consistency across alerts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cli/admin/upgrade/recommend/examples_test.go`:
- Around line 81-85: The test loop incorrectly assumes variant.versions is
non-nil and indexes it unguarded, causing nil-map variants to always hit the
else branch and skip tests; fix by first checking whether variant.versions !=
nil before reading variant.versions[cv], and only apply the continue/setting of
variant.outputSuffix when the map exists: if variant.versions != nil { if
version = variant.versions[cv]; version != "" { variant.outputSuffix =
fmt.Sprintf(variant.outputSuffixPattern, version) } else { continue } } (leave
behavior unchanged for variants with a nil versions map).

---

Nitpick comments:
In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output`:
- Line 21: The test fixture contains an inconsistent leading whitespace for the
annotation "<alert does not have a runbook_url annotation>" (it has three
leading spaces on the shown line while identical annotations earlier do not);
locate that annotation string in the example content and remove the extra
leading spaces so all occurrences are normalized to the same no-leading-space
format to ensure consistency across alerts.

ℹ️ Review info

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 17103c5 and 0c36357.

📒 Files selected for processing (9)
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-alerts.json
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples_test.go

@JianLi-RH
Copy link
Author

/uncc @ardaguclu @atiratree

@JianLi-RH JianLi-RH force-pushed the test_for_extend-update-recommend-precheck-alerts branch from 0c36357 to 261f317 Compare February 28, 2026 07:38
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: 1

🧹 Nitpick comments (1)
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json (1)

29-33: Consider sanitizing environment-specific identifiers in fixtures.

Line 29 and Line 51 include concrete cluster/node identifiers. Replacing them with clearly synthetic placeholders would make snapshots less brittle and safer to share broadly.

Also applies to: 51-58

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json`
around lines 29 - 33, The fixture contains environment-specific identifiers
(e.g., values for the JSON keys "instance" and "pod" in
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json)
that should be sanitized; replace concrete cluster/node IDs like
"10.130.0.31:8443" and "insights-operator-b8b5f97fc-kl8rr" (and the similar
values around lines 51-58) with clear synthetic placeholders such as
"INSTANCE_PLACEHOLDER" and "POD_PLACEHOLDER" (or similarly named tokens) so
snapshots are stable and shareable, and ensure any other environment-specific
fields (namespace, job, info_link query params containing IDs) are likewise
replaced or parameterized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output`:
- Around line 18-21: The wrapped "Message:" block has inconsistent indentation
(an extra leading space on the third wrapped line); edit the golden output so
that the third line of the wrapped message matches the indentation of the
previous wrapped lines (remove the extra leading space before "it might have
issues..." in the Message block) to normalize formatting and ensure all wrapped
lines under "Message:" align consistently.

---

Nitpick comments:
In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json`:
- Around line 29-33: The fixture contains environment-specific identifiers
(e.g., values for the JSON keys "instance" and "pod" in
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json)
that should be sanitized; replace concrete cluster/node IDs like
"10.130.0.31:8443" and "insights-operator-b8b5f97fc-kl8rr" (and the similar
values around lines 51-58) with clear synthetic placeholders such as
"INSTANCE_PLACEHOLDER" and "POD_PLACEHOLDER" (or similarly named tokens) so
snapshots are stable and shareable, and ensure any other environment-specific
fields (namespace, job, info_link query params containing IDs) are likewise
replaced or parameterized.

ℹ️ Review info

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0c36357 and 261f317.

📒 Files selected for processing (9)
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-alerts.json
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.output
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/cli/admin/upgrade/recommend/examples_test.go
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert.output

Comment on lines +18 to +21
Message: warning alert TestAlert firing, suggesting issues worth investigating before updating the cluster. machine ci-ln-plnvytb-76ef8-42h8v-worker-us-east-1a-84pg2 is in phase: . The alert description is: The machine has been without a Running or Deleting phase for more than 60 minutes.
The machine may not have been provisioned properly from the infrastructure provider, or
it might have issues with CertificateSigningRequests being approved.
<alert does not have a runbook_url annotation>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Normalize wrapped-message indentation in the golden output.

Line 21 has an extra leading space versus Line 19 and Line 20, making this block inconsistently formatted.

Suggested fix
-   <alert does not have a runbook_url annotation>
+  <alert does not have a runbook_url annotation>
📝 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
Message: warning alert TestAlert firing, suggesting issues worth investigating before updating the cluster. machine ci-ln-plnvytb-76ef8-42h8v-worker-us-east-1a-84pg2 is in phase: . The alert description is: The machine has been without a Running or Deleting phase for more than 60 minutes.
The machine may not have been provisioned properly from the infrastructure provider, or
it might have issues with CertificateSigningRequests being approved.
<alert does not have a runbook_url annotation>
Message: warning alert TestAlert firing, suggesting issues worth investigating before updating the cluster. machine ci-ln-plnvytb-76ef8-42h8v-worker-us-east-1a-84pg2 is in phase: . The alert description is: The machine has been without a Running or Deleting phase for more than 60 minutes.
The machine may not have been provisioned properly from the infrastructure provider, or
it might have issues with CertificateSigningRequests being approved.
<alert does not have a runbook_url annotation>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.show-outdated-releases-output`
around lines 18 - 21, The wrapped "Message:" block has inconsistent indentation
(an extra leading space on the third wrapped line); edit the golden output so
that the third line of the wrapped message matches the indentation of the
previous wrapped lines (remove the extra leading space before "it might have
issues..." in the Message block) to normalize formatting and ensure all wrapped
lines under "Message:" align consistently.

@JianLi-RH
Copy link
Author

@wking Could you please help take a look at below tests?

Tested it locally:

[jianl@jianl-thinkpadt14gen4 oc]$ make verify
Running `gofmt -s -l` on 657 file(s).
go vet -mod=vendor ./...
go run ./tools/clicheck
-----+ checking command oc adm build-chain
-----+ checking command oc adm catalog mirror

...

ts generated in _output/verify-generated-completions/bash
Assets generated in _output/verify-generated-completions/zsh
KUBE_GIT_VERSION="v1.34.1" hack/verify-kube-version.sh
[jianl@jianl-thinkpadt14gen4 oc]$ 

Make test:

[jianl@jianl-thinkpadt14gen4 oc]$ make test
go test -mod=vendor -race ./... 
ok      github.com/openshift/oc/cmd/oc  1.628s

...
?       github.com/openshift/oc/pkg/cli/admin/upgrade/channel   [no test files]
ok      github.com/openshift/oc/pkg/cli/admin/upgrade/recommend 1.337s
ok      github.com/openshift/oc/pkg/cli/admin/upgrade/rollback  1.095s
...

?       github.com/openshift/oc/tools/genman    [no test files]
?       github.com/openshift/oc/tools/genman/md2man     [no test files]
FAIL
make: *** [vendor/github.com/openshift/build-machinery-go/make/targets/golang/test-unit.mk:7: test-unit] Error 1
[jianl@jianl-thinkpadt14gen4 oc]$

https://issues.redhat.com/browse/OTA-1811 introduces some new alerts, this PR meand to automate the tests to those alerts.

In this PR I added two test file:

1. 4.22.0-extend-recommended-alert-cv.yaml
This file covers:
- VirtHandlerDaemonSetRolloutFailing + warning + precheck + firing
- VMCannotBeEvicted + warning + not precheck + firing
- Custom alert + warning + precheck + firing

2. 4.22.0-extend-recommended-critical-alert-cv.yaml
This file covers:
- VirtHandlerDaemonSetRolloutFailing + critical + precheck + firing
- VMCannotBeEvicted + critical + precheck + pending
@JianLi-RH JianLi-RH force-pushed the test_for_extend-update-recommend-precheck-alerts branch from 261f317 to 626e1c5 Compare February 28, 2026 07:55
@JianLi-RH
Copy link
Author

/cc @wking

@openshift-ci openshift-ci bot requested a review from wking February 28, 2026 07:59
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 28, 2026

@JianLi-RH: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/unit 626e1c5 link true /test unit

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

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant