Skip to content

Conversation

@miyadav
Copy link
Member

@miyadav miyadav commented Jan 9, 2026

e2e tests for capi machine vap .
@sunzhaohua2 @huali9 PTAL when time permits.

Summary by CodeRabbit

  • Tests
    • Enhanced validation and permission enforcement testing for Machine API field, label, and annotation protections across multiple authorization scenarios, improving reliability of the protection mechanisms.

✏️ Tip: You can customize this high-level summary in your review settings.

@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 Jan 9, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 9, 2026

@miyadav: This pull request references OCPCLOUD-2992 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:

e2e tests for capi machine vap .
@sunzhaohua2 @huali9 PTAL when time permits.

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

📝 Walkthrough

Walkthrough

A single test file receives enhancements for validating admission policies (VAP) across different machine authorization scenarios. New error message constants, test contexts, and test cases are introduced to exercise VAP enforcement when either Machine API or CAPI is authoritative. A utility function signature is refactored from accepting a concrete machine type to accepting an interface type to support multiple machine implementations.

Changes

Cohort / File(s) Summary
Test Infrastructure and Constants
e2e/machine_migration_vap_tests.go
Adds three new VAP error message constants: vapCAPISpecLockedMessage, vapCAPIProtectedLabelMessage, vapCAPIProtectedAnnotationMessage for assertion of VAP enforcement on spec fields, labels, and annotations.
Verification Logic Refactoring
e2e/machine_migration_vap_tests.go
Updates verifyUpdateAllowed() method signature to accept interface{} instead of concrete *mapiv1beta1.Machine type, enabling type-based routing for both MAPI and CAPI machine updates with machine-specific success messaging.
New Test Contexts and Cases
e2e/machine_migration_vap_tests.go
Introduces comprehensive test suites for VAP enforcement covering MAPI-authoritative and CAPI-authoritative scenarios, with dedicated test contexts for spec field restrictions, protected label restrictions, and protected annotation restrictions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hopping through tests with vigil keen,
Machines now speak in types between,
VAP enforcement, policies tight,
MAPI and CAPI, both tested right!
One interface to rule them all,
Authority checked, none shall fall.

🚥 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 directly references the Jira ticket (OCPCLOUD-2992) and clearly states the main change: adding tests for CAPI machine VAPs (Validating Admission Policies) related to OCP-86581.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

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 chrischdi and mdbooth January 9, 2026 10:01
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 9, 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 racheljpg 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 Jan 9, 2026

@miyadav: This pull request references OCPCLOUD-2992 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:

e2e tests for capi machine vap .
@sunzhaohua2 @huali9 PTAL when time permits.

Summary by CodeRabbit

  • Tests

  • Expanded end-to-end test coverage for machine migration scenarios with enhanced validation enforcement testing.

  • Refactor

  • Improved test infrastructure to support multiple machine types in validation scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

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

🧹 Nitpick comments (1)
e2e/machine_migration_vap_tests.go (1)

408-420: Use client.Object parameter to eliminate unnecessary type-switching.
Both *mapiv1beta1.Machine and *clusterv1.Machine implement client.Object, and komega.Update() accepts it directly—allowing you to drop the runtime type assertion.

Proposed simplification
-func verifyUpdateAllowed(machine interface{}, updateFunc func()) {
+func verifyUpdateAllowed(machine client.Object, updateFunc func()) {
 	By("Verifying that machine update is allowed")
-
-	switch m := machine.(type) {
-	case *mapiv1beta1.Machine:
-		Eventually(komega.Update(m, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
-			"Expected MAPI machine update to succeed")
-	case *clusterv1.Machine:
-		Eventually(komega.Update(m, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
-			"Expected CAPI machine update to succeed")
-	default:
-		Fail(fmt.Sprintf("unknown machine type: %T", machine))
-	}
+	Eventually(komega.Update(machine, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
+		"Expected machine update to succeed")
 }

You'll need to import client from controller-runtime: "sigs.k8s.io/controller-runtime/pkg/client".

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between b76286b and 7cf72b0.

📒 Files selected for processing (1)
  • e2e/machine_migration_vap_tests.go
🧰 Additional context used
🧬 Code graph analysis (1)
e2e/machine_migration_vap_tests.go (2)
pkg/conversion/mapi2capi/interface.go (1)
  • Machine (24-26)
e2e/framework/framework.go (3)
  • CAPINamespace (14-14)
  • WaitMedium (24-24)
  • RetryMedium (18-18)
🔇 Additional comments (2)
e2e/machine_migration_vap_tests.go (2)

37-44: The error message constants are correctly sourced from the cluster-api-machine-vap ValidatingAdmissionPolicy defined in manifests/0000_30_cluster-api_09_admission-policies.yaml. All three messages match the VAP policy exactly:

  • vapCAPISpecLockedMessage: matches the VAP spec validation message
  • vapCAPIProtectedLabelMessage: matches the VAP label guard message
  • vapCAPIProtectedAnnotationMessage: matches the VAP annotation guard message

Since these error messages are controlled by the VAP policy manifest in the same repository and the test assertions already use ContainSubstring() (which allows for flexibility rather than exact matching), the brittleness risk is manageable. Any drift between the constants and the VAP policy will be caught by test failures, which is the intended behavior.


275-395: Nil-deref concerns in the MAPI-authoritative test suite are overstated.

The code follows established patterns in the test suite:

  1. testCAPIMachine lookup: capiframework.GetMachine() uses Eventually(komega.Get(...)) with a 1-minute timeout, polling the API. It either succeeds (returning a valid object) or fails the test assertion. The testCAPIMachine pointer cannot be nil after the call succeeds.

  2. InfrastructureRef field access: The pattern testCAPIMachine.Spec.InfrastructureRef.Name = ... is used consistently throughout the codebase without nil guards:

    • machine_migration_helpers.go line 158
    • machineset_migration_helpers.go line 332
    • Other existing VAP test cases in the same file

    This consistent usage suggests InfrastructureRef is a struct value, not a pointer. If it were a pointer and could be nil, the existing code would already fail.

No changes are needed. The test fixture setup is sound, and the code aligns with established patterns in the suite.

@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 13, 2026

@miyadav: This pull request references OCPCLOUD-2992 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:

e2e tests for capi machine vap .
@sunzhaohua2 @huali9 PTAL when time permits.

Summary by CodeRabbit

  • Tests

  • Expanded end-to-end coverage for machine migration scenarios, adding enforcement checks for spec, label, and annotation update restrictions across authoritative contexts.

  • Refactor

  • Improved test infrastructure to support multiple machine types and unified update-verification flows.

  • Chores

  • Pinned Go tool version for consistent test execution.

✏️ Tip: You can customize this high-level summary in your review settings.

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

🤖 Fix all issues with AI agents
In @e2e/machine_migration_vap_tests.go:
- Around line 302-306: The test mutates
testCAPIMachine.Spec.InfrastructureRef.Name directly which can nil-pointer panic
if InfrastructureRef is nil; update the test before calling
verifyCAPIUpdatePrevented to either ensure Spec.InfrastructureRef is non-nil
(allocate & set a minimal corev1.ObjectReference) or guard the mutation with an
if testCAPIMachine.Spec.InfrastructureRef == nil {
testCAPIMachine.Spec.InfrastructureRef = &corev1.ObjectReference{ /* minimal
fields */ } } so that assigning to Spec.InfrastructureRef.Name is safe while
still invoking verifyCAPIUpdatePrevented with vapCAPISpecLockedMessage.
🧹 Nitpick comments (1)
e2e/machine_migration_vap_tests.go (1)

403-416: Consider using generics for type safety.

Using interface{} loses compile-time type checking. While the runtime type switch with Fail() handles errors appropriately for tests, you could leverage Go generics for stronger compile-time guarantees.

♻️ Optional: Type-safe alternative using generics
-func verifyUpdateAllowed(machine interface{}, updateFunc func()) {
+func verifyUpdateAllowed[T *mapiv1beta1.Machine | *clusterv1.Machine](machine T, updateFunc func()) {
 	By("Verifying that machine update is allowed")
-
-	switch m := machine.(type) {
-	case *mapiv1beta1.Machine:
-		Eventually(komega.Update(m, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
-			"Expected MAPI machine update to succeed")
-	case *clusterv1.Machine:
-		Eventually(komega.Update(m, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
-			"Expected CAPI machine update to succeed")
-	default:
-		Fail(fmt.Sprintf("unknown machine type: %T", machine))
-	}
+	Eventually(komega.Update(machine, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
+		fmt.Sprintf("Expected %T update to succeed", machine))
 }

Note: This requires komega.Update to accept both types. If komega.Update has specific type constraints, keeping the type switch may be necessary.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7cf72b0 and 0df38f6.

📒 Files selected for processing (2)
  • .tool-versions
  • e2e/machine_migration_vap_tests.go
✅ Files skipped from review due to trivial changes (1)
  • .tool-versions
🧰 Additional context used
🧬 Code graph analysis (1)
e2e/machine_migration_vap_tests.go (3)
pkg/conversion/mapi2capi/interface.go (1)
  • Machine (24-26)
e2e/framework/machine.go (1)
  • GetMachine (75-86)
e2e/framework/framework.go (3)
  • CAPINamespace (14-14)
  • WaitMedium (24-24)
  • RetryMedium (18-18)
🔇 Additional comments (3)
e2e/machine_migration_vap_tests.go (3)

42-43: Potential typo in annotation error message constant.

The label message on line 42 consistently uses the /* wildcard pattern (cluster.x-k8s.io/*), but the annotation message on line 43 appears to be missing the wildcards: "cluster.x-k8s.io or clusters.x-k8s.io" instead of "cluster.x-k8s.io/* or clusters.x-k8s.io/*".

If this matches the actual VAP policy message exactly, please disregard. Otherwise, consider aligning the pattern format.


275-390: LGTM!

The new test context for MAPI-authoritative VAP enforcement is well-structured with proper BeforeAll setup, DeferCleanup teardown, and comprehensive coverage of spec, label, and annotation restrictions. The test cases appropriately verify both blocked and allowed updates.


288-288: Verify verifyMachineAuthoritative helper function exists.

This line calls verifyMachineAuthoritative, but the function is not visible in the provided code. The other test contexts (lines 70-75 and 234-239) use inline Eventually with WithTransform assertions instead.

#!/bin/bash
# Search for the verifyMachineAuthoritative function definition
rg -n "func verifyMachineAuthoritative" --type go

Comment on lines +302 to +306
It("should prevent updating spec.infrastructureRef", func() {
verifyCAPIUpdatePrevented(testCAPIMachine, func() {
testCAPIMachine.Spec.InfrastructureRef.Name = "new-infra-ref"
}, vapCAPISpecLockedMessage)
})
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 nil pointer dereference on InfrastructureRef.

Accessing testCAPIMachine.Spec.InfrastructureRef.Name directly could cause a nil pointer panic if InfrastructureRef is nil. Consider adding a nil check or ensuring the machine always has this field populated.

🐛 Proposed fix with nil check
 			It("should prevent updating spec.infrastructureRef", func() {
 				verifyCAPIUpdatePrevented(testCAPIMachine, func() {
+					if testCAPIMachine.Spec.InfrastructureRef == nil {
+						testCAPIMachine.Spec.InfrastructureRef = &corev1.ObjectReference{}
+					}
 					testCAPIMachine.Spec.InfrastructureRef.Name = "new-infra-ref"
 				}, vapCAPISpecLockedMessage)
 			})
📝 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
It("should prevent updating spec.infrastructureRef", func() {
verifyCAPIUpdatePrevented(testCAPIMachine, func() {
testCAPIMachine.Spec.InfrastructureRef.Name = "new-infra-ref"
}, vapCAPISpecLockedMessage)
})
It("should prevent updating spec.infrastructureRef", func() {
verifyCAPIUpdatePrevented(testCAPIMachine, func() {
if testCAPIMachine.Spec.InfrastructureRef == nil {
testCAPIMachine.Spec.InfrastructureRef = &corev1.ObjectReference{}
}
testCAPIMachine.Spec.InfrastructureRef.Name = "new-infra-ref"
}, vapCAPISpecLockedMessage)
})
🤖 Prompt for AI Agents
In @e2e/machine_migration_vap_tests.go around lines 302 - 306, The test mutates
testCAPIMachine.Spec.InfrastructureRef.Name directly which can nil-pointer panic
if InfrastructureRef is nil; update the test before calling
verifyCAPIUpdatePrevented to either ensure Spec.InfrastructureRef is non-nil
(allocate & set a minimal corev1.ObjectReference) or guard the mutation with an
if testCAPIMachine.Spec.InfrastructureRef == nil {
testCAPIMachine.Spec.InfrastructureRef = &corev1.ObjectReference{ /* minimal
fields */ } } so that assigning to Spec.InfrastructureRef.Name is safe while
still invoking verifyCAPIUpdatePrevented with vapCAPISpecLockedMessage.

@miyadav miyadav requested a review from sunzhaohua2 January 21, 2026 10:17
@sunzhaohua2
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 22, 2026
@openshift-ci-robot
Copy link

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aws-capi-techpreview
/test e2e-aws-ovn
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-aws-ovn-techpreview
/test e2e-aws-ovn-techpreview-upgrade
/test e2e-azure-capi-techpreview
/test e2e-azure-ovn-techpreview
/test e2e-azure-ovn-techpreview-upgrade
/test e2e-gcp-capi-techpreview
/test e2e-gcp-ovn-techpreview
/test e2e-metal3-capi-techpreview
/test e2e-openstack-capi-techpreview
/test e2e-openstack-ovn-techpreview
/test e2e-vsphere-capi-techpreview
/test regression-clusterinfra-aws-ipi-techpreview-capi

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 26, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 26, 2026

@miyadav: This pull request references OCPCLOUD-2992 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:

e2e tests for capi machine vap .
@sunzhaohua2 @huali9 PTAL when time permits.

Summary by CodeRabbit

  • Tests
  • Enhanced validation and permission enforcement testing for Machine API field, label, and annotation protections across multiple authorization scenarios, improving reliability of the protection mechanisms.

✏️ Tip: You can customize this high-level summary in your review settings.

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.

@sunzhaohua2
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 26, 2026
@openshift-ci-robot
Copy link

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aws-capi-techpreview
/test e2e-aws-ovn
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-aws-ovn-techpreview
/test e2e-aws-ovn-techpreview-upgrade
/test e2e-azure-capi-techpreview
/test e2e-azure-ovn-techpreview
/test e2e-azure-ovn-techpreview-upgrade
/test e2e-gcp-capi-techpreview
/test e2e-gcp-ovn-techpreview
/test e2e-metal3-capi-techpreview
/test e2e-openstack-capi-techpreview
/test e2e-openstack-ovn-techpreview
/test e2e-vsphere-capi-techpreview
/test regression-clusterinfra-aws-ipi-techpreview-capi

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 26, 2026

@miyadav: 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/e2e-metal3-capi-techpreview c6ec789 link false /test e2e-metal3-capi-techpreview
ci/prow/e2e-aws-capi-techpreview c6ec789 link true /test e2e-aws-capi-techpreview
ci/prow/e2e-azure-ovn-techpreview c6ec789 link false /test e2e-azure-ovn-techpreview
ci/prow/e2e-gcp-ovn-techpreview c6ec789 link true /test e2e-gcp-ovn-techpreview

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.

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. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants