diff --git a/azure/services/natgateways/client.go b/azure/services/natgateways/client.go index 1f246b2820c..b245b32b2e7 100644 --- a/azure/services/natgateways/client.go +++ b/azure/services/natgateways/client.go @@ -53,14 +53,14 @@ func newClient(auth azure.Authorizer) *azureClient { return &azureClient{c} } -// netNatGatewaysClient creates a new NAT gateways client from subscription ID. +// netNatGatewaysClient creates a new nat gateways client from subscription ID. func netNatGatewaysClient(subscriptionID string, baseURI string, authorizer autorest.Authorizer) network.NatGatewaysClient { natGatewaysClient := network.NewNatGatewaysClientWithBaseURI(baseURI, subscriptionID) azure.SetAutoRestClientDefaults(&natGatewaysClient.Client, authorizer) return natGatewaysClient } -// Get gets the specified NAT gateway. +// Get gets the specified nat gateway. func (ac *azureClient) Get(ctx context.Context, resourceGroupName, natGatewayName string) (network.NatGateway, error) { ctx, _, done := tele.StartSpanWithLogger(ctx, "natgateways.azureClient.Get") defer done() @@ -68,7 +68,7 @@ func (ac *azureClient) Get(ctx context.Context, resourceGroupName, natGatewayNam return ac.natgateways.Get(ctx, resourceGroupName, natGatewayName, "") } -// CreateOrUpdateAsync creates or updates a NAT gateway asynchronously. +// CreateOrUpdateAsync creates or updates a Nat Gateway asynchronously. // It sends a PUT request to Azure and if accepted without error, the func will return a Future which can be used to track the ongoing // progress of the operation. func (ac *azureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.ResourceSpecGetter) (interface{}, azureautorest.FutureAPI, error) { @@ -78,14 +78,14 @@ func (ac *azureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou var existingNatGateway interface{} if existing, err := ac.Get(ctx, spec.ResourceGroupName(), spec.ResourceName()); err != nil && !azure.ResourceNotFound(err) { - return nil, nil, errors.Wrapf(err, "failed to get NAT gateway %s for %s in %s", spec.ResourceName(), spec.OwnerResourceName(), spec.ResourceGroupName()) + return nil, nil, errors.Wrapf(err, "failed to get Nat Gateway %s for %s in %s", spec.ResourceName(), spec.OwnerResourceName(), spec.ResourceGroupName()) } else if err == nil { existingNatGateway = existing } params, err := spec.Parameters(existingNatGateway) if err != nil { - return nil, nil, errors.Wrapf(err, "failed to get desired parameters for NAT gateway %s", spec.ResourceName()) + return nil, nil, errors.Wrapf(err, "failed to get desired parameters for Nat Gateway %s", spec.ResourceName()) } natGateway, ok := params.(network.NatGateway) @@ -118,7 +118,7 @@ func (ac *azureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou return result, nil, err } -// DeleteAsync deletes a NAT gateway asynchronously. DeleteAsync sends a DELETE +// DeleteAsync deletes a Nat Gateway asynchronously. DeleteAsync sends a DELETE // request to Azure and if accepted without error, the func will return a Future which can be used to track the ongoing // progress of the operation. func (ac *azureClient) DeleteAsync(ctx context.Context, spec azure.ResourceSpecGetter) (azureautorest.FutureAPI, error) { @@ -146,19 +146,22 @@ func (ac *azureClient) DeleteAsync(ctx context.Context, spec azure.ResourceSpecG // IsDone returns true if the long-running operation has completed. func (ac *azureClient) IsDone(ctx context.Context, future azureautorest.FutureAPI) (bool, error) { - ctx, _, done := tele.StartSpanWithLogger(ctx, "natgateways.Service.DeleteAsync") + ctx, _, done := tele.StartSpanWithLogger(ctx, "natgateways.Service.IsDone") defer done() - done, err := future.DoneWithContext(ctx, ac.natgateways) + isDone, err := future.DoneWithContext(ctx, ac.natgateways) if err != nil { return false, errors.Wrap(err, "failed checking if the operation was complete") } - return done, nil + return isDone, nil } // Result fetches the result of a long-running operation future. func (ac *azureClient) Result(ctx context.Context, futureData azureautorest.FutureAPI, futureType string) (interface{}, error) { + _, _, done := tele.StartSpanWithLogger(ctx, "natgateways.Service.Result") + defer done() + if futureData == nil { return nil, errors.Errorf("cannot get result from nil future") } diff --git a/azure/services/natgateways/natgateways.go b/azure/services/natgateways/natgateways.go index 49275857191..64b1775d54b 100644 --- a/azure/services/natgateways/natgateways.go +++ b/azure/services/natgateways/natgateways.go @@ -75,16 +75,14 @@ func (s *Service) Reconcile(ctx context.Context) error { } } if err == nil && resultingErr != nil { - // TODO: consider making OwnerResourceName() a no-op - subnetSpec := s.Scope.Subnet(natGatewaySpec.OwnerResourceName()) networkNatGateway, ok := natGateway.(network.NatGateway) if !ok { // Return out of loop since this would be an unexpcted fatal error return errors.Errorf("created resource %T is not a network.NatGateway", natGateway) } + // TODO: is it necessary to set the spec since it doesn't appear to change any behavior - subnetSpec.NatGateway.ID = *networkNatGateway.ID - s.Scope.SetSubnet(subnetSpec) + s.SetNatGatewayIDInSubnets(natGatewaySpec.ResourceName(), *networkNatGateway.ID) } } @@ -116,12 +114,11 @@ func (s *Service) Delete(ctx context.Context) error { return result } -func (s *Service) SetNatGatewayID(name string, id string) { +func (s *Service) SetNatGatewayIDInSubnets(name string, id string) { for _, subnet := range s.Scope.Subnets() { if subnet.NatGateway.Name == name { subnet.NatGateway.ID = id s.Scope.SetSubnet(subnet) - // s.AzureCluster.Spec.NetworkSpec.Subnets[i] = id } } }