Skip to content

OTA-1817 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

OTA-1817 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 a "specific version" variant when no matching version exists.
  • Chores

    • Added static example data and human-readable example outputs illustrating alert states, preflight checks, and upgrade recommendation reports.

@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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Added multiple static example files (JSON alerts, ClusterVersion YAML, and textual outputs) for both standard and critical upgrade-alert scenarios, and a small test guard in TestExamples to skip the "specific version" variant when no version 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 outputs for a standard recommended-alert scenario: alerts JSON (seven alert objects), a ClusterVersion manifest snapshot, and two textual output examples documenting the 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 outputs for a critical-alert scenario: alerts JSON (five alert objects), a 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 mapped version exists for a given ClusterVersion, preventing that variant from running with an empty mapping.

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.
Stable And Deterministic Test Names ✅ Passed Pull request uses Go's standard testing package with stable, deterministic test names instead of Ginkgo framework, meeting the test naming requirements.
Test Structure And Quality ✅ Passed Test file uses standard Go testing framework with testing.T and table-driven tests, not Ginkgo. Custom check is not applicable to this code pattern. PR changes are appropriate.
Title check ✅ Passed The title 'OTA-1817 Adding unit tests for the extend recommended alerts' clearly describes the main change: adding unit tests for extended recommended alerts functionality.

✏️ 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]$

@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
@JianLi-RH JianLi-RH force-pushed the test_for_extend-update-recommend-precheck-alerts branch from 626e1c5 to f6277e1 Compare March 5, 2026 00:58
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.

🧹 Nitpick comments (1)
pkg/cli/admin/upgrade/recommend/examples_test.go (1)

81-87: Consider checking variant.versions != nil instead of string comparison.

The current fix correctly addresses the bug, but comparing against the literal string "specific version" is fragile—if the variant name changes, this logic silently breaks. A more robust approach is to check whether the variant uses a versions map at all.

♻️ Suggested refactor for robustness
 			var version string
-			if version = variant.versions[cv]; version != "" {
-				variant.outputSuffix = fmt.Sprintf(variant.outputSuffixPattern, version)
-			} else {
-				if variant.name == "specific version" {
+			if variant.versions != nil {
+				if version = variant.versions[cv]; version == "" {
 					continue
 				}
+				variant.outputSuffix = fmt.Sprintf(variant.outputSuffixPattern, version)
 			}

This approach ties the skip logic directly to the presence of a versions map, making the code self-documenting and resilient to variant name changes.

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

In `@pkg/cli/admin/upgrade/recommend/examples_test.go` around lines 81 - 87, The
branch that currently checks variant.name == "specific version" should instead
test whether the variant has a versions map; change the logic around
variant.versions and the assignment to variant.outputSuffix so that you first
check if variant.versions != nil (or len(variant.versions) == 0) and if it is
nil/empty then continue, otherwise look up version := variant.versions[cv] and,
if non-empty, set variant.outputSuffix =
fmt.Sprintf(variant.outputSuffixPattern, version); this removes the fragile
string comparison and ties behavior to the presence of the versions map on the
variant struct.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/cli/admin/upgrade/recommend/examples_test.go`:
- Around line 81-87: The branch that currently checks variant.name == "specific
version" should instead test whether the variant has a versions map; change the
logic around variant.versions and the assignment to variant.outputSuffix so that
you first check if variant.versions != nil (or len(variant.versions) == 0) and
if it is nil/empty then continue, otherwise look up version :=
variant.versions[cv] and, if non-empty, set variant.outputSuffix =
fmt.Sprintf(variant.outputSuffixPattern, version); this removes the fragile
string comparison and ties behavior to the presence of the versions map on the
variant struct.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: b5b07e20-35d1-49c7-be70-ca5143a1d700

📥 Commits

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

📒 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 (4)
  • 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-alert-alerts.json
  • 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-alert.show-outdated-releases-output

@JianLi-RH
Copy link
Author

/test security

@JianLi-RH JianLi-RH changed the title [WIP] Adding unit tests for the extend recommended alerts Adding unit tests for the extend recommended alerts Mar 9, 2026
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 9, 2026
@JianLi-RH JianLi-RH changed the title Adding unit tests for the extend recommended alerts [WIP] OTA-1817 Adding unit tests for the extend recommended alerts Mar 10, 2026
@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 Mar 10, 2026
@JianLi-RH JianLi-RH force-pushed the test_for_extend-update-recommend-precheck-alerts branch from f6277e1 to edb8d85 Compare March 11, 2026 08:02
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.

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

25-39: Use a scenario-specific name for the synthetic custom alert.

TestAlert works, but a name like CustomPrecheckAlert would make the fixture and any golden-output diffs more self-explanatory when this case fails.

🤖 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 25 - 39, Replace the generic synthetic alert name by changing the
JSON key "alertname" value currently set to "TestAlert" to a scenario-specific
name like "CustomPrecheckAlert" so the fixture and golden-output diffs are
self-explanatory; locate the object containing the "alertname" key (alongside
keys "openShiftUpdatePrecheck", "reason", "severity") and update its value
accordingly.
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml (1)

4-10: Trim volatile runtime metadata from this example fixture.

creationTimestamp, resourceVersion, uid, clusterID, the transition timestamps, and versionHash all look incidental to the recommend-alert behavior under test. Keeping only the fields the parser actually reads will make future fixture refreshes much smaller and easier to review.

Also applies to: 57-100

🤖 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-critical-alert-cv.yaml`
around lines 4 - 10, Remove volatile runtime metadata from the example YAML:
delete top-level keys creationTimestamp, resourceVersion, uid, and any
incidental spec.clusterID, transition timestamps, and versionHash so the fixture
only contains the fields the recommend-alert parser actually reads (keep the
minimal spec and version fields used by the test). Locate these keys in the
top-level metadata/spec blocks (creationTimestamp, resourceVersion, uid,
clusterID, versionHash, and any "transition" timestamp fields) and strip them
out across the example (also apply the same pruning to the other similar
examples mentioned).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json`:
- Around line 25-39: Replace the generic synthetic alert name by changing the
JSON key "alertname" value currently set to "TestAlert" to a scenario-specific
name like "CustomPrecheckAlert" so the fixture and golden-output diffs are
self-explanatory; locate the object containing the "alertname" key (alongside
keys "openShiftUpdatePrecheck", "reason", "severity") and update its value
accordingly.

In
`@pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml`:
- Around line 4-10: Remove volatile runtime metadata from the example YAML:
delete top-level keys creationTimestamp, resourceVersion, uid, and any
incidental spec.clusterID, transition timestamps, and versionHash so the fixture
only contains the fields the recommend-alert parser actually reads (keep the
minimal spec and version fields used by the test). Locate these keys in the
top-level metadata/spec blocks (creationTimestamp, resourceVersion, uid,
clusterID, versionHash, and any "transition" timestamp fields) and strip them
out across the example (also apply the same pruning to the other similar
examples mentioned).

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: 163e81a4-b78c-4ea9-967b-ca9bc3c15485

📥 Commits

Reviewing files that changed from the base of the PR and between f6277e1 and edb8d85.

📒 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 (2)
  • 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.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.show-outdated-releases-output
  • pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert.output

@JianLi-RH JianLi-RH force-pushed the test_for_extend-update-recommend-precheck-alerts branch from edb8d85 to 447a13b Compare March 11, 2026 08:29
@JianLi-RH JianLi-RH changed the title [WIP] OTA-1817 Adding unit tests for the extend recommended alerts OTA-1817 Adding unit tests for the extend recommended alerts Mar 11, 2026
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 11, 2026
pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert:
Add Additional Alerts to the OCP Update Precheck

Component teams want to raise special alerts to the `oc adm upgrade recommend ...`
command for consideration by cluster-admins considering a future cluster update.
And we also give `label-maintainers` the ability to add or remove alerts from
the recommend-precheck by a new label `openShiftUpdatePrecheck`[1]

We can follow below steps to generate these test files:

Launch a cluster by cluster-bot:
  $ launch 4.22 aws

Cluster Bot gives the default (X.509 certificate based) kubeconfig
returned by the installer, but Thanos alert-retrieval requires a
token.  So I created one using the cluster-version operator's
namespace:
  $ TOKEN="$(oc -n openshift-cluster-version create token default)"

And Cluster Bot clusters use self-signed certificate, so I collected
all possible Kube API server and ingress TLS certificates in a file:
  $ oc -n openshift-kube-apiserver get -o json secrets | jq -r '.items[] | select(.type == "kubernetes.io/tls").data["tls.crt"] | @base64d' >ca.crt
  $ oc -n openshift-ingress get -o json secrets | jq -r '.items[] | select(.type == "kubernetes.io/tls").data["tls.crt"] | @base64d' >>ca.crt

Prepare test data for warning alerts:

$ cat <<EOF | oc -n openshift-cluster-version create -f -
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: warning-testing
  namespace: openshift-cluster-version
  annotations:
    kubernetes.io/description: Alerting rules for testing.
spec:
  groups:
  - name: VirtWarningPrecheck
    rules:
    - alert: VirtHandlerDaemonSetRolloutFailing
      annotations:
        summary: Test summary.
        description: Test description.
      expr: |
        up{job="cluster-version-operator"} == 1
      labels:
        severity: warning
        namespace: openshift-cluster-version
        reason: UpdatingPrometheusFailed
        openShiftUpdatePrecheck: "true"
  - name: VMCannotBeEvictedWarningNormal
    rules:
    - alert: VMCannotBeEvicted
      annotations:
        summary: Test summary.
        description: Test description.
      expr: |
        up{job="cluster-version-operator"} == 1
      labels:
        severity: warning
        namespace: openshift-cluster-version
        reason: UpdatingPrometheusFailed
        openShiftUpdatePrecheck: "false"
  - name: CustomWarningPrecheck
    rules:
    - alert: TestAlert
      annotations:
        summary: Test summary.
        description: Test description.
      expr: |
        up{job="cluster-version-operator"} == 1
      labels:
        severity: warning
        namespace: openshift-cluster-version
        reason: UpdatingPrometheusFailed
        openShiftUpdatePrecheck: "true"
EOF

retrieved ClusterVersion YAML with:
  $ oc get -o yaml clusterversion version >pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-cv.yaml

retrieve the cluster's alerts:
  $ OC_ENABLE_CMD_INSPECT_ALERTS=true oc adm inspect-alerts --token "${TOKEN}" --certificate-authority ca.crt | jq . > pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-alert-alerts.json

then I generated the output fixtures with:
  $ UPDATE=yes go test -v ./pkg/cli/admin/upgrade/recommend/...

delete above alerts:
  $ oc delete PrometheusRule/warning-testing -n openshift-cluster-version

Wait some minutes, then repeat above step to generate new test data for critical alearts:
Create critical alerts:

cat <<EOF | oc -n openshift-cluster-version create -f -
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: critical-testing
  namespace: openshift-cluster-version
  annotations:
    kubernetes.io/description: Alerting rules for testing.
spec:
  groups:
  - name: VirtCriticalPrecheck
    rules:
    - alert: VirtHandlerDaemonSetRolloutFailing
      annotations:
        summary: Test summary.
        description: Test description.
      expr: |
        up{job="cluster-version-operator"} == 1
      labels:
        severity: critical
        namespace: openshift-cluster-version
        reason: UpdatingPrometheusFailed
        openShiftUpdatePrecheck: "true"
  - name: VMCannotBeEvictedCriticalPrecheck
    rules:
    - alert: VMCannotBeEvicted
      for: 1h
      annotations:
        summary: Test summary.
        description: Test description.
      expr: |
        up{job="cluster-version-operator"} == 1
      labels:
        severity: critical
        namespace: openshift-cluster-version
        reason: UpdatingPrometheusFailed
        openShiftUpdatePrecheck: "true"
EOF

Generate test data:
  $ oc get -o yaml clusterversion version >pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-cv.yaml
  $ OC_ENABLE_CMD_INSPECT_ALERTS=true oc adm inspect-alerts --token "${TOKEN}" --certificate-authority ca.crt | jq . >pkg/cli/admin/upgrade/recommend/examples/4.22.0-extend-recommended-critical-alert-alerts.json
  $ UPDATE=yes go test -v ./pkg/cli/admin/upgrade/recommend/...

Then delate critical alerts:
  $ oc delete PrometheusRule/critical-testing -n openshift-cluster-version

[1]: https://issues.redhat.com/browse/OTA-1864
@JianLi-RH JianLi-RH force-pushed the test_for_extend-update-recommend-precheck-alerts branch from 447a13b to 030a4e7 Compare March 11, 2026 09:38
@JianLi-RH
Copy link
Author

/test e2e-aws-ovn-serial-1of2

@JianLi-RH
Copy link
Author

/test e2e-aws-ovn-serial-1of2

@JianLi-RH
Copy link
Author

@wking could you please help review it? thanks

@JianLi-RH
Copy link
Author

/test e2e-aws-ovn-serial-1of2

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

@JianLi-RH: 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant