Skip to content

Commit

Permalink
include postCreateOrUpdateHook
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Sep 28, 2023
1 parent 7af8382 commit c751c16
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion azure/services/natgateways/natgateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package natgateways

import (
"context"

asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
Expand All @@ -42,11 +44,22 @@ type Service struct {

// New creates a new service.
func New(scope NatGatewayScope) *Service {
svc := aso.NewService[*asonetworkv1.NatGateway](serviceName, scope)
svc := aso.NewService[*asonetworkv1.NatGateway, NatGatewayScope](serviceName, scope)
svc.Specs = scope.NatGatewaySpecs()
svc.ConditionType = infrav1.NATGatewaysReadyCondition
svc.PostCreateOrUpdateResourceHook = func(scope NatGatewayScope, result *asonetworkv1.NatGateway, err error) {
if err == nil {
scope.SetNatGatewayIDInSubnets(result.Name, *result.Status.Id)
}
}
return &Service{
Scope: scope,
Service: svc,
}
}

// IsManaged returns true if the ASO NatGateway was created by CAPZ,
// meaning that the NATGateway's lifecycle is managed.
func (s *Service) IsManaged(ctx context.Context, spec azure.ASOResourceSpecGetter[*asonetworkv1.NatGateway]) (bool, error) {
return aso.IsManaged(ctx, s.Scope.GetClient(), spec, s.Scope.ClusterName())
}

0 comments on commit c751c16

Please sign in to comment.