Skip to content

Commit

Permalink
Merge pull request #1676 from whites11/public-ip-single-nic
Browse files Browse the repository at this point in the history
Avoid duplicate NIC for AzureMachine if AllocatePublicIP is set to true.
  • Loading branch information
k8s-ci-robot authored Sep 17, 2021
2 parents 75ff0f4 + 309b102 commit 21141fd
Show file tree
Hide file tree
Showing 2 changed files with 429 additions and 15 deletions.
21 changes: 6 additions & 15 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,17 @@ func (m *MachineScope) NICSpecs() []azure.NICSpec {
}
}

// If Nat Gateway is not enabled, then the NIC needs to reference the LB to get outbound traffic.
if m.Role() == infrav1.Node && !m.Subnet().IsNatGatewayEnabled() {
// If Nat Gateway is not enabled and node has no public IP, then the NIC needs to reference the LB to get outbound traffic.
if m.Role() == infrav1.Node && !m.Subnet().IsNatGatewayEnabled() && !m.AzureMachine.Spec.AllocatePublicIP {
spec.PublicLBName = m.OutboundLBName(m.Role())
spec.PublicLBAddressPoolName = m.OutboundPoolName(m.OutboundLBName(m.Role()))
}
specs := []azure.NICSpec{spec}
if m.AzureMachine.Spec.AllocatePublicIP {
specs = append(specs, azure.NICSpec{
Name: azure.GeneratePublicNICName(m.Name()),
MachineName: m.Name(),
VNetName: m.Vnet().Name,
VNetResourceGroup: m.Vnet().ResourceGroup,
SubnetName: m.AzureMachine.Spec.SubnetName,
PublicIPName: azure.GenerateNodePublicIPName(m.Name()),
VMSize: m.AzureMachine.Spec.VMSize,
AcceleratedNetworking: m.AzureMachine.Spec.AcceleratedNetworking,
})

if m.Role() == infrav1.Node && m.AzureMachine.Spec.AllocatePublicIP {
spec.PublicIPName = azure.GenerateNodePublicIPName(m.Name())
}

return specs
return []azure.NICSpec{spec}
}

// NICNames returns the NIC names.
Expand Down
Loading

0 comments on commit 21141fd

Please sign in to comment.