Skip to content

Commit

Permalink
change the signature of PublicIPSpecs method to return []azure.Resour…
Browse files Browse the repository at this point in the history
…ceSpecGetter instead of []publicips.PublicIPSpec

Signed-off-by: Karuppiah Natarajan <[email protected]>
  • Loading branch information
karuppiah7890 committed Oct 3, 2021
1 parent f2c9079 commit e62c522
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
22 changes: 11 additions & 11 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ func (s *ClusterScope) Authorizer() autorest.Authorizer {
}

// PublicIPSpecs returns the public IP specs.
func (s *ClusterScope) PublicIPSpecs() []publicips.PublicIPSpec {
var publicIPSpecs []publicips.PublicIPSpec
func (s *ClusterScope) PublicIPSpecs() []azure.ResourceSpecGetter {
var publicIPSpecs []azure.ResourceSpecGetter

// Public IP specs for control plane lb
var controlPlaneOutboundIPSpecs []publicips.PublicIPSpec
var controlPlaneOutboundIPSpecs []azure.ResourceSpecGetter
if s.IsAPIServerPrivate() {
// Public IP specs for control plane outbound lb
if s.ControlPlaneOutboundLB() != nil {
controlPlaneOutboundIPSpecs = s.getOutboundLBPublicIPSpecs(s.ControlPlaneOutboundLB(), azure.GenerateControlPlaneOutboundIPName)
}
} else {
controlPlaneOutboundIPSpecs = []publicips.PublicIPSpec{{
controlPlaneOutboundIPSpecs = []azure.ResourceSpecGetter{&publicips.PublicIPSpec{
Name: s.APIServerPublicIP().Name,
DNSName: s.APIServerPublicIP().DNSName,
IsIPv6: false, // currently azure requires a ipv4 lb rule to enable ipv6
Expand All @@ -148,10 +148,10 @@ func (s *ClusterScope) PublicIPSpecs() []publicips.PublicIPSpec {
}

// Public IP specs for node nat gateways
var nodeNatGatewayIPSpecs []publicips.PublicIPSpec
var nodeNatGatewayIPSpecs []azure.ResourceSpecGetter
for _, subnet := range s.NodeSubnets() {
if subnet.IsNatGatewayEnabled() {
nodeNatGatewayIPSpecs = append(nodeNatGatewayIPSpecs, publicips.PublicIPSpec{
nodeNatGatewayIPSpecs = append(nodeNatGatewayIPSpecs, &publicips.PublicIPSpec{
Name: subnet.NatGateway.NatGatewayIP.Name,
DNSName: subnet.NatGateway.NatGatewayIP.DNSName,
ResourceGroup: s.ResourceGroup(),
Expand All @@ -166,7 +166,7 @@ func (s *ClusterScope) PublicIPSpecs() []publicips.PublicIPSpec {

if s.AzureCluster.Spec.BastionSpec.AzureBastion != nil {
// public IP for Azure Bastion.
azureBastionPublicIP := publicips.PublicIPSpec{
azureBastionPublicIP := &publicips.PublicIPSpec{
Name: s.AzureCluster.Spec.BastionSpec.AzureBastion.PublicIP.Name,
DNSName: s.AzureCluster.Spec.BastionSpec.AzureBastion.PublicIP.DNSName,
ResourceGroup: s.ResourceGroup(),
Expand Down Expand Up @@ -697,13 +697,13 @@ func (s *ClusterScope) SetDNSName() {
}

// getOutboundLBPublicIPSpecs returns the public ip specs for a LoadBalancerSpec based on the number of frontend ips configured.
func (s *ClusterScope) getOutboundLBPublicIPSpecs(outboundLB *infrav1.LoadBalancerSpec, generateOutboundIPName func(string) string) []publicips.PublicIPSpec {
var outboundIPSpecs []publicips.PublicIPSpec
func (s *ClusterScope) getOutboundLBPublicIPSpecs(outboundLB *infrav1.LoadBalancerSpec, generateOutboundIPName func(string) string) []azure.ResourceSpecGetter {
var outboundIPSpecs []azure.ResourceSpecGetter
loadBalancerNodeOutboundIPs := outboundLB.FrontendIPsCount
if loadBalancerNodeOutboundIPs == nil || *loadBalancerNodeOutboundIPs == 0 {
// do nothing
} else if *loadBalancerNodeOutboundIPs == 1 {
outboundIPSpecs = append(outboundIPSpecs, publicips.PublicIPSpec{
outboundIPSpecs = append(outboundIPSpecs, &publicips.PublicIPSpec{
Name: generateOutboundIPName(s.ClusterName()),
ResourceGroup: s.ResourceGroup(),
Location: s.Location(),
Expand All @@ -713,7 +713,7 @@ func (s *ClusterScope) getOutboundLBPublicIPSpecs(outboundLB *infrav1.LoadBalanc
})
} else {
for i := 0; i < int(*loadBalancerNodeOutboundIPs); i++ {
outboundIPSpecs = append(outboundIPSpecs, publicips.PublicIPSpec{
outboundIPSpecs = append(outboundIPSpecs, &publicips.PublicIPSpec{
Name: azure.WithIndex(generateOutboundIPName(s.ClusterName()), i+1),
ResourceGroup: s.ResourceGroup(),
Location: s.Location(),
Expand Down
6 changes: 3 additions & 3 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func (m *MachineScope) TagsSpecs() []azure.TagsSpec {
}

// PublicIPSpecs returns the public IP specs.
func (m *MachineScope) PublicIPSpecs() []publicips.PublicIPSpec {
var spec []publicips.PublicIPSpec
func (m *MachineScope) PublicIPSpecs() []azure.ResourceSpecGetter {
var spec []azure.ResourceSpecGetter
if m.AzureMachine.Spec.AllocatePublicIP {
spec = append(spec, publicips.PublicIPSpec{
spec = append(spec, &publicips.PublicIPSpec{
Name: azure.GenerateNodePublicIPName(m.Name()),
ResourceGroup: m.ResourceGroup(),
Location: m.Location(),
Expand Down
6 changes: 3 additions & 3 deletions azure/services/publicips/mock_publicips/publicips_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions azure/services/publicips/publicips.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type PublicIPScope interface {
logr.Logger
azure.ClusterDescriber
azure.AsyncStatusUpdater
PublicIPSpecs() []PublicIPSpec
PublicIPSpecs() []azure.ResourceSpecGetter
}

// Service provides operations on Azure resources.
Expand Down Expand Up @@ -68,7 +68,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
var result error

for _, ipSpec := range s.Scope.PublicIPSpecs() {
if err := async.CreateResource(ctx, s.Scope, s.Client, &ipSpec, serviceName); err != nil {
if err := async.CreateResource(ctx, s.Scope, s.Client, ipSpec, serviceName); err != nil {
if !azure.IsOperationNotDoneError(err) || result == nil {
result = err
}
Expand All @@ -95,7 +95,7 @@ func (s *Service) Delete(ctx context.Context) error {
var result error

for _, ipSpec := range s.Scope.PublicIPSpecs() {
managed, err := s.isIPManaged(ctx, ipSpec.Name)
managed, err := s.isIPManaged(ctx, ipSpec.ResourceName())
if err != nil {
if azure.ResourceNotFound(err) {
// public ip already deleted or doesn't exist
Expand All @@ -107,11 +107,11 @@ func (s *Service) Delete(ctx context.Context) error {
}

if !managed {
s.Scope.V(2).Info("Skipping IP deletion for unmanaged public IP", "public ip", ipSpec.Name)
s.Scope.V(2).Info("Skipping IP deletion for unmanaged public IP", "public ip", ipSpec.ResourceName())
continue
}

if err = async.DeleteResource(ctx, s.Scope, s.Client, &ipSpec, serviceName); err != nil {
if err = async.DeleteResource(ctx, s.Scope, s.Client, ipSpec, serviceName); err != nil {
if !azure.IsOperationNotDoneError(err) || result == nil {
result = err
}
Expand Down

0 comments on commit e62c522

Please sign in to comment.