Skip to content

✨OPRUN-3873: Add e2e tests for NetworkPolicies #2013

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anik120
Copy link
Contributor

@anik120 anik120 commented Jun 5, 2025

Description

This PR introduces a new e2e test to continuously validate the NetworkPolicy objects for the catalogd and operator-controller components.

The new test, TestNetworkPolicyJustifications, achieves the following:

  • Documents NetworkPolicies deployed: A registry of all allowed network policies (allowedNetworkPolicies) is defined using the RFC: OLMv1 Static Network Policies. Every rule within these policies is explicitly registered in the registry with a clear, written justification of a minimum length. This ensures that every rule's purpose is documented and understood.

  • Prevents Regressions: The test validates that the NetworkPolicy objects deployed in the cluster exactly match the definitions in a registry (allowedNetworkPolicies). This prevents undocumented or accidental changes to our network rules.

  • Improves Security Posture: Enforces thoughtful consideration for any change to existing network rules, improving overall security posture. Also ensures that other, unrelated network policies won't inadvertently break existing functionalities.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@anik120 anik120 requested a review from a team as a code owner June 5, 2025 14:56
Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit ecc156b
🔍 Latest deploy log https://app.netlify.com/projects/olmv1/deploys/684be15d0f2c8f0008e7ddb6
😎 Deploy Preview https://deploy-preview-2013--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

openshift-ci bot commented Jun 5, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign perdasilva for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

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

@anik120
Copy link
Contributor Author

anik120 commented Jun 5, 2025

@joelanford incorporated your suggestions..also fyi had to change the struct definitions a bit because I realized the policies are defined as a single ingress/egress policy with multiple ports, instead of multiple ingress/egress policies, for each NetworkPolicy object. PTAL, thanks!

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.80%. Comparing base (efc6657) to head (ecc156b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2013      +/-   ##
==========================================
+ Coverage   73.78%   73.80%   +0.01%     
==========================================
  Files          80       80              
  Lines        7146     7146              
==========================================
+ Hits         5273     5274       +1     
+ Misses       1550     1549       -1     
  Partials      323      323              
Flag Coverage Δ
e2e 44.14% <ø> (ø)
unit 60.18% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anik120 anik120 force-pushed the np-tests branch 2 times, most recently from 5496cd9 to ec22c0a Compare June 6, 2025 15:48
@anik120 anik120 force-pushed the np-tests branch 2 times, most recently from 7506ef0 to b61ee05 Compare June 10, 2025 19:12
@anik120
Copy link
Contributor Author

anik120 commented Jun 11, 2025

@joelanford @perdasilva regarding the discussion about possibly switching this to a unit test, I see the Quickstart target in the Makefile, and ack the discussion about using steps from that target (separated out) to generate the manifests and before starting the unit tests, and then consuming the generated manifests from the unit test.

I don't see a natural home for the unit test though. Maybe that's actually a good signal that this should be a e2e test instead.

Thoughts?

@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Jun 12, 2025

Hi @anik120

I see that you asked for their input here as well; #2013 (comment), so we can wait for their thoughts

However, IHMO:

  • Yes, it would be better to do the tests by checking the YAML files directly, as discussed yesterday
  • However, IMHO:

Yes — it would indeed be better to write the tests by checking the YAML files directly, as we discussed yesterday. That said, the current implementation is already acceptable. Also, considering our earlier conversation, we’ll likely have the YAML merged in the repo in the future, so an update would be necessary at that point anyway if we want to move toward the ideal approach.

So, IHMO: it’s really up to you. If you’re able to make the change now, that would be great 🥇 — but if not, I think this PR still accomplishes its goal effectively. From my side, LGTM.

@anik120
Copy link
Contributor Author

anik120 commented Jun 12, 2025

@camilamacedo86 PR #2025 gives me the manifests locally that I can consume and write the test with.

However the question of "which package is a natural home for that test, and if we cannot think of a natural home package for that test is that a strong signal that this is better suited as an e2e test", still remains.

Maybe we wait a little to see if anyone has a better idea, if not I'm happy with this PR and we can merge it in 👍🏽

@tmshort
Copy link
Contributor

tmshort commented Jun 12, 2025

Make sure you rebase...

@perdasilva
Copy link
Contributor

@anik120 I've pushed up a rebase to try and get this down if its green =D

@perdasilva
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 13, 2025
@perdasilva
Copy link
Contributor

@anik120 I'll wait to approve until you give the final go ahead. I don't know if you want to make some changes still...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants