Skip to content

Conversation

@sunzhaohua2
Copy link
Contributor

@sunzhaohua2 sunzhaohua2 commented Dec 1, 2025

Summary by CodeRabbit

  • Tests
    • Added new test scenarios to verify that MAPI Machine creation fails when a CAPI Machine with the same name already exists.
    • Added new test scenarios to verify that MAPI MachineSet creation fails when a CAPI MachineSet with the same name already exists.
    • Activated a previously disabled test for non-authoritative MAPI MachineSet provider specification validation.

✏️ 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 Dec 1, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Dec 1, 2025

@sunzhaohua2: This pull request references OCPCLOUD-2641 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.21.0" version, but no target version was set.

This pull request references OCPCLOUD-3188 which is a valid jira issue.

Details

In response to this:

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 openshift-ci bot requested review from damdo and mdbooth December 1, 2025 08:25
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 1, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

Walkthrough

This pull request adds helper functions for testing failure scenarios in machine and machineset migration, alongside corresponding end-to-end tests that verify creation fails when a resource with the same name already exists. A previously pending test for non-authoritative MAPI MachineSet provider spec validation is also enabled.

Changes

Cohort / File(s) Summary
Machine migration failure testing
e2e/machine_migration_helpers.go, e2e/machine_migration_mapi_authoritative_test.go
Adds createMAPIMachineExpectFailure helper function and introduces a new test context that attempts to create a MAPI Machine when a CAPI Machine with the same name exists, asserting failure with the expected error message.
MachineSet migration failure testing
e2e/machineset_migration_helpers.go, e2e/machineset_migration_mapi_authoritative_test.go
Adds createMAPIMachineSetExpectFailure helper function and converts a pending test (PIt) to an active test (It) that validates MAPI MachineSet creation fails when a CAPI MachineSet with the same name exists.
Enable pending MachineSet test
e2e/machineset_migration_capi_authoritative_test.go
Converts a pending test specification from PIt to It, enabling validation that non-authoritative MAPI MachineSet providerSpec mirrors authoritative CAPI values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Test helper functions follow a consistent, straightforward pattern for failure assertions
  • Changes are isolated to test files with minimal logic density
  • Homogeneous additions across machine and machineset test suites reduce cognitive overhead per file

Poem

🐰 With tests now bold, no more they hide,
We check for fails—the happy side!
When names collide, our helpers see
The errors dance where they should be. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title references adding e2e tests to verify ValidatingAdmissionPolicy, but the actual changes add tests for MAPI Machine and MachineSet migration failure scenarios, not ValidatingAdmissionPolicy validation. Revise the title to accurately reflect the changes, such as: 'Add e2e tests for MAPI Machine and MachineSet migration failure scenarios' or 'OCPCLOUD-2641,OCPCLOUD-3188: verify MAPI migration rejects duplicate CAPI resources'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@openshift-ci-robot
Copy link

openshift-ci-robot commented Dec 1, 2025

@sunzhaohua2: This pull request references OCPCLOUD-2641 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.21.0" version, but no target version was set.

This pull request references OCPCLOUD-3188 which is a valid jira issue.

Details

In response to this:

Summary by CodeRabbit

  • Tests
  • Added new test scenarios to verify that MAPI Machine creation fails when a CAPI Machine with the same name already exists.
  • Added new test scenarios to verify that MAPI MachineSet creation fails when a CAPI MachineSet with the same name already exists.
  • Activated a previously disabled test for non-authoritative MAPI MachineSet provider specification validation.

✏️ 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 (5)
e2e/machineset_migration_capi_authoritative_test.go (1)

61-63: Enabling providerSpec mirror check looks correct

Activating this spec and asserting InstanceType on the MAPI providerSpec matches the authoritative CAPI MachineSet is consistent with the setup in this context and should give good signal on mirror correctness. If you want stronger coverage later, you could extend verifyMAPIMachineSetProviderSpec calls here to check a couple more key fields, but not required for this PR.

e2e/machineset_migration_helpers.go (1)

85-99: Failure helper is consistent with the success path; consider tightening error assertions

The helper mirrors createMAPIMachineSetWithAuthoritativeAPI nicely and gives a clear place to assert admission failures and expected messages. Two optional tweaks you might consider:

  • Assert on the error more directly, e.g. Expect(err).To(MatchError(ContainSubstring(expectedErrorMessage))), to couple the “must fail” and “message” expectations into a single check.
  • If you care about the failure class (e.g. validation vs conflict), you could also assert apierrors.IsInvalid(err)/IsForbidden(err) in addition to the substring to guard against unrelated failures.

Not blocking; current form is perfectly serviceable for these e2e tests.

e2e/machineset_migration_mapi_authoritative_test.go (1)

58-60: Name‑collision failure test is wired correctly

The scenario—pre‑create CAPI MachineSet, then assert MAPI MachineSet creation with the same name fails with the expected message via the helper—matches the intended admission behavior and keeps cleanup on the CAPI side only, which is appropriate for an expected failure.

If you end up adding more of these, you might factor the shared error substring ("a Cluster API MachineSet with the same name already exists") into a package‑level const to avoid brittle duplication, but this is fine as‑is.

e2e/machine_migration_helpers.go (1)

131-168: MAPI machine failure helper matches the existing patterns

This helper lines up well with createMAPIMachineWithAuthority: it selects a worker as a template, scrubs instance‑specific fields, applies the requested authority, and asserts that admission rejects the create with the expected message. That should give you a good place to centralize all “must fail” machine cases.

If you want to tighten it later, you could:

  • Use Expect(cl.Create(...)).To(MatchError(ContainSubstring(expectedErrorMessage))) to express the failure and message expectation in one go.
  • Optionally also assert on the error class (apierrors.IsInvalid/IsForbidden) to distinguish admission rejections from transport issues.

Not required for this PR.

e2e/machine_migration_mapi_authoritative_test.go (1)

32-50: Collision test between CAPI and MAPI Machines is well‑structured

Pre‑creating the CAPI Machine, then asserting that creating a MAPI Machine with the same name fails via createMAPIMachineExpectFailure cleanly exercises the VAP/validation behavior you care about. Cleanup only tracks the CAPI side here, which matches the “no MAPI created” expectation.

If you ever want extra defensiveness against unexpected admission behavior changes, you could extend the helper or this context to best‑effort clean up a successfully created MAPI Machine, but that’s a nice‑to‑have rather than a blocker.

📜 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 3d0f9cd and 5069190.

📒 Files selected for processing (5)
  • e2e/machine_migration_helpers.go (1 hunks)
  • e2e/machine_migration_mapi_authoritative_test.go (1 hunks)
  • e2e/machineset_migration_capi_authoritative_test.go (1 hunks)
  • e2e/machineset_migration_helpers.go (1 hunks)
  • e2e/machineset_migration_mapi_authoritative_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
e2e/machine_migration_helpers.go (2)
e2e/framework/machine.go (1)
  • GetMachines (18-44)
pkg/conversion/mapi2capi/interface.go (1)
  • Machine (24-26)
e2e/machineset_migration_helpers.go (1)
e2e/framework/machineset.go (1)
  • CreateMachineSet (49-94)
e2e/machine_migration_mapi_authoritative_test.go (1)
pkg/conversion/mapi2capi/interface.go (1)
  • Machine (24-26)

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 1, 2025

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

}

// createMAPIMachineExpectFailure attempts to create a MAPI Machine with specified authoritativeAPI and expects the creation to fail.
func createMAPIMachineExpectFailure(ctx context.Context, cl client.Client, machineName string, authority mapiv1beta1.MachineAuthority, expectedErrorMessage string) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit .. Can rename the function as createSameNameMachineBlockedByVAPAuthMapi it would convey exactly what the function is doing without checking its details ?

}

// createMAPIMachineSetExpectFailure attempts to create a MAPI MachineSet with specified authoritativeAPI and expects the creation to fail.
func createMAPIMachineSetExpectFailure(ctx context.Context, cl client.Client, replicas int, machineSetName string, machineSetAuthority mapiv1beta1.MachineAuthority, machineAuthority mapiv1beta1.MachineAuthority, expectedErrorMessage string) {
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above for function name

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