@@ -19,12 +19,12 @@ package privatedns
1919import (
2020 "context"
2121
22- "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns"
2322 "github.com/pkg/errors"
2423 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2524 "sigs.k8s.io/cluster-api-provider-azure/azure"
2625 "sigs.k8s.io/cluster-api-provider-azure/azure/converters"
2726 "sigs.k8s.io/cluster-api-provider-azure/azure/services/async"
27+ "sigs.k8s.io/cluster-api-provider-azure/azure/services/tags"
2828 "sigs.k8s.io/cluster-api-provider-azure/util/reconciler"
2929 "sigs.k8s.io/cluster-api-provider-azure/util/tele"
3030)
@@ -42,8 +42,7 @@ type Scope interface {
4242// Service provides operations on Azure resources.
4343type Service struct {
4444 Scope Scope
45- zoneGetter async.Getter
46- vnetLinkGetter async.Getter
45+ TagsGetter async.TagsGetter
4746 zoneReconciler async.Reconciler
4847 vnetLinkReconciler async.Reconciler
4948 recordReconciler async.Reconciler
@@ -54,10 +53,10 @@ func New(scope Scope) *Service {
5453 zoneClient := newPrivateZonesClient (scope )
5554 vnetLinkClient := newVirtualNetworkLinksClient (scope )
5655 recordSetsClient := newRecordSetsClient (scope )
56+ tagsClient := tags .NewClient (scope )
5757 return & Service {
5858 Scope : scope ,
59- zoneGetter : zoneClient ,
60- vnetLinkGetter : vnetLinkClient ,
59+ TagsGetter : tagsClient ,
6160 zoneReconciler : async .New (scope , zoneClient , zoneClient ),
6261 vnetLinkReconciler : async .New (scope , vnetLinkClient , vnetLinkClient ),
6362 recordReconciler : async .New (scope , recordSetsClient , recordSetsClient ),
@@ -136,17 +135,18 @@ func (s *Service) Delete(ctx context.Context) error {
136135// isVnetLinkManaged returns true if the vnet link has an owned tag with the cluster name as value,
137136// meaning that the vnet link lifecycle is managed.
138137func (s * Service ) isVnetLinkManaged (ctx context.Context , spec azure.ResourceSpecGetter ) (bool , error ) {
139- result , err := s .vnetLinkGetter .Get (ctx , spec )
138+ scope := azure .VirtualNetworkLinkID (s .Scope .SubscriptionID (), spec .ResourceGroupName (), spec .OwnerResourceName (), spec .ResourceName ())
139+ result , err := s .TagsGetter .GetAtScope (ctx , scope )
140140 if err != nil {
141141 return false , err
142142 }
143143
144- link , ok := result .(privatedns. VirtualNetworkLink )
145- if ! ok {
146- return false , errors . Errorf ( "%T is not a privatedns.VirtualNetworkLink" , link )
144+ tagsMap := make ( map [ string ] * string )
145+ if result . Properties != nil && result . Properties . Tags != nil {
146+ tagsMap = result . Properties . Tags
147147 }
148148
149- tags := converters .MapToTags (link . Tags )
149+ tags := converters .MapToTags (tagsMap )
150150 return tags .HasOwned (s .Scope .ClusterName ()), nil
151151}
152152
@@ -158,15 +158,17 @@ func (s *Service) IsManaged(ctx context.Context) (bool, error) {
158158 return false , errors .Errorf ("no private dns zone spec available" )
159159 }
160160
161- result , err := s .zoneGetter .Get (ctx , zoneSpec )
161+ scope := azure .PrivateDNSZoneID (s .Scope .SubscriptionID (), zoneSpec .ResourceGroupName (), zoneSpec .ResourceName ())
162+ result , err := s .TagsGetter .GetAtScope (ctx , scope )
162163 if err != nil {
163164 return false , err
164165 }
165- zone , ok := result .(privatedns.PrivateZone )
166- if ! ok {
167- return false , errors .Errorf ("%T is not a privatedns.PrivateZone" , zone )
166+
167+ tagsMap := make (map [string ]* string )
168+ if result .Properties != nil && result .Properties .Tags != nil {
169+ tagsMap = result .Properties .Tags
168170 }
169171
170- tags := converters .MapToTags (zone . Tags )
172+ tags := converters .MapToTags (tagsMap )
171173 return tags .HasOwned (s .Scope .ClusterName ()), nil
172174}
0 commit comments