Skip to content

Conversation

@jiajliu
Copy link

@jiajliu jiajliu commented Dec 23, 2025

This PR refactors test case OCP-46922 with client-go and migrated it from the openshift-tests-private repository to the CVO repository as an openshift-tests-extension test.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Dec 23, 2025
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Dec 23, 2025

@jiajliu: This pull request references OTA-1604 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 task to target the "4.22.0" version, but no target version was set.

Details

In response to this:

/uncc

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

coderabbitai bot commented Dec 23, 2025

Walkthrough

Adds a duplicate test entry to the cluster-version-operator payload JSON and implements a Go test that initializes a Kubernetes client (KUBECONFIG/in-cluster), then verifies the CVO namespace run-level label, asserts exactly one running CVO pod, and checks the pod SCC annotation.

Changes

Cohort / File(s) Summary
Test Configuration
​.openshift-tests-extension/openshift_payload_cluster-version-operator.json
Appends a second test object named "[Jira:\"Cluster Version Operator\"] cluster-version-operator-tests with cluster access should have correct runlevel and scc" with identical labels, resources.isolation, source, lifecycle, and environmentSelector as the existing entry.
Test Implementation
test/cvo/cvo.go
Adds Kubernetes client imports and setup (context, metav1, client-go/rest, clientcmd), introduces restCfg and kubeClient with a BeforeEach creating the client from KUBECONFIG or in-cluster config, and adds a "with cluster access" test that skips if the CVO deployment is missing, checks openshift.io/run-level on the CVO namespace is empty, lists running CVO pods (by label/phase), asserts exactly one pod, and verifies pod annotation openshift.io/scc equals hostaccess.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

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

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 56162c0 and ba5e305.

📒 Files selected for processing (2)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
  • test/cvo/cvo.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • test/cvo/cvo.go
🔇 Additional comments (3)
test/cvo/cvo.go (3)

4-10: LGTM!

The Kubernetes client-go imports are appropriate for the new cluster access functionality.


28-39: LGTM!

The BeforeEach setup properly initializes the Kubernetes client using the standard client-go configuration loading rules, which respects KUBECONFIG and falls back to in-cluster configuration when appropriate.


43-71: The hard-coded SCC value "hostaccess" is correct.

The test assertion is validated by the official CVO deployment manifest at pkg/payload/testdata/TestRenderManifest_expected_cvo_deployment.yaml, which explicitly declares openshift.io/required-scc: hostaccess in the pod template. The test correctly verifies that the applied SCC annotation matches this requirement. No other SCC values are referenced for CVO pods in the codebase.


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

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Dec 23, 2025

@jiajliu: This pull request references OTA-1604 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 task to target the "4.22.0" version, but no target version was set.

Details

In response to this:

/uncc

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 Dec 23, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

1 similar comment
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 23, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

🧹 Nitpick comments (2)
test/cvo/cvo.go (2)

16-16: Consider removing or relocating GinkgoRecover.

The defer GinkgoRecover() at the Describe block level executes during test registration, not during test execution. It would only catch panics during the registration phase. Ginkgo v2 already handles panics in test specs automatically, making this defer unnecessary. If you need to recover from panics in spawned goroutines within tests, move GinkgoRecover() into those goroutines instead.

🔎 Proposed change
 var _ = Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests`, func() {
-	defer GinkgoRecover()
-
 	const cvoNamespace = "openshift-cluster-version"

24-40: Consider using consistent error handling.

The BeforeEach block mixes two error handling styles: Fail() at line 35 and Expect().NotTo(HaveOccurred()) at line 39. For consistency and better integration with Ginkgo/Gomega patterns, consider using Expect().NotTo(HaveOccurred()) throughout.

🔎 Proposed change for consistency
 		restCfg, err = rest.InClusterConfig()
 		if err != nil {
 			// Fall back to kubeconfig (respects KUBECONFIG env var for local execution)
 			loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
 			cfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
 			restCfg, err = cfg.ClientConfig()
-			if err != nil {
-				Fail("Failed to load Kubernetes configuration. Please ensure KUBECONFIG environment variable is set or running in-cluster.")
-			}
+			Expect(err).NotTo(HaveOccurred(), "Failed to load Kubernetes configuration. Please ensure KUBECONFIG environment variable is set or running in-cluster.")
 		}
 		kubeClient, err = kubernetes.NewForConfig(restCfg)
 		Expect(err).NotTo(HaveOccurred(), "Failed to create Kubernetes client")
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 381275d and df298e2.

📒 Files selected for processing (2)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
  • test/cvo/cvo.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • test/cvo/cvo.go
🔇 Additional comments (3)
test/cvo/cvo.go (3)

4-9: LGTM! Appropriate imports for Kubernetes client setup.

The added imports correctly support the test's requirements: context for test lifecycle, k8s.io client libraries for cluster interaction, and clientcmd for kubeconfig fallback.


18-22: LGTM! Well-structured test setup variables.

The constant for the CVO namespace and variables for the REST config and Kubernetes client are appropriately scoped and typed.


48-69: LGTM! Well-structured test with clear validation logic.

The test correctly validates:

  • CVO namespace has no explicit run-level label (empty string = default early-start priority)
  • Exactly one running CVO pod exists with the expected label
  • CVO pod uses the "hostaccess" SCC for necessary host-level privileges

The use of By() statements, descriptive assertions, and reference comments to the migration source all contribute to maintainability.

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

🧹 Nitpick comments (1)
test/cvo/cvo.go (1)

22-33: Consider using BeforeAll for efficiency.

The BeforeEach creates a new Kubernetes client before every test, including the trivial "should support passing tests" which doesn't need one. Since the client configuration doesn't change between tests, consider using Ginkgo's BeforeAll (or wrapping the client-dependent test in its own Context with a dedicated BeforeEach).

This is a minor efficiency concern given the small number of tests.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 160d2ac and 221cf46.

📒 Files selected for processing (2)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
  • test/cvo/cvo.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • test/cvo/cvo.go
🔇 Additional comments (1)
test/cvo/cvo.go (1)

41-62: LGTM!

The migrated test logic is correct:

  • Properly retrieves the namespace and checks the openshift.io/run-level label (empty string check works correctly even if label is absent, since Go maps return zero value).
  • Pod listing with label and field selectors is appropriate.
  • Single pod assertion and SCC annotation check are well-structured.

The migration preserves the original test intent while using idiomatic client-go patterns.

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

🧹 Nitpick comments (1)
test/cvo/cvo.go (1)

46-49: Consider distinguishing "not found" from other errors for clearer debugging.

If a network or API error occurs (not just NotFound), the skip message "CVO deployment not found!" may be misleading. For better debuggability in CI logs, consider checking specifically for NotFound errors:

🔎 Suggested improvement
+	"k8s.io/apimachinery/pkg/api/errors"
 		cvoDeployment, err := kubeClient.AppsV1().Deployments(cvoNamespace).Get(ctx, "cluster-version-operator", metav1.GetOptions{})
-		if err != nil || cvoDeployment == nil {
+		if errors.IsNotFound(err) {
 			Skip("Skipping test: CVO deployment not found!")
 		}
+		Expect(err).NotTo(HaveOccurred(), "Failed to get CVO deployment")
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 221cf46 and 56162c0.

📒 Files selected for processing (2)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
  • test/cvo/cvo.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • .openshift-tests-extension/openshift_payload_cluster-version-operator.json
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • test/cvo/cvo.go
🔇 Additional comments (3)
test/cvo/cvo.go (3)

4-10: LGTM!

The imports are appropriate for the Kubernetes client-go operations being performed.


27-38: LGTM!

The Kubernetes client setup follows idiomatic patterns for client-go. Using NewDefaultClientConfigLoadingRules correctly respects the KUBECONFIG environment variable, and error messages are descriptive.


51-68: LGTM!

The test assertions are well-structured with clear By() statements for documentation. The runlevel and SCC verification logic is correct, and error messages are descriptive for debugging test failures.

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Dec 24, 2025

@jiajliu: This pull request references OTA-1604 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 task to target the "4.22.0" version, but no target version was set.

Details

In response to this:

This PR refactors test case OCP-46922 with client-go and migrated it from the openshift-tests-private repository to the CVO repository as an openshift-tests-extension test.

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 Dec 24, 2025

@jiajliu: 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/okd-scos-images ba5e305 link true /test okd-scos-images

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.

@jiajliu
Copy link
Author

jiajliu commented Dec 24, 2025

Local test result:

$ ./_output/linux/amd64/cluster-version-operator-tests run-test -n "[Jira:\"Cluster Version Operator\"] cluster-version-operator-tests with cluster access should have correct runlevel and scc"
  Running Suite:  - /home/jiajliu/work/cluster-version-operator
  =============================================================
  Random Seed: 1766564711 - will randomize all specs

  Will run 1 of 1 specs
  ------------------------------
  [Jira:"Cluster Version Operator"] cluster-version-operator-tests with cluster access should have correct runlevel and scc
  /home/jiajliu/work/cluster-version-operator/test/cvo/cvo.go:43
    STEP: Check runlevel in cvo namespace. @ 12/24/25 16:25:12.376
    STEP: Check scc of cvo pod. @ 12/24/25 16:25:12.624
  • [1.507 seconds]
  ------------------------------

  Ran 1 of 1 Specs in 1.507 seconds
  SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
[
  {
    "name": "[Jira:\"Cluster Version Operator\"] cluster-version-operator-tests with cluster access should have correct runlevel and scc",
    "lifecycle": "blocking",
    "duration": 1507,
    "startTime": "2025-12-24 08:25:11.425672 UTC",
    "endTime": "2025-12-24 08:25:12.932730 UTC",
    "result": "passed",
    "output": "  STEP: Check runlevel in cvo namespace. @ 12/24/25 16:25:12.376\n  STEP: Check scc of cvo pod. @ 12/24/25 16:25:12.624\n"
  }
]

From pre-submits jobs e2e-aws-ovn-techpreview and e2e-agnostic-ovn, the new case [Jira:"Cluster Version Operator"] cluster-version-operator-tests with cluster access should have correct runlevel and scc has been added and passed in the CI.

cc @hongkailiu @DavidHurta to help review, thanks

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants