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

OCPBUGS-43724: Fix Load balancer IP setup #9144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions pkg/asset/manifests/azure/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
}

virtualNetworkID := ""
lbip := capz.DefaultInternalLBIPAddress
machineCidr := installConfig.Config.MachineNetwork
// Check if default lbip is within machine network.
isInMachineCIDR := false
for _, cidrRange := range machineCidr {
_, ipnet, err := net.ParseCIDR(cidrRange.CIDR.String())
if err != nil {
return nil, fmt.Errorf("failed to get machine network CIDR: %w", err)
}
if ipnet.Contains(net.ParseIP(lbip)) {
isInMachineCIDR = true
break
}
}

// If not in machine network, assign the first IP in the CIDR to lbip.
if !isInMachineCIDR {
ip, ipnet, err := net.ParseCIDR(machineCidr[0].CIDR.String())
rna-afk marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, fmt.Errorf("failed to get machine network CIDR: %w", err)
}
lbip = ip.Mask(ipnet.Mask).String()
}
lbip, err = getNextAvailableIP(context.TODO(), installConfig, lbip)
if err != nil {
return nil, err
}
apiServerLB.FrontendIPs = []capz.FrontendIP{{
Name: fmt.Sprintf("%s-internal-frontEnd", clusterID.InfraID),
FrontendIPClass: capz.FrontendIPClass{
PrivateIPAddress: lbip,
},
}}
if installConfig.Config.Azure.VirtualNetwork != "" {
client, err := installConfig.Azure.Client()
if err != nil {
Expand All @@ -117,16 +150,12 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
if virtualNetwork != nil {
virtualNetworkID = *virtualNetwork.ID
}
lbip, err := getNextAvailableIP(ctx, installConfig)
lbip, err := getNextAvailableIP(ctx, installConfig, lbip)
if err != nil {
return nil, err
}
apiServerLB.FrontendIPs = []capz.FrontendIP{{
Name: fmt.Sprintf("%s-internal-frontEnd", clusterID.InfraID),
FrontendIPClass: capz.FrontendIPClass{
PrivateIPAddress: lbip,
},
},
apiServerLB.FrontendIPs[0].FrontendIPClass = capz.FrontendIPClass{
PrivateIPAddress: lbip,
}
}

Expand Down Expand Up @@ -255,9 +284,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
}, nil
}

func getNextAvailableIP(ctx context.Context, installConfig *installconfig.InstallConfig) (string, error) {
lbip := capz.DefaultInternalLBIPAddress
machineCidr := installConfig.Config.MachineNetwork
func getNextAvailableIP(ctx context.Context, installConfig *installconfig.InstallConfig, lbip string) (string, error) {
client, err := installConfig.Azure.Client()
if err != nil {
return "", fmt.Errorf("failed to get azure client: %w", err)
Expand All @@ -267,6 +294,7 @@ func getNextAvailableIP(ctx context.Context, installConfig *installconfig.Instal
return "", fmt.Errorf("failed to get azure virtual network client: %w", err)
}

machineCidr := installConfig.Config.MachineNetwork
availableIP, err := vClient.CheckIPAddressAvailability(ctx, installConfig.Config.Azure.NetworkResourceGroupName, installConfig.Config.Azure.VirtualNetwork, lbip)
if err != nil {
return "", fmt.Errorf("failed to get azure ip availability: %w", err)
Expand Down