Skip to content

Commit

Permalink
remove tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Sep 29, 2023
1 parent 67e8816 commit 2c954e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 262 deletions.
5 changes: 3 additions & 2 deletions azure/services/aso/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ func (s *Service[T, S]) Reconcile(ctx context.Context) error {
var resultErr error
for _, spec := range s.Specs {
result, err := s.CreateOrUpdateResource(ctx, spec, s.Name())
if err != nil && (!azure.IsOperationNotDoneError(err) || resultErr == nil) {
resultErr = err
if err != nil && (!azure.IsOperationNotDoneError(err) || resultErr == nil) { // TODO: should this be resultErr == zero T ?
resultErr = err // TODO: @nojnhuh: Should we be returning this error instead? resultErr gets overwritten at line 83.
// TODO: also, how do we ensure that this is a transient error?
}
if s.PostCreateOrUpdateResourceHook != nil {
s.PostCreateOrUpdateResourceHook(s.Scope, result, err)
Expand Down
26 changes: 10 additions & 16 deletions azure/services/natgateways/natgateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ import (
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/aso"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const serviceName = "natgateways"

// NatGatewayScope defines the scope interface for NAT gateway service.
type NatGatewayScope interface {
azure.ClusterScoper
azure.AsyncStatusUpdater
aso.Scope
SetNatGatewayIDInSubnets(natGatewayName string, natGatewayID string)
NatGatewaySpecs() []azure.ASOResourceSpecGetter[*asonetworkv1.NatGateway]
aso.Scope // TODO: remove later. Mock should add GetClient() and ClusterName() methods
}

// Service provides operations on azure resources.
Expand All @@ -48,27 +46,23 @@ func New(scope NatGatewayScope) *Service {
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)
}
}
svc.PostCreateOrUpdateResourceHook = natGatewayPostCreateOrUpdateHook
return &Service{
Scope: scope,
Service: svc,
}
}

func (s *Service) GetClient() client.Client {
return s.Scope.GetClient()
}

func (s *Service) ClusterName() string {
return s.Scope.ClusterName()
}

// IsManaged returns true if the ASO NatGateway was created by CAPZ,
// meaning that the NATGateway's lifecycle is managed.
// TODO: where is this called?
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())
}

func natGatewayPostCreateOrUpdateHook(scope NatGatewayScope, result *asonetworkv1.NatGateway, err error) {
if err == nil {
scope.SetNatGatewayIDInSubnets(result.Name, *result.Status.Id)
}
// TODO: log here
}
243 changes: 0 additions & 243 deletions azure/services/natgateways/natgateways_test.go

This file was deleted.

26 changes: 25 additions & 1 deletion azure/services/natgateways/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/aso"
azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)
Expand Down Expand Up @@ -107,7 +108,30 @@ func hasPublicIP(natGateway *asonetworkv1.NatGateway, publicIPName string) bool
}

// WasManaged implements azure.ASOResourceSpecGetter.
// TODO: update WasManaged() after we port Vnet to ASO
func (s *NatGatewaySpec) WasManaged(resource ASOType) bool {
// TODO: this should be updated to use the new tags
// return infrav1.Tags(resource.Status.Tags).HasOwned(s.ClusterName)
return true
}

var _ aso.TagsGetterSetter[*asonetworkv1.NatGateway] = (*NatGatewaySpec)(nil)

// GetAdditionalTags implements aso.TagsGetterSetter.
func (s *NatGatewaySpec) GetAdditionalTags() infrav1.Tags {
return s.AdditionalTags
}

// GetDesiredTags implements aso.TagsGetterSetter.
func (*NatGatewaySpec) GetDesiredTags(resource *asonetworkv1.NatGateway) infrav1.Tags {
return resource.Spec.Tags
}

// GetActualTags implements aso.TagsGetterSetter.
func (*NatGatewaySpec) GetActualTags(resource *asonetworkv1.NatGateway) infrav1.Tags {
return resource.Status.Tags
}

// SetTags implements aso.TagsGetterSetter.
func (*NatGatewaySpec) SetTags(resource *asonetworkv1.NatGateway, tags infrav1.Tags) {
resource.Spec.Tags = tags
}

0 comments on commit 2c954e3

Please sign in to comment.