Skip to content

Add test to validate openshift.io/required-scc annotation for all HCO deployments #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

geetikakay
Copy link
Contributor

@geetikakay geetikakay commented May 30, 2025

Short description:

Refer : kubevirt/hyperconverged-cluster-operator#3284

More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
jira-ticket:

https://issues.redhat.com/browse/CNV-60087

Summary by CodeRabbit

  • Tests
    • Added automated tests to ensure all HyperConverged Operator deployments have the correct security context constraint annotation, improving security compliance and reporting any missing or incorrect annotations.

Copy link

coderabbitai bot commented May 30, 2025

"""

Walkthrough

A new test module was added to verify that all HyperConverged Operator (HCO) deployments have the "openshift.io/required-scc" annotation set to "restricted-v2". The tests use pytest fixtures to collect deployments, check for missing or incorrect annotations, and assert compliance, with traceability via Polarion IDs.

Changes

Files/Paths Change Summary
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py Added pytest fixture and tests to verify presence and correctness of required SCC annotation on HCO deployments

Possibly related issues

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-virtualization-qe-bot-3

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
  • to assign reviewer to PR use /assign-reviewer @<reviewer>

PR will be approved when the following conditions are met:

  • /approve from one of the approvers.
  • Minimum number of required /lgtm (2) is met.
Approvers and Reviewers
  • Approvers:

    • dshchedr
    • myakove
    • rnetser
    • vsibirsk
  • Reviewers:

    • OhadRevah
    • RoniKishner
    • dshchedr
    • hmeir
    • rnetser
    • vsibirsk
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest build-container: Retest build-container
  • /retest all: Retest all
Supported labels
  • hold
  • verified
  • wip
  • lgtm
  • approve

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between abcd461 and f02c4f8.

📒 Files selected for processing (1)
  • tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (2)
utilities/infra.py (1)
  • is_jira_open (854-867)
tests/conftest.py (2)
  • hco_namespace (1027-1029)
  • namespace (648-662)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: build-container
  • GitHub Check: tox
🔇 Additional comments (5)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (5)

1-14: LGTM! Good module structure and clear constants.

The file header, imports, and constant definitions are well-organized. The constants REQUIRED_SCC_ANNOTATION and REQUIRED_SCC_VALUE make the code maintainable and clear.


16-21: LGTM! Well-structured fixture with appropriate scope.

The fixture correctly creates Deployment objects and sorts them for consistent test execution. The module scope is appropriate for this type of resource collection.


45-50: LGTM! Clear test with appropriate assertions.

The test function properly asserts that no deployments are missing the required annotation and provides informative error messages. The Polarion marker ensures proper traceability.


53-58: LGTM! Complementary test with clear validation.

This test correctly validates that deployments with the annotation have the correct value. Together with the previous test, it provides comprehensive coverage of the annotation requirement.


30-31:

✅ Verification successful

Verify the JIRA conditional logic.

The conditional skip logic for VIRT_EXPORTPROXY deployments when JIRA CNV-62807 is open appears correct, but should be verified to ensure VIRT_EXPORTPROXY contains the expected deployment names.


🏁 Script executed:

#!/bin/bash
# Description: Verify the VIRT_EXPORTPROXY constant contains expected deployment names
# Expected: Should find the constant definition and show its value

rg -A 5 "VIRT_EXPORTPROXY.*=" utilities/constants.py

Length of output: 278


VIRT_EXPORTPROXY constant verified

VIRT_EXPORTPROXY is defined as the string "virt-exportproxy", which matches the deployment name checked by dp.name in VIRT_EXPORTPROXY. The skip logic for CNV-62807 therefore behaves as intended.

@geetikakay
Copy link
Contributor Author

/wip

@openshift-virtualization-qe-bot-2 openshift-virtualization-qe-bot-2 changed the title Add test to validate openshift.io/required-scc annotation for all HCO deployments WIP: Add test to validate openshift.io/required-scc annotation for all HCO deployments May 30, 2025
@geetikakay
Copy link
Contributor Author

/wip cancel

@openshift-virtualization-qe-bot-2 openshift-virtualization-qe-bot-2 changed the title WIP: Add test to validate openshift.io/required-scc annotation for all HCO deployments Add test to validate openshift.io/required-scc annotation for all HCO deployments May 30, 2025
@geetikakay
Copy link
Contributor Author

/verified

@openshift-virtualization-qe-bot

D/S test tox -e verify-tc-requirement-polarion failed: cnv-tests-tox-executor/12190

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

♻️ Duplicate comments (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (1)

24-24: ⚠️ Potential issue

Address the unaddressed unsafe attribute access issue.

This line still has the same unsafe chained attribute access issue that was flagged in previous reviews. If any intermediate attribute (spec, template, metadata, or annotations) is None, this will raise an AttributeError.

Apply the previously suggested fix to make the code more robust:

-        scc = dp.instance.spec.template.metadata.annotations.get(REQUIRED_SCC_ANNOTATION)
+        try:
+            annotations = dp.instance.spec.template.metadata.annotations or {}
+            scc = annotations.get(REQUIRED_SCC_ANNOTATION)
+        except AttributeError:
+            # If any intermediate attribute is missing, treat as missing annotation
+            missing_required_scc_annotation.append(dp.name)
+            continue
🧹 Nitpick comments (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (1)

15-16: Add docstrings to address static analysis warnings.

Consider adding docstrings to the fixture and test functions to improve code documentation and address pylint warnings.

 @pytest.fixture(scope="module")
 def required_scc_deployment_check(admin_client, hco_namespace):
+    """
+    Fixture to check SCC annotations on CNV deployments.
+    
+    Returns:
+        dict: Contains lists of deployments missing or having incorrect SCC annotations.
+    """
     missing_required_scc_annotation = []

 @pytest.mark.polarion("CNV-11964")
 def test_deployments_missing_required_scc_annotation(required_scc_deployment_check):
+    """Test that all CNV deployments have the required SCC annotation."""
     assert not required_scc_deployment_check["missing_required_scc_annotation"], (

 @pytest.mark.polarion("CNV-11965")
 def test_deployments_with_incorrect_required_scc(required_scc_deployment_check):
+    """Test that all CNV deployments have the correct SCC annotation value."""
     assert not required_scc_deployment_check["incorrect_required_scc_annotation_value"], (

Also applies to: 38-38, 46-46

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 16-16: Missing function or method docstring

(C0116)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f96fcc3 and 00ab55d.

📒 Files selected for processing (1)
  • tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (2)
tests/conftest.py (3)
  • admin_client (303-307)
  • hco_namespace (1029-1031)
  • namespace (650-664)
tests/network/user_defined_network/test_user_defined_network.py (1)
  • client (89-98)
🪛 Pylint (3.3.7)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py

[error] 7-7: Unable to import 'ocp_resources.deployment'

(E0401)


[convention] 16-16: Missing function or method docstring

(C0116)


[convention] 38-38: Missing function or method docstring

(C0116)


[warning] 38-38: Redefining name 'required_scc_deployment_check' from outer scope (line 16)

(W0621)


[convention] 46-46: Missing function or method docstring

(C0116)


[warning] 46-46: Redefining name 'required_scc_deployment_check' from outer scope (line 16)

(W0621)

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: tox
  • GitHub Check: build-container
  • GitHub Check: can-be-merged
🔇 Additional comments (2)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (2)

26-29: Good fix for the annotation categorization logic.

The logic now correctly separates deployments with missing annotations from those with incorrect values, addressing the previous concern about adding deployments to both lists.


37-42: Well-structured test functions with clear assertions.

The test functions properly use the fixture data and provide clear error messages that will help identify which deployments are non-compliant. The Polarion markers ensure proper test traceability.

Also applies to: 45-50

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 38-38: Missing function or method docstring

(C0116)


[warning] 38-38: Redefining name 'required_scc_deployment_check' from outer scope (line 16)

(W0621)

@rnetser
Copy link
Collaborator

rnetser commented Jun 5, 2025

/approve

@RoniKishner
Copy link
Contributor

/lgtm

@rnetser rnetser dismissed their stale review June 9, 2025 08:37

updated

@rnetser rnetser merged commit daca909 into RedHatQE:main Jun 9, 2025
8 checks passed
@openshift-virtualization-qe-bot-2

New container for quay.io/openshift-cnv/openshift-virtualization-tests:latest published

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

Successfully merging this pull request may close these issues.

8 participants