Skip to content

check if a source NAT IP address is needed before assigning one - #12408

Closed
DaanHoogland wants to merge 1 commit into
apache:4.20from
shapeblue:ghi10122-routedModeWithSourceNAT
Closed

check if a source NAT IP address is needed before assigning one#12408
DaanHoogland wants to merge 1 commit into
apache:4.20from
shapeblue:ghi10122-routedModeWithSourceNAT

Conversation

@DaanHoogland

Copy link
Copy Markdown
Contributor

Description

This PR...

Fixes: #10122

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Jan 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.26%. Comparing base (549daae) to head (c38f3cc).

Files with missing lines Patch % Lines
...n/java/com/cloud/network/IpAddressManagerImpl.java 0.00% 17 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #12408      +/-   ##
============================================
- Coverage     16.26%   16.26%   -0.01%     
  Complexity    13434    13434              
============================================
  Files          5667     5667              
  Lines        500731   500737       +6     
  Branches      60803    60808       +5     
============================================
- Hits          81455    81447       -8     
- Misses       410172   410182      +10     
- Partials       9104     9108       +4     
Flag Coverage Δ
uitests 4.14% <ø> (ø)
unittests 17.12% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16344

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #10122 regarding incorrect IP address labeling as "Source NAT" in Routed VPC networks. The main change introduces logic to check if a network is routed before assigning a source NAT IP address, which prevents unnecessary source NAT IP allocation for routed networks where Source NAT service is not applicable.

Changes:

  • Adds new isRouted() method to determine if a network uses routing mode
  • Updates assignSourceNatIpAddressToGuestNetwork() to conditionally assign source NAT based on routing mode
  • Updates isSourceNatAvailableForNetwork() to treat networks with routing mode as having shared source NAT
  • Includes extensive code cleanup: removes unused imports and fields, applies diamond operators, and simplifies conditional logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java
@weizhouapache

Copy link
Copy Markdown
Member

@DaanHoogland
as I understand, #10122 is a UI issue.
Does this PR fix other issues ?

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@DaanHoogland as I understand, #10122 is a UI issue. Does this PR fix other issues ?

it is not a pure UI issue. The IP address is marked as source NAT in the DB. I am not sure if this addresses all scenarios yet, but it will prevent marking the primary IP for a ROUTED-mode network as source NAT.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Outdated
Comment on lines +1037 to +1050
private boolean isRouted(Network guestNetwork) {
VpcOffering vpcOffer = null;
NetworkOffering netOffer = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
if (netOffer == null) {
throw new CloudRuntimeException("network without offering found???");
}
if (netOffer.isForVpc() && guestNetwork.getVpcId() != null) {
VpcVO vpc = _vpcDao.findById(guestNetwork.getVpcId());
if (vpc != null) {
vpcOffer = vpcOfferingDao.findById(vpc.getVpcOfferingId());
}
}
return netOffer.getRoutingMode() != null || (vpcOffer != null && vpcOffer.getRoutingMode() != null);
}

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

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

The new isRouted method lacks test coverage. Since the repository has comprehensive test coverage for IpAddressManagerImpl (see IpAddressManagerTest.java), consider adding unit tests to verify:

  1. The method correctly identifies routed networks based on NetworkOffering routing mode
  2. The method correctly identifies routed VPC networks based on VPC offering routing mode
  3. Edge cases like null VPC or null VPC offering are handled properly

Copilot uses AI. Check for mistakes.
@DaanHoogland
DaanHoogland force-pushed the ghi10122-routedModeWithSourceNAT branch from 7274c9e to 519b8cf Compare January 14, 2026 15:19
@weizhouapache

Copy link
Copy Markdown
Member

@DaanHoogland as I understand, #10122 is a UI issue. Does this PR fix other issues ?

it is not a pure UI issue. The IP address is marked as source NAT in the DB. I am not sure if this addresses all scenarios yet, but it will prevent marking the primary IP for a ROUTED-mode network as source NAT.

ok @DaanHoogland
it is becoming a PR with big impact then.

as I understand, what @msinhore wanted is the change of label of public IP. source nat of routed network confuses users, need to change to "external gateway" or so
what ACS saves into database and how it is processed in the service layer are not very important.

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@DaanHoogland as I understand, #10122 is a UI issue. Does this PR fix other issues ?

it is not a pure UI issue. The IP address is marked as source NAT in the DB. I am not sure if this addresses all scenarios yet, but it will prevent marking the primary IP for a ROUTED-mode network as source NAT.

ok @DaanHoogland it is becoming a PR with big impact then.

as I understand, what @msinhore wanted is the change of label of public IP. source nat of routed network confuses users, need to change to "external gateway" or so what ACS saves into database and how it is processed in the service layer are not very important.

isSourceNat is a flag returned to the UI, if we do not change it in the service we have to honour that flag conditionally. Not a very clean solution either and technical debt at the same time. I would suggest we fix it good or not.

@weizhouapache

Copy link
Copy Markdown
Member

@DaanHoogland as I understand, #10122 is a UI issue. Does this PR fix other issues ?

it is not a pure UI issue. The IP address is marked as source NAT in the DB. I am not sure if this addresses all scenarios yet, but it will prevent marking the primary IP for a ROUTED-mode network as source NAT.

ok @DaanHoogland it is becoming a PR with big impact then.
as I understand, what @msinhore wanted is the change of label of public IP. source nat of routed network confuses users, need to change to "external gateway" or so what ACS saves into database and how it is processed in the service layer are not very important.

isSourceNat is a flag returned to the UI, if we do not change it in the service we have to honour that flag conditionally. Not a very clean solution either and technical debt at the same time. I would suggest we fix it good or not.

ok.
please bear in mind, Routed network requires a public IP for VR, as external gateway IP.
you can set isSourceNat to false in response, but may need to add another flag, for example isGateway which is set to true.

a simple workaround on UI

  • if IP is source nat,
    • if network is Routed, display "external gateway"
    • if not, display "source nat"
  • xxx

@weizhouapache weizhouapache added this to the 4.20.4 milestone May 7, 2026
@DaanHoogland
DaanHoogland force-pushed the ghi10122-routedModeWithSourceNAT branch from 519b8cf to c38f3cc Compare August 4, 2026 07:34
@DaanHoogland
DaanHoogland marked this pull request as draft August 4, 2026 07:48
@weizhouapache

Copy link
Copy Markdown
Member

@DaanHoogland
actually, an IP address from the public IP range is still required for a routed network.

However, it is not used for Source NAT. Instead, it is used to establish routing between the virtual router and the upstream router.

In my opinion, we only need to change the label of Public IP addresses for Routed network or VPC on UI.
image

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong IP Address Name label for Public IP address in Routed VPC Network

4 participants