Skip to content

Conversation

@miyadav
Copy link
Member

@miyadav miyadav commented Feb 6, 2026

Added tests for networkpolicies for capi namespaces.
@sunzhaohua2 @huali9 PTAL when time permits
cc @mdbooth @damdo

`miyadav@miyadav-mac cluster-capi-operator % KUBECONFIG=~/.kube/config go test -v ./e2e -ginkgo.focus="Network Policy Tests" -ginkgo.v -timeout 10m
=== RUN   TestAPIs
Running Suite: Cluster API Suite - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e
================================================================================================
Random Seed: 1770379888

Will run 6 of 101 specs
------------------------------
[BeforeSuite] 
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/e2e_test.go:15
[BeforeSuite] PASSED [0.739 seconds]
------------------------------
SSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration MAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: MachineAPI and existing CAPI MachineSet with same name should reject creation of MAPI MachineSet with same name as existing CAPI MachineSet
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_mapi_authoritative_test.go:59
------------------------------
SSSSSSSSSSSSSSSSSSS
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have network policies with correct labels
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:56
  STEP: Checking default-deny network policy exists @ 02/06/26 12:11:29.097
  STEP: Verifying default-deny policy has correct annotations @ 02/06/26 12:11:29.242
  STEP: Verifying default-deny policy denies all ingress and egress @ 02/06/26 12:11:29.242
  STEP: Checking allow-ingress-to-metrics-controllers network policy exists @ 02/06/26 12:11:29.242
  STEP: Verifying metrics controllers policy allows ingress on port 8443 @ 02/06/26 12:11:29.388
  STEP: Checking allow-ingress-to-metrics-operators network policy exists @ 02/06/26 12:11:29.388
  STEP: Checking allow-egress-controllers network policy exists @ 02/06/26 12:11:29.531
  STEP: Checking allow-egress-operators network policy exists @ 02/06/26 12:11:29.676
  STEP: Checking allow-ingress-to-webhook network policy exists @ 02/06/26 12:11:29.821
• [1.159 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have services exposing all metrics ports
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:125
  STEP: Checking webhook service exists with correct ports @ 02/06/26 12:11:29.962
  STEP: Verifying webhook service exposes port 9443 @ 02/06/26 12:11:30.107
  STEP: Verifying webhook service targets capi-controllers pods @ 02/06/26 12:11:30.107
  STEP: Checking capi-controllers deployment has metrics ports configured @ 02/06/26 12:11:30.107
  STEP: Verifying capi-controllers pod has required ports @ 02/06/26 12:11:30.262
  STEP: Verifying capi-controllers container exposes diagnostics port 8443 @ 02/06/26 12:11:30.262
  STEP: Verifying capi-controllers container exposes webhook port 9443 @ 02/06/26 12:11:30.262
  STEP: Verifying capi-controllers container exposes health port 9440 @ 02/06/26 12:11:30.262
  STEP: Verifying machine-api-migration container exposes diagnostics port 8442 @ 02/06/26 12:11:30.262
  STEP: Verifying machine-api-migration container exposes health port 9441 @ 02/06/26 12:11:30.262
• [0.301 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should allow Prometheus to access metrics endpoints
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:223
  STEP: Verifying namespace has cluster monitoring enabled @ 02/06/26 12:11:30.263
  STEP: Creating a test pod to verify metrics endpoint accessibility @ 02/06/26 12:11:30.407
  STEP: Waiting for test pod to be ready @ 02/06/26 12:11:30.556
  STEP: Verifying network policy allows access to metrics endpoints @ 02/06/26 12:11:35.844
  STEP: Network policy configuration allows metrics scraping from pod capi-controllers-546cdcbfd4-2hb8b at 10.128.0.16:8443 @ 02/06/26 12:11:35.99
  STEP: Cleaning up test pod @ 02/06/26 12:11:35.99
• [5.877 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290
  STEP: Checking capi-operator deployment exists @ 02/06/26 12:11:36.14
  [SKIPPED] in [It] - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
S [SKIPPED] [0.142 seconds]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace [It] should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290

  [SKIPPED] capi-operator pods not found in openshift-cluster-api-operator namespace
  In [It] at: /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have cluster monitoring enabled
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:335
  STEP: Verifying namespace has cluster monitoring label @ 02/06/26 12:11:36.282
• [0.145 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests NetworkPolicy port specifications should have correct port configurations in network policies
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:345
  STEP: Verifying allow-ingress-to-metrics-controllers has correct port @ 02/06/26 12:11:36.427
  STEP: Verifying allow-ingress-to-metrics-operators has correct port @ 02/06/26 12:11:36.574
  STEP: Verifying allow-ingress-to-webhook has correct ports @ 02/06/26 12:11:36.719
• [0.438 seconds]
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration CAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name should verify that the non-authoritative MAPI MachineSet providerSpec has been updated to reflect the authoritative CAPI MachineSet mirror values
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_capi_authoritative_test.go:62
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

Ran 5 of 101 Specs in 8.806 seconds
SUCCESS! -- 5 Passed | 0 Failed | 2 Pending | 94 Skipped
--- PASS: TestAPIs (8.81s)
PASS
ok      github.com/openshift/cluster-capi-operator/e2e  9.617s`

Summary by CodeRabbit

  • Tests
    • Added a comprehensive end-to-end test suite validating NetworkPolicy behavior, default-deny and allow rules, service exposure, container ports and port names, operator/namespace labels, and Prometheus metrics accessibility.
    • Includes checks for gating/feature conditions, multi-namespace coverage, metrics/webhook connectivity, pod-based access verification, and conditional skips/cleanup for missing components.

@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Feb 6, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 6, 2026

@miyadav: This pull request references OCPCLOUD-3357 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 story to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Added tests for networkpolicies for capi namespaces.
@sunzhaohua2 @huali9 PTAL when time permits
cc @mdbooth @damdo

`miyadav@miyadav-mac cluster-capi-operator % KUBECONFIG=~/.kube/config go test -v ./e2e -ginkgo.focus="Network Policy Tests" -ginkgo.v -timeout 10m
=== RUN   TestAPIs
Running Suite: Cluster API Suite - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e
================================================================================================
Random Seed: 1770379888

Will run 6 of 101 specs
------------------------------
[BeforeSuite] 
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/e2e_test.go:15
[BeforeSuite] PASSED [0.739 seconds]
------------------------------
SSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration MAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: MachineAPI and existing CAPI MachineSet with same name should reject creation of MAPI MachineSet with same name as existing CAPI MachineSet
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_mapi_authoritative_test.go:59
------------------------------
SSSSSSSSSSSSSSSSSSS
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have network policies with correct labels
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:56
 STEP: Checking default-deny network policy exists @ 02/06/26 12:11:29.097
 STEP: Verifying default-deny policy has correct annotations @ 02/06/26 12:11:29.242
 STEP: Verifying default-deny policy denies all ingress and egress @ 02/06/26 12:11:29.242
 STEP: Checking allow-ingress-to-metrics-controllers network policy exists @ 02/06/26 12:11:29.242
 STEP: Verifying metrics controllers policy allows ingress on port 8443 @ 02/06/26 12:11:29.388
 STEP: Checking allow-ingress-to-metrics-operators network policy exists @ 02/06/26 12:11:29.388
 STEP: Checking allow-egress-controllers network policy exists @ 02/06/26 12:11:29.531
 STEP: Checking allow-egress-operators network policy exists @ 02/06/26 12:11:29.676
 STEP: Checking allow-ingress-to-webhook network policy exists @ 02/06/26 12:11:29.821
• [1.159 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have services exposing all metrics ports
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:125
 STEP: Checking webhook service exists with correct ports @ 02/06/26 12:11:29.962
 STEP: Verifying webhook service exposes port 9443 @ 02/06/26 12:11:30.107
 STEP: Verifying webhook service targets capi-controllers pods @ 02/06/26 12:11:30.107
 STEP: Checking capi-controllers deployment has metrics ports configured @ 02/06/26 12:11:30.107
 STEP: Verifying capi-controllers pod has required ports @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes diagnostics port 8443 @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes webhook port 9443 @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes health port 9440 @ 02/06/26 12:11:30.262
 STEP: Verifying machine-api-migration container exposes diagnostics port 8442 @ 02/06/26 12:11:30.262
 STEP: Verifying machine-api-migration container exposes health port 9441 @ 02/06/26 12:11:30.262
• [0.301 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should allow Prometheus to access metrics endpoints
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:223
 STEP: Verifying namespace has cluster monitoring enabled @ 02/06/26 12:11:30.263
 STEP: Creating a test pod to verify metrics endpoint accessibility @ 02/06/26 12:11:30.407
 STEP: Waiting for test pod to be ready @ 02/06/26 12:11:30.556
 STEP: Verifying network policy allows access to metrics endpoints @ 02/06/26 12:11:35.844
 STEP: Network policy configuration allows metrics scraping from pod capi-controllers-546cdcbfd4-2hb8b at 10.128.0.16:8443 @ 02/06/26 12:11:35.99
 STEP: Cleaning up test pod @ 02/06/26 12:11:35.99
• [5.877 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290
 STEP: Checking capi-operator deployment exists @ 02/06/26 12:11:36.14
 [SKIPPED] in [It] - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
S [SKIPPED] [0.142 seconds]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace [It] should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290

 [SKIPPED] capi-operator pods not found in openshift-cluster-api-operator namespace
 In [It] at: /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have cluster monitoring enabled
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:335
 STEP: Verifying namespace has cluster monitoring label @ 02/06/26 12:11:36.282
• [0.145 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests NetworkPolicy port specifications should have correct port configurations in network policies
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:345
 STEP: Verifying allow-ingress-to-metrics-controllers has correct port @ 02/06/26 12:11:36.427
 STEP: Verifying allow-ingress-to-metrics-operators has correct port @ 02/06/26 12:11:36.574
 STEP: Verifying allow-ingress-to-webhook has correct ports @ 02/06/26 12:11:36.719
• [0.438 seconds]
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration CAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name should verify that the non-authoritative MAPI MachineSet providerSpec has been updated to reflect the authoritative CAPI MachineSet mirror values
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_capi_authoritative_test.go:62
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

Ran 5 of 101 Specs in 8.806 seconds
SUCCESS! -- 5 Passed | 0 Failed | 2 Pending | 94 Skipped
--- PASS: TestAPIs (8.81s)
PASS
ok      github.com/openshift/cluster-capi-operator/e2e  9.617s`

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 Feb 6, 2026

📝 Walkthrough

Walkthrough

Adds a new end-to-end Go test suite (Ginkgo/Gomega) that validates Kubernetes NetworkPolicy, service exposure, pod/container ports, and Prometheus metrics accessibility for OpenShift Cluster API components across openshift-cluster-api and openshift-cluster-api-operator namespaces.

Changes

Cohort / File(s) Summary
NetworkPolicy E2E Test Suite
e2e/network_policy_test.go
New 401-line Ginkgo/Gomega test file validating default-deny and allow ingress/egress policies, presence and ports of metrics/webhook services (8443, 8442, 9443, 9440, 9441), container port names and ports for capi-controllers and machine-api-migration, operator namespace checks (labels, ports), and Prometheus metrics access via a test Pod. Includes AWS-only gating, feature-gate checks, conditional skips, and cleanup logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 I hopped through tests both bold and neat,

validating ports and policies fleet.
From webhooks to metrics, every check done right,
I nibbled bugs away beneath the moonlight. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding tests for network policies in CAPI, which directly aligns with the addition of the network_policy_test.go file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

No actionable comments were generated in the recent review. 🎉

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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

@openshift-ci openshift-ci bot requested review from mdbooth and racheljpg February 6, 2026 12:12
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 6, 2026

[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 stephenfin 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

@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 6, 2026

@miyadav: This pull request references OCPCLOUD-3357 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 story to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Added tests for networkpolicies for capi namespaces.
@sunzhaohua2 @huali9 PTAL when time permits
cc @mdbooth @damdo

`miyadav@miyadav-mac cluster-capi-operator % KUBECONFIG=~/.kube/config go test -v ./e2e -ginkgo.focus="Network Policy Tests" -ginkgo.v -timeout 10m
=== RUN   TestAPIs
Running Suite: Cluster API Suite - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e
================================================================================================
Random Seed: 1770379888

Will run 6 of 101 specs
------------------------------
[BeforeSuite] 
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/e2e_test.go:15
[BeforeSuite] PASSED [0.739 seconds]
------------------------------
SSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration MAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: MachineAPI and existing CAPI MachineSet with same name should reject creation of MAPI MachineSet with same name as existing CAPI MachineSet
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_mapi_authoritative_test.go:59
------------------------------
SSSSSSSSSSSSSSSSSSS
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have network policies with correct labels
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:56
 STEP: Checking default-deny network policy exists @ 02/06/26 12:11:29.097
 STEP: Verifying default-deny policy has correct annotations @ 02/06/26 12:11:29.242
 STEP: Verifying default-deny policy denies all ingress and egress @ 02/06/26 12:11:29.242
 STEP: Checking allow-ingress-to-metrics-controllers network policy exists @ 02/06/26 12:11:29.242
 STEP: Verifying metrics controllers policy allows ingress on port 8443 @ 02/06/26 12:11:29.388
 STEP: Checking allow-ingress-to-metrics-operators network policy exists @ 02/06/26 12:11:29.388
 STEP: Checking allow-egress-controllers network policy exists @ 02/06/26 12:11:29.531
 STEP: Checking allow-egress-operators network policy exists @ 02/06/26 12:11:29.676
 STEP: Checking allow-ingress-to-webhook network policy exists @ 02/06/26 12:11:29.821
• [1.159 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have services exposing all metrics ports
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:125
 STEP: Checking webhook service exists with correct ports @ 02/06/26 12:11:29.962
 STEP: Verifying webhook service exposes port 9443 @ 02/06/26 12:11:30.107
 STEP: Verifying webhook service targets capi-controllers pods @ 02/06/26 12:11:30.107
 STEP: Checking capi-controllers deployment has metrics ports configured @ 02/06/26 12:11:30.107
 STEP: Verifying capi-controllers pod has required ports @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes diagnostics port 8443 @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes webhook port 9443 @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes health port 9440 @ 02/06/26 12:11:30.262
 STEP: Verifying machine-api-migration container exposes diagnostics port 8442 @ 02/06/26 12:11:30.262
 STEP: Verifying machine-api-migration container exposes health port 9441 @ 02/06/26 12:11:30.262
• [0.301 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should allow Prometheus to access metrics endpoints
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:223
 STEP: Verifying namespace has cluster monitoring enabled @ 02/06/26 12:11:30.263
 STEP: Creating a test pod to verify metrics endpoint accessibility @ 02/06/26 12:11:30.407
 STEP: Waiting for test pod to be ready @ 02/06/26 12:11:30.556
 STEP: Verifying network policy allows access to metrics endpoints @ 02/06/26 12:11:35.844
 STEP: Network policy configuration allows metrics scraping from pod capi-controllers-546cdcbfd4-2hb8b at 10.128.0.16:8443 @ 02/06/26 12:11:35.99
 STEP: Cleaning up test pod @ 02/06/26 12:11:35.99
• [5.877 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290
 STEP: Checking capi-operator deployment exists @ 02/06/26 12:11:36.14
 [SKIPPED] in [It] - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
S [SKIPPED] [0.142 seconds]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace [It] should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290

 [SKIPPED] capi-operator pods not found in openshift-cluster-api-operator namespace
 In [It] at: /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have cluster monitoring enabled
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:335
 STEP: Verifying namespace has cluster monitoring label @ 02/06/26 12:11:36.282
• [0.145 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests NetworkPolicy port specifications should have correct port configurations in network policies
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:345
 STEP: Verifying allow-ingress-to-metrics-controllers has correct port @ 02/06/26 12:11:36.427
 STEP: Verifying allow-ingress-to-metrics-operators has correct port @ 02/06/26 12:11:36.574
 STEP: Verifying allow-ingress-to-webhook has correct ports @ 02/06/26 12:11:36.719
• [0.438 seconds]
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration CAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name should verify that the non-authoritative MAPI MachineSet providerSpec has been updated to reflect the authoritative CAPI MachineSet mirror values
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_capi_authoritative_test.go:62
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

Ran 5 of 101 Specs in 8.806 seconds
SUCCESS! -- 5 Passed | 0 Failed | 2 Pending | 94 Skipped
--- PASS: TestAPIs (8.81s)
PASS
ok      github.com/openshift/cluster-capi-operator/e2e  9.617s`

Summary by CodeRabbit

  • Tests
  • Added comprehensive end-to-end test suite validating Kubernetes NetworkPolicy configurations, service exposure, and metrics accessibility for cluster operations.

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.

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

🤖 Fix all issues with AI agents
In `@e2e/network_policy_test.go`:
- Around line 390-397: In the webhook port loop in e2e/network_policy_test.go
(the block that sets hasWebhookPort and iterates over webhookPorts), avoid
directly accessing port.Port.IntVal because it can be zero for named ports;
instead check port.Port.Type (or use port.Port.IntValue()) before comparing to
webhookPort or 443 and keep the same protocol assertions
(Expect(port.Protocol).ToNot(BeNil()) and
Expect(*port.Protocol).To(Equal(corev1.ProtocolTCP))). Update the conditional
that currently uses port.Port.IntVal to first ensure the value is an int (or
call IntValue()) so named ports don’t produce false negatives.
- Around line 273-286: The test currently only logs a message (By(...)) and
never verifies connectivity; update the test in e2e/network_policy_test.go to
actually assert reachability of the metrics endpoint: after obtaining podList,
targetPod, targetPodIP and metricsPort, exec a command from the test pod (or a
dedicated test helper pod) to curl or wget
http://<targetPodIP>:<metricsPort>/metrics and assert a successful HTTP response
(0 exit code and non-empty body) rather than just using By(); refer to the
existing podList, targetPod, targetPodIP and metricsPort symbols and add the
exec call and Expect assertions to fail the test if scraping is blocked.
- Around line 84-93: The test can miss named ports because it only checks
port.Port.IntVal; update the check inside the loop that iterates
metricsControllersPolicy.Spec.Ingress to handle intstr.IntOrString properly
(e.g., call port.Port.IntValue() or first check port.Port.Type == intstr.Int
before using IntVal) and compare that result to metricsPort so hasMetricsPort
correctly becomes true for both numeric and named-port representations.
🧹 Nitpick comments (4)
e2e/network_policy_test.go (4)

170-198: Consider extracting repeated port-checking logic into a helper.

The same pattern of iterating over container ports to find a specific port and name is repeated multiple times (lines 171-177, 181-187, 191-197, and again in the migration container section). This could be simplified with a helper function.

Example helper function
// Add this helper function at package level or within the test
func hasContainerPort(container *corev1.Container, port int32, name string) bool {
	for _, p := range container.Ports {
		if p.ContainerPort == port && p.Name == name {
			return true
		}
	}
	return false
}

Then simplify checks:

-			By("Verifying capi-controllers container exposes diagnostics port 8443")
-			hasMetricsPortInContainer := false
-			for _, port := range capiControllersContainer.Ports {
-				if port.ContainerPort == metricsPort && port.Name == "diagnostics-o" {
-					hasMetricsPortInContainer = true
-					break
-				}
-			}
-			Expect(hasMetricsPortInContainer).To(BeTrue(), "capi-controllers container should expose diagnostics port 8443")
+			By("Verifying capi-controllers container exposes diagnostics port 8443")
+			Expect(hasContainerPort(capiControllersContainer, metricsPort, "diagnostics-o")).To(BeTrue(),
+				"capi-controllers container should expose diagnostics port 8443")

241-244: Consider using a pinned image tag instead of :latest.

Using :latest for the test pod image (registry.access.redhat.com/ubi9/ubi-minimal:latest) can lead to non-reproducible test results if the image changes. Consider pinning to a specific version or digest for deterministic behavior.


251-254: Simplify error handling for pod creation.

The current pattern is functional but could be clearer.

Proposed simplification
 			err := cl.Create(ctx, testPod)
-			if err != nil && !apierrors.IsAlreadyExists(err) {
-				Expect(err).ToNot(HaveOccurred())
-			}
+			Expect(client.IgnoreAlreadyExists(err)).ToNot(HaveOccurred())

client.IgnoreAlreadyExists from controller-runtime returns nil if the error is AlreadyExists, making the intent clearer.


353-360: Brittle assertion on exact number of ingress rules.

The assertion Expect(policy.Spec.Ingress).To(HaveLen(1)) will fail if the policy is extended with additional ingress rules, even if the required port is still correctly configured. Consider checking that the expected port exists among the rules rather than asserting an exact count.

More resilient approach
-			Expect(policy.Spec.Ingress).To(HaveLen(1))
-			Expect(policy.Spec.Ingress[0].Ports).ToNot(BeEmpty())
-
-			port := policy.Spec.Ingress[0].Ports[0]
-			Expect(port.Protocol).ToNot(BeNil())
-			Expect(*port.Protocol).To(Equal(corev1.ProtocolTCP))
-			Expect(port.Port).ToNot(BeNil())
-			Expect(*port.Port).To(Equal(intstr.FromInt(metricsPort)))
+			Expect(policy.Spec.Ingress).ToNot(BeEmpty())
+			
+			foundPort := false
+			for _, ingress := range policy.Spec.Ingress {
+				for _, port := range ingress.Ports {
+					if port.Port != nil && *port.Port == intstr.FromInt(metricsPort) {
+						Expect(port.Protocol).ToNot(BeNil())
+						Expect(*port.Protocol).To(Equal(corev1.ProtocolTCP))
+						foundPort = true
+						break
+					}
+				}
+			}
+			Expect(foundPort).To(BeTrue(), "Policy should have metrics port configured")

Comment on lines +84 to +93
hasMetricsPort := false
for _, ingress := range metricsControllersPolicy.Spec.Ingress {
for _, port := range ingress.Ports {
if port.Port != nil && port.Port.IntVal == metricsPort {
hasMetricsPort = true
break
}
}
}
Expect(hasMetricsPort).To(BeTrue(), "NetworkPolicy should allow ingress on port 8443")
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

Potential false negative when port is specified as a string.

intstr.IntOrString can hold either an integer (IntVal) or a string (StrVal). If the NetworkPolicy specifies the port as a named port string, port.Port.IntVal will be 0 even though port.Port != nil. This could cause the test to incorrectly report that the metrics port is not configured.

Proposed fix to handle both int and string port types
 			hasMetricsPort := false
 			for _, ingress := range metricsControllersPolicy.Spec.Ingress {
 				for _, port := range ingress.Ports {
-					if port.Port != nil && port.Port.IntVal == metricsPort {
+					if port.Port != nil && port.Port.IntValue() == int(metricsPort) {
 						hasMetricsPort = true
 						break
 					}
 				}
 			}

Note: IntValue() returns the integer value regardless of whether the underlying type is int or string (returns 0 for non-numeric strings). Alternatively, explicitly check port.Port.Type == intstr.Int before accessing IntVal.

📝 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
hasMetricsPort := false
for _, ingress := range metricsControllersPolicy.Spec.Ingress {
for _, port := range ingress.Ports {
if port.Port != nil && port.Port.IntVal == metricsPort {
hasMetricsPort = true
break
}
}
}
Expect(hasMetricsPort).To(BeTrue(), "NetworkPolicy should allow ingress on port 8443")
hasMetricsPort := false
for _, ingress := range metricsControllersPolicy.Spec.Ingress {
for _, port := range ingress.Ports {
if port.Port != nil && port.Port.IntValue() == int(metricsPort) {
hasMetricsPort = true
break
}
}
}
Expect(hasMetricsPort).To(BeTrue(), "NetworkPolicy should allow ingress on port 8443")
🤖 Prompt for AI Agents
In `@e2e/network_policy_test.go` around lines 84 - 93, The test can miss named
ports because it only checks port.Port.IntVal; update the check inside the loop
that iterates metricsControllersPolicy.Spec.Ingress to handle intstr.IntOrString
properly (e.g., call port.Port.IntValue() or first check port.Port.Type ==
intstr.Int before using IntVal) and compare that result to metricsPort so
hasMetricsPort correctly becomes true for both numeric and named-port
representations.

Comment on lines +273 to +286
By("Verifying network policy allows access to metrics endpoints")
podList := &corev1.PodList{}
Expect(cl.List(ctx, podList, client.InNamespace(capiNamespace), client.MatchingLabels{
capiControllersLabel: capiControllersValue,
})).To(Succeed())

Expect(podList.Items).ToNot(BeEmpty(), "capi-controllers pods should exist for testing")

targetPod := podList.Items[0]
targetPodIP := targetPod.Status.PodIP
Expect(targetPodIP).ToNot(BeEmpty(), "Target pod should have an IP address")

By(fmt.Sprintf("Network policy configuration allows metrics scraping from pod %s at %s:%d", targetPod.Name, targetPodIP, metricsPort))
})
Copy link

@coderabbitai coderabbitai bot Feb 6, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Test does not actually verify metrics endpoint accessibility.

The test creates a pod and retrieves the target pod's IP but never actually verifies that the test pod can reach the metrics endpoint. The final By() statement just logs a message without performing any connectivity check. This makes the test name misleading.

Consider either:

  1. Actually testing connectivity (e.g., exec into the test pod and curl the metrics endpoint)
  2. Renaming the test to reflect what it actually validates (policy configuration exists)
  3. Adding a comment explaining that this is a configuration validation only
🤖 Prompt for AI Agents
In `@e2e/network_policy_test.go` around lines 273 - 286, The test currently only
logs a message (By(...)) and never verifies connectivity; update the test in
e2e/network_policy_test.go to actually assert reachability of the metrics
endpoint: after obtaining podList, targetPod, targetPodIP and metricsPort, exec
a command from the test pod (or a dedicated test helper pod) to curl or wget
http://<targetPodIP>:<metricsPort>/metrics and assert a successful HTTP response
(0 exit code and non-empty body) rather than just using By(); refer to the
existing podList, targetPod, targetPodIP and metricsPort symbols and add the
exec call and Expect assertions to fail the test if scraping is blocked.

Copy link
Contributor

Choose a reason for hiding this comment

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

You raise a good point, CodeRabbit. I was wondering this myself.

Copy link

Choose a reason for hiding this comment

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

@mdbooth Thank you for confirming! Since this test could be more robust, I'd be happy to help plan the implementation of an actual connectivity check if the team decides to address it.

The fix would involve:

  1. Using the Kubernetes client's CoreV1().Pods().Exec() or a similar mechanism to run a command inside the test pod
  2. Executing a curl/wget command to hit http://<targetPodIP>:<metricsPort>/metrics
  3. Adding an Expect() assertion on the exit code and response to ensure the metrics endpoint is actually reachable

Just let me know if you'd like me to help plan the code changes for this! 🐰

Comment on lines +390 to +397
hasWebhookPort := false
for _, port := range webhookPorts {
if port.Port != nil && (port.Port.IntVal == webhookPort || port.Port.IntVal == 443) {
hasWebhookPort = true
Expect(port.Protocol).ToNot(BeNil())
Expect(*port.Protocol).To(Equal(corev1.ProtocolTCP))
}
}
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

Same IntVal access pattern issue.

Similar to the earlier comment, port.Port.IntVal may be 0 if the port is specified as a named string port. Consider using port.Port.IntValue() or checking port.Port.Type first.

🤖 Prompt for AI Agents
In `@e2e/network_policy_test.go` around lines 390 - 397, In the webhook port loop
in e2e/network_policy_test.go (the block that sets hasWebhookPort and iterates
over webhookPorts), avoid directly accessing port.Port.IntVal because it can be
zero for named ports; instead check port.Port.Type (or use port.Port.IntValue())
before comparing to webhookPort or 443 and keep the same protocol assertions
(Expect(port.Protocol).ToNot(BeNil()) and
Expect(*port.Protocol).To(Equal(corev1.ProtocolTCP))). Update the conditional
that currently uses port.Port.IntVal to first ensure the value is an int (or
call IntValue()) so named ports don’t produce false negatives.

@miyadav
Copy link
Member Author

miyadav commented Feb 6, 2026

/test unit

@miyadav
Copy link
Member Author

miyadav commented Feb 9, 2026

One of the test was getting skipped due to label updated label -

`miyadav@miyadav-mac cluster-capi-operator % go test -v ./e2e -ginkgo.focus="Network Policy Tests" -ginkgo.v -timeout 10m
=== RUN   TestAPIs
Running Suite: Cluster API Suite - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e
================================================================================================
Random Seed: 1770635408

Will run 6 of 101 specs
------------------------------
[BeforeSuite] 
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/e2e_test.go:15
[BeforeSuite] PASSED [0.573 seconds]
------------------------------
S
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have network policies with correct labels
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:56
  STEP: Checking default-deny network policy exists @ 02/09/26 11:10:09.425
  STEP: Verifying default-deny policy has correct annotations @ 02/09/26 11:10:09.538
  STEP: Verifying default-deny policy denies all ingress and egress @ 02/09/26 11:10:09.538
  STEP: Checking allow-ingress-to-metrics-controllers network policy exists @ 02/09/26 11:10:09.539
  STEP: Verifying metrics controllers policy allows ingress on port 8443 @ 02/09/26 11:10:09.649
  STEP: Checking allow-ingress-to-metrics-operators network policy exists @ 02/09/26 11:10:09.649
  STEP: Checking allow-egress-controllers network policy exists @ 02/09/26 11:10:09.762
  STEP: Checking allow-egress-operators network policy exists @ 02/09/26 11:10:09.875
  STEP: Checking allow-ingress-to-webhook network policy exists @ 02/09/26 11:10:09.985
• [0.902 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have services exposing all metrics ports
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:125
  STEP: Checking webhook service exists with correct ports @ 02/09/26 11:10:10.097
  STEP: Verifying webhook service exposes port 9443 @ 02/09/26 11:10:10.208
  STEP: Verifying webhook service targets capi-controllers pods @ 02/09/26 11:10:10.208
  STEP: Checking capi-controllers deployment has metrics ports configured @ 02/09/26 11:10:10.208
  STEP: Verifying capi-controllers pod has required ports @ 02/09/26 11:10:10.32
  STEP: Verifying capi-controllers container exposes diagnostics port 8443 @ 02/09/26 11:10:10.32
  STEP: Verifying capi-controllers container exposes webhook port 9443 @ 02/09/26 11:10:10.32
  STEP: Verifying capi-controllers container exposes health port 9440 @ 02/09/26 11:10:10.32
  STEP: Verifying machine-api-migration container exposes diagnostics port 8442 @ 02/09/26 11:10:10.32
  STEP: Verifying machine-api-migration container exposes health port 9441 @ 02/09/26 11:10:10.32
• [0.224 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should allow Prometheus to access metrics endpoints
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:223
  STEP: Verifying namespace has cluster monitoring enabled @ 02/09/26 11:10:10.321
  STEP: Creating a test pod to verify metrics endpoint accessibility @ 02/09/26 11:10:10.432
  STEP: Waiting for test pod to be ready @ 02/09/26 11:10:10.551
  STEP: Verifying network policy allows access to metrics endpoints @ 02/09/26 11:10:20.889
  STEP: Network policy configuration allows metrics scraping from pod capi-controllers-546cdcbfd4-7w67w at 10.128.0.36:8443 @ 02/09/26 11:10:21.002
  STEP: Cleaning up test pod @ 02/09/26 11:10:21.002
• [10.799 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290
  STEP: Checking capi-operator deployment exists @ 02/09/26 11:10:21.12
  STEP: Verifying capi-operator pod has required container @ 02/09/26 11:10:21.231
  STEP: Verifying capi-operator container exposes diagnostics port 8443 @ 02/09/26 11:10:21.231
  STEP: Verifying capi-operator container exposes health port 9440 @ 02/09/26 11:10:21.231
• [0.111 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have cluster monitoring enabled
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:335
  STEP: Verifying namespace has cluster monitoring label @ 02/09/26 11:10:21.231
• [0.117 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests NetworkPolicy port specifications should have correct port configurations in network policies
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:345
  STEP: Verifying allow-ingress-to-metrics-controllers has correct port @ 02/09/26 11:10:21.348
  STEP: Verifying allow-ingress-to-metrics-operators has correct port @ 02/09/26 11:10:21.471
  STEP: Verifying allow-ingress-to-webhook has correct ports @ 02/09/26 11:10:21.59
• [0.360 seconds]
------------------------------
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration MAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: MachineAPI and existing CAPI MachineSet with same name should reject creation of MAPI MachineSet with same name as existing CAPI MachineSet
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_mapi_authoritative_test.go:59
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration CAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name should verify that the non-authoritative MAPI MachineSet providerSpec has been updated to reflect the authoritative CAPI MachineSet mirror values
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_capi_authoritative_test.go:62
------------------------------
SSSSSSSSSSSSS

Ran 6 of 101 Specs in 13.092 seconds
SUCCESS! -- 6 Passed | 0 Failed | 2 Pending | 93 Skipped
--- PASS: TestAPIs (13.09s)
PASS
ok      github.com/openshift/cluster-capi-operator/e2e  13.866s`

@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 9, 2026

@miyadav: This pull request references OCPCLOUD-3357 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 story to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Added tests for networkpolicies for capi namespaces.
@sunzhaohua2 @huali9 PTAL when time permits
cc @mdbooth @damdo

`miyadav@miyadav-mac cluster-capi-operator % KUBECONFIG=~/.kube/config go test -v ./e2e -ginkgo.focus="Network Policy Tests" -ginkgo.v -timeout 10m
=== RUN   TestAPIs
Running Suite: Cluster API Suite - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e
================================================================================================
Random Seed: 1770379888

Will run 6 of 101 specs
------------------------------
[BeforeSuite] 
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/e2e_test.go:15
[BeforeSuite] PASSED [0.739 seconds]
------------------------------
SSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration MAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: MachineAPI and existing CAPI MachineSet with same name should reject creation of MAPI MachineSet with same name as existing CAPI MachineSet
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_mapi_authoritative_test.go:59
------------------------------
SSSSSSSSSSSSSSSSSSS
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have network policies with correct labels
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:56
 STEP: Checking default-deny network policy exists @ 02/06/26 12:11:29.097
 STEP: Verifying default-deny policy has correct annotations @ 02/06/26 12:11:29.242
 STEP: Verifying default-deny policy denies all ingress and egress @ 02/06/26 12:11:29.242
 STEP: Checking allow-ingress-to-metrics-controllers network policy exists @ 02/06/26 12:11:29.242
 STEP: Verifying metrics controllers policy allows ingress on port 8443 @ 02/06/26 12:11:29.388
 STEP: Checking allow-ingress-to-metrics-operators network policy exists @ 02/06/26 12:11:29.388
 STEP: Checking allow-egress-controllers network policy exists @ 02/06/26 12:11:29.531
 STEP: Checking allow-egress-operators network policy exists @ 02/06/26 12:11:29.676
 STEP: Checking allow-ingress-to-webhook network policy exists @ 02/06/26 12:11:29.821
• [1.159 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should have services exposing all metrics ports
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:125
 STEP: Checking webhook service exists with correct ports @ 02/06/26 12:11:29.962
 STEP: Verifying webhook service exposes port 9443 @ 02/06/26 12:11:30.107
 STEP: Verifying webhook service targets capi-controllers pods @ 02/06/26 12:11:30.107
 STEP: Checking capi-controllers deployment has metrics ports configured @ 02/06/26 12:11:30.107
 STEP: Verifying capi-controllers pod has required ports @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes diagnostics port 8443 @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes webhook port 9443 @ 02/06/26 12:11:30.262
 STEP: Verifying capi-controllers container exposes health port 9440 @ 02/06/26 12:11:30.262
 STEP: Verifying machine-api-migration container exposes diagnostics port 8442 @ 02/06/26 12:11:30.262
 STEP: Verifying machine-api-migration container exposes health port 9441 @ 02/06/26 12:11:30.262
• [0.301 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api namespace should allow Prometheus to access metrics endpoints
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:223
 STEP: Verifying namespace has cluster monitoring enabled @ 02/06/26 12:11:30.263
 STEP: Creating a test pod to verify metrics endpoint accessibility @ 02/06/26 12:11:30.407
 STEP: Waiting for test pod to be ready @ 02/06/26 12:11:30.556
 STEP: Verifying network policy allows access to metrics endpoints @ 02/06/26 12:11:35.844
 STEP: Network policy configuration allows metrics scraping from pod capi-controllers-546cdcbfd4-2hb8b at 10.128.0.16:8443 @ 02/06/26 12:11:35.99
 STEP: Cleaning up test pod @ 02/06/26 12:11:35.99
• [5.877 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290
 STEP: Checking capi-operator deployment exists @ 02/06/26 12:11:36.14
 [SKIPPED] in [It] - /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
S [SKIPPED] [0.142 seconds]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace [It] should have capi-operator deployment with metrics ports configured
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:290

 [SKIPPED] capi-operator pods not found in openshift-cluster-api-operator namespace
 In [It] at: /Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:298 @ 02/06/26 12:11:36.282
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests in openshift-cluster-api-operator namespace should have cluster monitoring enabled
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:335
 STEP: Verifying namespace has cluster monitoring label @ 02/06/26 12:11:36.282
• [0.145 seconds]
------------------------------
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Network Policy Tests NetworkPolicy port specifications should have correct port configurations in network policies
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/network_policy_test.go:345
 STEP: Verifying allow-ingress-to-metrics-controllers has correct port @ 02/06/26 12:11:36.427
 STEP: Verifying allow-ingress-to-metrics-operators has correct port @ 02/06/26 12:11:36.574
 STEP: Verifying allow-ingress-to-webhook has correct ports @ 02/06/26 12:11:36.719
• [0.438 seconds]
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSS
P [PENDING]
[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration CAPI Authoritative Tests Create MAPI MachineSets with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name should verify that the non-authoritative MAPI MachineSet providerSpec has been updated to reflect the authoritative CAPI MachineSet mirror values
/Users/miyadav/github.com/openshift/cluster-capi-operator/e2e/machineset_migration_capi_authoritative_test.go:62
------------------------------
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

Ran 5 of 101 Specs in 8.806 seconds
SUCCESS! -- 5 Passed | 0 Failed | 2 Pending | 94 Skipped
--- PASS: TestAPIs (8.81s)
PASS
ok      github.com/openshift/cluster-capi-operator/e2e  9.617s`

Summary by CodeRabbit

  • Tests
  • Added a comprehensive end-to-end test suite validating NetworkPolicy behavior, default-deny and allow rules, service exposure, container ports and port names, operator/namespace labels, and Prometheus metrics accessibility.
  • Includes checks for gating/feature conditions, multi-namespace coverage, metrics/webhook connectivity, pod-based access verification, and conditional skips/cleanup for missing components.

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 Feb 9, 2026

@miyadav: 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.

@damdo
Copy link
Member

damdo commented Feb 9, 2026

/assign @mdbooth

Copy link
Contributor

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

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

This contains a number of what I call 'diff tests', where the test is essentially just asserting that the code is exactly what it is. Do we normally write these? I have only ever found them counter productive because:

  • They don't actually tell if the code works
  • But they still trip you up when you modify the code

So... negative value imho 😬

I was hoping to see something that directly tested the functionality. E.g.

  • Confirm that connections that the NetworkPolicy intends to allow are permitted
  • Confirm that connections that the NetworkPolicy does not allow are not permitted
  • Confirm that metrics are showing up in the place that they're supposed to

That last one feels like it might live in the step registry? Not sure about that.

Comment on lines +273 to +286
By("Verifying network policy allows access to metrics endpoints")
podList := &corev1.PodList{}
Expect(cl.List(ctx, podList, client.InNamespace(capiNamespace), client.MatchingLabels{
capiControllersLabel: capiControllersValue,
})).To(Succeed())

Expect(podList.Items).ToNot(BeEmpty(), "capi-controllers pods should exist for testing")

targetPod := podList.Items[0]
targetPodIP := targetPod.Status.PodIP
Expect(targetPodIP).ToNot(BeEmpty(), "Target pod should have an IP address")

By(fmt.Sprintf("Network policy configuration allows metrics scraping from pod %s at %s:%d", targetPod.Name, targetPodIP, metricsPort))
})
Copy link
Contributor

Choose a reason for hiding this comment

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

You raise a good point, CodeRabbit. I was wondering this myself.

})

Context("in openshift-cluster-api namespace", func() {
It("should have network policies with correct labels", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading this test, it looks like it's just checking that the policy exists and has the properties defined in the manifest. That's basically a test of CVO. Do we normally test stuff like this?

My experience of this kind of test is that it just trips you up when renaming something, without ever providing any useful testing signal.


})

It("should have services exposing all metrics ports", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same as above, except for the Service. This isn't testing any functionality, just that the Service created matches what's in the manifest. That's CVO's job. I wouldn't test this. It doesn't tell me anything I need to know, but it does create additional work if I need to modify the manifests.

}
})

It("should allow Prometheus to access metrics endpoints", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

As CodeRabbit points out, this appears to be missing the actual test. I was expecting to see us create a pod and then perhaps:

  • Confirm that the metrics endpoint is accessible from the same namespace
  • Confirm that the metrics endpoint is accessible from another namespace
  • Confirm that some other port is not exposed outside the namespace?

I haven't thought deeply about these, btw. You may come up with more relevant tests.

})
})

Context("in openshift-cluster-api-operator namespace", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, this is just checking the names of things. In this case that a deployed Pod has the properties which were defined in its Deployment. This is testing CVO and kube-controller-manager. I don't think this test lives here.

Expect(hasHealthPort).To(BeTrue(), "capi-operator container should expose health port 9440")
})

It("should have cluster monitoring enabled", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way we can test this directly instead? e.g. by ensuring that metrics from this namespace actually show up in cluster monitoring?

})

Context("NetworkPolicy port specifications", func() {
It("should have correct port configurations in network policies", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, this is just testing that the network policy was created as defined. It doesn't test any resulting functionality. I would not include this test.

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.

4 participants