Skip to content

Conversation

duanwei33
Copy link

This commit adds comprehensive e2e tests to verify that storage-related operators and controllers have the required network policy labels and that NetworkPolicy resources exist with correct pod selectors.

Changes:

  • Add namespace constants to helpers.go for reuse across storage tests
  • Add storage_networkpolicy.go with tests for CSO and CSI operators
  • Verify required network policy labels on deployments
  • Validate NetworkPolicy resources in storage namespaces

Something on-tracking:

  • The network policy in the hypershift management cluster control-plane namespace should be taken into an overall consideration, see discussion in slack

Test records:

$ ./openshift-tests run all --dry-run | grep -E "OCPFeature:StorageNetworkPolicy" | ./openshift-tests run -f -
passed: (15.5s) 2025-10-09T09:32:06 "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators"
passed: (16.7s) 2025-10-09T09:32:07 "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators"
passed: (17.7s) 2025-10-09T09:32:08 "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels"

@openshift-ci openshift-ci bot requested review from jsafrane and tsmetana October 9, 2025 10:44
Copy link
Contributor

openshift-ci bot commented Oct 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@duanwei33
Copy link
Author

@mpatlasov @dobsonj Could you help take a look?
(cc @Phaow @chao007)

Copy link

openshift-trt bot commented Oct 9, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New Test Risks for sha: 92d160d

Job Name New Test Risk
pull-ci-openshift-origin-main-e2e-aws-ovn-microshift High - "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" is a new test that failed 1 time(s) against the current commit

New tests seen in this PR at sha: 92d160d

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 5, Fail: 1, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]

@duanwei33
Copy link
Author

/test verify

@duanwei33 duanwei33 force-pushed the storage-networkpolicy-e2e branch from 1b1417c to 81e1f58 Compare October 11, 2025 07:16
Copy link

openshift-trt bot commented Oct 11, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New Test Risks for sha: 81e1f58

Job Name New Test Risk
pull-ci-openshift-origin-main-e2e-aws-ovn-microshift High - "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" is a new test that failed 1 time(s) against the current commit

New tests seen in this PR at sha: 81e1f58

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 7, Pass: 6, Fail: 1, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 7, Pass: 7, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 7, Pass: 7, Fail: 0, Flake: 0]

@duanwei33 duanwei33 force-pushed the storage-networkpolicy-e2e branch from a065245 to c1d5777 Compare October 14, 2025 06:39
Copy link

openshift-trt bot commented Oct 14, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New tests seen in this PR at sha: c1d5777

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]

@duanwei33 duanwei33 force-pushed the storage-networkpolicy-e2e branch from c1d5777 to 4580205 Compare October 14, 2025 13:15
Copy link

openshift-trt bot commented Oct 14, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New tests seen in this PR at sha: 4580205

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]

Namespace: CSINamespace,
Name: "aws-ebs-csi-driver-controller",
Platform: "aws",
RequiredLabels: csiControllerRequiredLabels,

Choose a reason for hiding this comment

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

Should we check for openshift.storage.network-policy.all-egress here as well?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. You've highlighted a key nuance here.

Ideally, fine-grained policies like allow-egress-to-api-server would be sufficient to enforce the principle of least privilege. However, the broader allow-all-egress policy exists as a practical measure to ensure functionality in certain configurations, acting as a workaround.
And when a pod has both policies applied, the more specific allow-egress-to-api-server becomes redundant, as its permissions are a subset of allow-all-egress(TCP all vs TCP specific port).

Nevertheless, I agree that adding it is the correct approach to accurately reflect the actual implementation.

g.It("should ensure required NetworkPolicies exist with correct labels", func() {
for _, c := range networkPolicyChecks {
_, err := oc.AdminKubeClient().CoreV1().Namespaces().Get(context.TODO(), c.Namespace, metav1.GetOptions{})
if err != nil {

Choose a reason for hiding this comment

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

Should we check if errors.IsNotFound(err) here and g.Fail() otherwise?

Copy link
Author

Choose a reason for hiding this comment

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

Just to clarify, the openshift-manila-csi-driver namespace is optional; we skip if there is no openshift-manila-csi-driver namespace.

Choose a reason for hiding this comment

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

Yes, I understand. There is another place in the PR where you "Get" a resource:

			deployment, err := oc.AdminKubeClient().AppsV1().Deployments(res.Namespace).Get(context.TODO(), res.Name, metav1.GetOptions{})
			if err != nil {
				if errors.IsNotFound(err) {

The logic there is to allow err!=nil only if it is NotFound, and g.Fail() otherwise. It's not obvious why getting namespace is special and it's OK to silently skip err!=nil (when !errors.IsNotFound(err)) for optional openshift-manila-csi-driver namespace case.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, got it. I think they don't have too many differences :)
I've rebased the branch. PTAL and let me know if it's ready for an lgtm

Choose a reason for hiding this comment

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

My suggestion is to make L301-308 look like this:

			_, err := oc.AdminKubeClient().CoreV1().Namespaces().Get(context.TODO(), c.Namespace, metav1.GetOptions{})
			if err != nil {
				if errors.IsNotFound(err) {
					if c.Optional {
						g.By(fmt.Sprintf("Skipping optional namespace %s (not found)", c.Namespace))
						continue
					}
					o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("namespace %s should exist", c.Namespace))
				}
				g.Fail(fmt.Sprintf("Error fetching namespace %s: %v", c.Namespace, err))
			}

wdyt?

Copy link
Author

Choose a reason for hiding this comment

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

Oh, got your point, yes it looks clearer.
Updated, thanks for the suggestion.

@duanwei33
Copy link
Author

/retest

Copy link

openshift-trt bot commented Oct 16, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New Test Risks for sha: c514831

Job Name New Test Risk
pull-ci-openshift-origin-main-e2e-aws-ovn-fips High - "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" is a new test that was not present in all runs against the current commit.
pull-ci-openshift-origin-main-e2e-aws-ovn-fips High - "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" is a new test that was not present in all runs against the current commit.
pull-ci-openshift-origin-main-e2e-aws-ovn-fips High - "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" is a new test that was not present in all runs against the current commit.

New tests seen in this PR at sha: c514831

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 8, Pass: 8, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 8, Pass: 8, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 8, Pass: 8, Fail: 0, Flake: 0]

@duanwei33 duanwei33 changed the title Add e2e tests for storage network policy STOR-2340: Add e2e tests for storage network policy Oct 16, 2025
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Oct 16, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 16, 2025

@duanwei33: This pull request references STOR-2340 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 epic to target either version "4.21." or "openshift-4.21.", but it targets "openshift-4.20" instead.

In response to this:

This commit adds comprehensive e2e tests to verify that storage-related operators and controllers have the required network policy labels and that NetworkPolicy resources exist with correct pod selectors.

Changes:

  • Add namespace constants to helpers.go for reuse across storage tests
  • Add storage_networkpolicy.go with tests for CSO and CSI operators
  • Verify required network policy labels on deployments
  • Validate NetworkPolicy resources in storage namespaces

Something on-tracking:

  • The network policy in the hypershift management cluster control-plane namespace should be taken into an overall consideration, see discussion in slack

Test records:

$ ./openshift-tests run all --dry-run | grep -E "OCPFeature:StorageNetworkPolicy" | ./openshift-tests run -f -
passed: (15.5s) 2025-10-09T09:32:06 "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators"
passed: (16.7s) 2025-10-09T09:32:07 "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators"
passed: (17.7s) 2025-10-09T09:32:08 "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels"

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.

@duanwei33 duanwei33 force-pushed the storage-networkpolicy-e2e branch from c514831 to 16c7f2c Compare October 16, 2025 07:23
Copy link

openshift-trt bot commented Oct 16, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New tests seen in this PR at sha: 16c7f2c

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]

@mpatlasov
Copy link

FYI, go-verify-deps started failing because PR#70376 was merged recently.

podTemplateLabels = daemonset.Spec.Template.Labels

default:
g.Fail(fmt.Sprintf("Unsupported resource type: %s", res.ResourceType))

Choose a reason for hiding this comment

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

I'd suggest to set err explicitly here. Otherwise, if err != nil { continue } below wouldn't work.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the review! I've addressed the issues: I've removed the code if err != nil { continue } and the unused var err error declaration. Here's why:

  1. Each case in the switch statement uses := to declare its own local err variable, which shadows the outer err
  2. Both ResourceTypeDeployment and ResourceTypeDaemonSet cases already handle errors appropriately (either continue or g.Fail)
  3. The default case calls g.Fail() which terminates the test immediately
  4. Therefore, the outer err variable is never set and the if err != nil check is unreachable

The current approach is cleaner - each case handles its own errors, and unsupported resource types (which would be a code bug) fail immediately with a clear error message. So I prefer to removing the unless code :)

Let me know if you'd prefer a different approach!

@mpatlasov
Copy link

mpatlasov commented Oct 18, 2025

Hi @duanwei33 , thank you for reworking test case "should ensure required NetworkPolicies exist with correct labels", it looks great! I have only a couple of nits remaining (see my inline comments). They are minor, I'm ok to lgtm anyway. Let me know if you're going to address them. Otherwise we can go ahead with current code as-is.

Btw, how did you verify that e2e.TestContext.Provider gives reasonable string (not just empty "")? Setting env vars TEST_PROVIDER and TEST_CSI_DRIVER_FILES doesn't help for manual runs, and g.By() adds message to the logs only if test fails, so when it succeeds it's not clear whether it ran with empty currentPlatform or not.

@duanwei33
Copy link
Author

/retest-required

@duanwei33 duanwei33 force-pushed the storage-networkpolicy-e2e branch from 16c7f2c to 55b9a04 Compare October 20, 2025 01:44
This adds comprehensive e2e tests to verify that storage-related
operators and controllers have the required network policy labels and
that NetworkPolicy resources exist with correct pod selectors.

Changes:
- Add namespace constants to helpers.go for reuse across storage tests
- Add storage_networkpolicy.go with tests for CSO and CSI operators
- Verify required network policy labels on deployments
- Validate NetworkPolicy resources in storage namespaces
- Skip these tests on MicroShift clusters where they are not applicable
- Temporarily disabled ManilaCSINamespace check due to OCPBUGS-61175
@duanwei33 duanwei33 force-pushed the storage-networkpolicy-e2e branch from 55b9a04 to da3860c Compare October 20, 2025 02:41
Copy link
Contributor

openshift-ci bot commented Oct 20, 2025

@duanwei33: The following tests 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/go-verify-deps da3860c link true /test go-verify-deps
ci/prow/e2e-aws-ovn-microshift da3860c link true /test e2e-aws-ovn-microshift
ci/prow/okd-scos-e2e-aws-ovn da3860c link false /test okd-scos-e2e-aws-ovn
ci/prow/e2e-aws-ovn-microshift-serial da3860c link true /test e2e-aws-ovn-microshift-serial

Full PR test history. Your PR dashboard.

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.

Copy link

openshift-trt bot commented Oct 20, 2025

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New tests seen in this PR at sha: da3860c

  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should ensure required NetworkPolicies exist with correct labels [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSI related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]
  • "[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy should verify required labels for CSO related Operators [Suite:openshift/conformance/parallel]" [Total: 6, Pass: 6, Fail: 0, Flake: 0]

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.

3 participants