Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #57861: Use existing subnetwork of forwarding rule #58110

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/cloudprovider/providers/gce/gce_loadbalancer_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,18 @@ func (gce *GCECloud) ensureInternalLoadBalancer(clusterName, clusterID string, s
requestedIP := determineRequestedIP(svc, existingFwdRule)
ipToUse := requestedIP

// If the ILB already exists, continue using the subnet that it's already using.
// This is to support existing ILBs that were setup using the wrong subnet.
subnetworkURL := gce.SubnetworkURL()
if existingFwdRule != nil && existingFwdRule.Subnetwork != "" {
// external LBs have an empty Subnetwork field.
subnetworkURL = existingFwdRule.Subnetwork
}

var addrMgr *addressManager
// If the network is not a legacy network, use the address manager
if !gce.IsLegacyNetwork() {
addrMgr = newAddressManager(gce, nm.String(), gce.Region(), gce.SubnetworkURL(), loadBalancerName, requestedIP, schemeInternal)
addrMgr = newAddressManager(gce, nm.String(), gce.Region(), subnetworkURL, loadBalancerName, requestedIP, schemeInternal)
ipToUse, err = addrMgr.HoldAddress()
if err != nil {
return nil, err
Expand All @@ -108,9 +116,10 @@ func (gce *GCECloud) ensureInternalLoadBalancer(clusterName, clusterID string, s
LoadBalancingScheme: string(scheme),
}

// Specify subnetwork if known
if len(gce.subnetworkURL) > 0 {
expectedFwdRule.Subnetwork = gce.subnetworkURL
// Given that CreateGCECloud will attempt to determine the subnet based off the network,
// the subnetwork should rarely be unknown.
if subnetworkURL != "" {
expectedFwdRule.Subnetwork = subnetworkURL
} else {
expectedFwdRule.Network = gce.networkURL
}
Expand Down