Skip to content

Conversation

@stephenfin
Copy link
Contributor

@stephenfin stephenfin commented Oct 9, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Prevented emitting invalid network configurations when no network/filter is provided.
    • Ensured ports include network details only when a network or subnet is explicitly present.
    • Improved subnet-only handling to avoid attaching empty network fields.
    • Clarified error messages when neither network nor subnet are properly referenced.
  • Stability

    • Reduced misconfiguration risk by only producing network/subnet settings when input data exists.
  • Tests

    • Strengthened fuzz tests to cover empty-filter and subnet-present network cases.

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Oct 9, 2025
@openshift-ci-robot
Copy link

@stephenfin: This pull request references Jira Issue OCPBUGS-62892, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @sunzhaohua2

The bug has been updated to refer to the pull request using the external bug tracker.

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.

@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

Walkthrough

MAPI↔CAPO OpenStack conversion logic was made stricter: network, filter, subnet, fixed IP, and port tag fields are only populated when corresponding input data exists; nil checks and guarded assignments were added in both conversion directions; fuzz test network case adjusted to use an empty UUID with a Filter and SubnetParam.

Changes

Cohort / File(s) Summary of Changes
MAPI → CAPO conversion
pkg/conversion/mapi2capi/openstack.go
- Introduced local capoNetwork, capoSubnet, capoPort, and capoFixedIP and populate them only when input fields exist
- Assign capoNetwork.ID when MAPI network UUID exists
- Populate capoNetwork.Filter (and compute ProjectID) only if MAPI Filter is non-empty
- For subnet-only paths, avoid emitting network config; build capoPort.Tags, per-subnet capoSubnet, and conditional capoFixedIP only when relevant fields exist
- Ensure final PortOpts uses capoFixedIPs and capoNetwork only when built
CAPO → MAPI conversion
pkg/conversion/capi2mapi/openstack.go
- Added explicit nil check on capoPort.Network and guarded handling of Network.ID vs Network.Filter (map UUID or populate Filter fields)
- If capoPort.Network is nil and no FixedIPs, record an error requiring network or subnet reference
- Assign port tags to MAPI subnet (PortTags) and populate subnet Filter fully when present; otherwise use UUID-based SubnetParam
- Broadened condition to convert network when network has ID/filter or when FixedIPs reference a subnet
Fuzz tests
pkg/conversion/mapi2capi/openstack_fuzz_test.go
- Modified fuzz case 0: set network.UUID to empty string, initialize network.Filter as an empty Filter, and add Subnets containing a generated SubnetParam (previously set UUID only)

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant M2C as convertMAPONetworksToCAPO
  participant Builder as CAPO Port Builder

  Caller->>M2C: convert MAPI network(s)
  activate M2C

  M2C->>M2C: iterate networks
  alt network.UUID present
    M2C->>Builder: set capoNetwork.ID
  end
  alt network.Filter non-empty
    M2C->>M2C: compute ProjectID
    M2C->>Builder: set capoNetwork.Filter
  else Filter empty
    note right of M2C: skip Filter population
  end

  alt no network but subnets present
    M2C->>M2C: for each subnet build capoSubnet and capoFixedIP only if fields exist
    M2C->>Builder: append capoFixedIP(s)
  else network present
    M2C->>Builder: attach capoNetwork and capoFixedIPs (if any)
  end

  M2C-->>Caller: CAPO Port/Network objects
  deactivate M2C
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant C2M as convertCAPOPortOptsToMAPO
  participant Builder as MAPI Network Builder

  Caller->>C2M: convert CAPO PortOpts
  activate C2M

  C2M->>C2M: inspect capoPort.Network
  alt capoPort.Network != nil
    opt Network.ID
      C2M->>Builder: set mapoNetwork.UUID from ID
    end
    opt Network.Filter
      C2M->>Builder: set mapoNetwork.Filter (tags, not-tags, projectID...)
    end
    alt neither ID nor Filter
      C2M->>Caller: record error "A network must be referenced by a UUID or filter"
    end
  else capoPort.Network == nil
    alt capoPort.FixedIPs present
      C2M->>C2M: set PortTags, build mapoSubnet(s) from FixedIPs (UUID or Filter)
      C2M->>Builder: attach subnet params
    else
      C2M->>Caller: record error "A network must be referenced by a UUID or filter, else a subnet must be referenced"
    end
  end

  C2M-->>Caller: MAPI network/port spec or errors
  deactivate C2M
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I twitch my whiskers, check each gate,
Only when fields exist do I populate.
Nets and subs now hop in place,
No phantom IDs left to chase.
A tidy rabbit guards each space. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely references the linked JIRA issue and clearly summarizes the primary change of handling empty MAPO network subnets in the OpenStack conversion logic, reflecting the pull request’s main purpose without extraneous detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent 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 c8b86ab and 6004d19.

📒 Files selected for processing (3)
  • pkg/conversion/capi2mapi/openstack.go (4 hunks)
  • pkg/conversion/mapi2capi/openstack.go (6 hunks)
  • pkg/conversion/mapi2capi/openstack_fuzz_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/conversion/mapi2capi/openstack_fuzz_test.go
🔇 Additional comments (2)
pkg/conversion/capi2mapi/openstack.go (2)

357-387: Network nil/guarded handling LGTM.

Clear errors for missing network or subnet reference; good tightening.


603-614: Broadened network/subnet selection logic LGTM.

Correctly treats “no network but FixedIPs with subnet” as a networks case.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@openshift-ci openshift-ci bot requested a review from sunzhaohua2 October 9, 2025 12:12
@openshift-ci-robot
Copy link

@stephenfin: This pull request references Jira Issue OCPBUGS-62892, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @sunzhaohua2

In response to this:

Summary by CodeRabbit

  • Bug Fixes

  • Subnets without identifiers are now skipped with a clear warning, preventing invalid network configurations.

  • Corrected tag application to occur per subnet after ID resolution, ensuring tags are only applied to valid subnets.

  • Reduced risk of creating incorrect OpenStack port configurations from incomplete subnet data.

  • Tests

  • Added coverage to verify warnings and behavior when subnets lack identifiers.

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 mdbooth and nrb October 9, 2025 12:16
@damdo
Copy link
Member

damdo commented Oct 9, 2025

/assign @mdbooth

@damdo
Copy link
Member

damdo commented Oct 9, 2025

/test ?

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 9, 2025

@damdo: The following commands are available to trigger required jobs:

/test build
/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-upgrade
/test e2e-gcp-capi-techpreview
/test e2e-gcp-ovn-techpreview
/test e2e-openstack-capi-techpreview
/test e2e-openstack-ovn-techpreview
/test e2e-vsphere-capi-techpreview
/test images
/test lint
/test okd-scos-images
/test unit
/test vendor
/test verify-deps

The following commands are available to trigger optional jobs:

/test e2e-azure-ovn-techpreview
/test e2e-metal3-capi-techpreview
/test okd-scos-e2e-aws-ovn
/test regression-clusterinfra-aws-ipi-techpreview-capi

Use /test all to run the following jobs that were automatically triggered:

pull-ci-openshift-cluster-capi-operator-main-build
pull-ci-openshift-cluster-capi-operator-main-images
pull-ci-openshift-cluster-capi-operator-main-lint
pull-ci-openshift-cluster-capi-operator-main-okd-scos-e2e-aws-ovn
pull-ci-openshift-cluster-capi-operator-main-okd-scos-images
pull-ci-openshift-cluster-capi-operator-main-unit
pull-ci-openshift-cluster-capi-operator-main-vendor
pull-ci-openshift-cluster-capi-operator-main-verify-deps

In response to this:

/test ?

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.

@damdo
Copy link
Member

damdo commented Oct 9, 2025

/test e2e-openstack-capi-techpreview

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 9, 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 ask for approval from mdbooth. For more information see the Code Review Process.

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

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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.

I think this fix is good. I think we also need need to fix subnetid if we want the test to pass, though.

Signed-off-by: Stephen Finucane <[email protected]>
@stephenfin
Copy link
Contributor Author

/test e2e-openstack-capi-techpreview

@damdo
Copy link
Member

damdo commented Oct 13, 2025

@stephenfin @mdbooth It looks like E2Es passed on ci/prow/e2e-openstack-capi-techpreview but the overall job failed due to a gather step failure (which might be recurrent and worth fixing, although not in this PR :) )

@mdbooth if you are happy with the latest changes I think we should be ok overriding and merging.

@stephenfin
Copy link
Contributor Author

@stephenfin @mdbooth It looks like E2Es passed on ci/prow/e2e-openstack-capi-techpreview but the overall job failed due to a gather step failure (which might be recurrent and worth fixing, although not in this PR :) )

Ah, yes, we fixed that this morning openshift/release#70212. This job must have started before that patch merged. It's merged now though so let's re-run.

/test e2e-openstack-capi-techpreview

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.

If you have time I still think there's a bunch of cleanup to do here. In particular I think this change highlights a latent panic which ideally we would fix.

However, given that it fixes an immediate problem I wouldn't want to hold it up for the issues here. Please consider having somebody on the team follow up, though.

/lgtm

// TenantID is deprecated and covered by ProjectID so we don't set it
if capoPort.Network != nil {
switch {
case capoPort.Network != nil && capoPort.Network.ID != nil:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the capoPort.Network != nil is redundant now we're guarding the whole switch.

} else if len(capoPort.FixedIPs) == 0 {
// TODO(OSASINFRA-3779): Add VAP to prevent usage of the below field.
errors = append(errors, field.Invalid(fldPath.Child("network"), capoPort.Network, "A network must be referenced by a UUID or filter"))
errors = append(errors, field.Invalid(fldPath.Child("network"), capoPort.Network, "A network must be referenced by a UUID or filter, else a subnet must be referenced"))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think it would be less confusing to say 'Either network or fixedIPs must be specified on a port'. The bit about UUID and filter doesn't have any context here.

mapoSubnet := mapiv1alpha1.SubnetParam{
UUID: *capoFixedIP.Subnet.ID,
Filter: mapiv1alpha1.SubnetFilter{
UUID: *capoFixedIP.Subnet.ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate this isn't new, but what stops us panicing here if the subnet is specified by filter instead of ID? Do we have test coverage of this?

if projectID == "" {
projectID = mapoNetwork.Filter.TenantID
}
if (mapoNetwork.Filter != mapiv1alpha1.Filter{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's an error for a network to specify both ID and filter. Filter is redundant if we specified ID, so we could add an additional guard here that networkID is not set.


// convert .Subnets
if networkID == "" && (mapoNetwork.Filter == mapiv1alpha1.Filter{}) { //nolint:nestif
if (capoNetwork == openstackv1.NetworkParam{}) { //nolint:nestif
Copy link
Contributor

Choose a reason for hiding this comment

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

Code structure observation. We have:

capoNetwork := switch {
  case mapoNetwork.UUID != "":
    addCAPOSubnets(capoNetwork{ID = &mapoNetwork.UUID}, ...)

  case mapoNetwork.Filter != nil:
    addCAPOSubnets(capoNetworkFromFilter(), ...)

  default:
    capoNetworkFromSubnets() (this if statement, which is the default/else of the above)
}

addCAPOSubnets() is the else branch starting line 483 below.

}
}

capoFixedIP := openstackv1.FixedIP{}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This doesn't seem to be doing anything outside the if block below. You could move it in there.


//nolint:funlen
func convertMAPONetworksToCAPO(fldPath *field.Path, mapoNetworks []mapiv1alpha1.NetworkParam) ([]openstackv1.PortOpts, []string, field.ErrorList) { //nolint:gocognit,cyclop
func convertMAPONetworksToCAPO(fldPath *field.Path, mapoNetworks []mapiv1alpha1.NetworkParam) ([]openstackv1.PortOpts, []string, field.ErrorList) { //nolint:gocognit,cyclop,gocyclo
Copy link
Contributor

Choose a reason for hiding this comment

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

I have to agree with the linter here: this function is getting hard to read!

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 14, 2025
@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 Oct 14, 2025

@stephenfin: 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-aws-ovn-techpreview 6004d19 link true /test e2e-aws-ovn-techpreview
ci/prow/e2e-openstack-ovn-techpreview 6004d19 link true /test e2e-openstack-ovn-techpreview

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@damdo
Copy link
Member

damdo commented Oct 24, 2025

Hey @stephenfin what's the plan for this one? TY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. 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.

4 participants