@@ -39,6 +39,7 @@ import (
3939
4040 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
4141 armcompute "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
42+ "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
4243 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
4344 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions"
4445
@@ -58,6 +59,7 @@ type perItOrDescribeTestContext struct {
5859 armComputeClientFactory * armcompute.ClientFactory
5960 armResourcesClientFactory * armresources.ClientFactory
6061 armSubscriptionsClientFactory * armsubscriptions.ClientFactory
62+ armNetworkClientFactory * armnetwork.ClientFactory
6163 graphClient * graphutil.Client
6264
6365 timingMetadata timing.SpecTimingMetadata
@@ -349,6 +351,11 @@ func (tc *perItOrDescribeTestContext) cleanupResourceGroup(ctx context.Context,
349351 return err
350352 }
351353
354+ networkClientFactory , err := tc .GetARMNetworkClientFactory (ctx )
355+ if err != nil {
356+ return err
357+ }
358+
352359 hcpClientFactory , err := tc .Get20240610ClientFactory (ctx )
353360 if err != nil {
354361 return err
@@ -371,7 +378,7 @@ func (tc *perItOrDescribeTestContext) cleanupResourceGroup(ctx context.Context,
371378 }
372379
373380 ginkgo .GinkgoLogr .Info ("deleting resource group" , "resourceGroup" , resourceGroupName )
374- if err := DeleteResourceGroup (ctx , resourceClientFactory .NewResourceGroupsClient (), resourceGroupName , false , timeout ); err != nil {
381+ if err := DeleteResourceGroup (ctx , resourceClientFactory .NewResourceGroupsClient (), networkClientFactory , resourceGroupName , false , timeout ); err != nil {
375382 return fmt .Errorf ("failed to cleanup resource group: %w" , err )
376383 }
377384
@@ -398,14 +405,19 @@ func (tc *perItOrDescribeTestContext) cleanupResourceGroupNoRP(ctx context.Conte
398405 return fmt .Errorf ("failed to search for managed resource groups: %w" , err )
399406 }
400407
401- clientFactory , err := tc .GetARMResourcesClientFactory (ctx )
408+ resourceClientFactory , err := tc .GetARMResourcesClientFactory (ctx )
409+ if err != nil {
410+ return err
411+ }
412+
413+ networkClientFactory , err := tc .GetARMNetworkClientFactory (ctx )
402414 if err != nil {
403415 return err
404416 }
405417
406418 for _ , managedRG := range managedResourceGroups {
407419 ginkgo .GinkgoLogr .Info ("deleting managed resource group" , "resourceGroup" , managedRG , "parentResourceGroup" , resourceGroupName )
408- if err := DeleteResourceGroup (ctx , clientFactory .NewResourceGroupsClient (), managedRG , true , timeout ); err != nil {
420+ if err := DeleteResourceGroup (ctx , resourceClientFactory .NewResourceGroupsClient (), networkClientFactory , managedRG , true , timeout ); err != nil {
409421 if isIgnorableResourceGroupCleanupError (err ) {
410422 ginkgo .GinkgoLogr .Info ("ignoring not found resource group" , "resourceGroup" , managedRG )
411423 } else {
@@ -415,7 +427,7 @@ func (tc *perItOrDescribeTestContext) cleanupResourceGroupNoRP(ctx context.Conte
415427 }
416428
417429 ginkgo .GinkgoLogr .Info ("deleting resource group" , "resourceGroup" , resourceGroupName )
418- if err := DeleteResourceGroup (ctx , clientFactory .NewResourceGroupsClient (), resourceGroupName , false , timeout ); err != nil {
430+ if err := DeleteResourceGroup (ctx , resourceClientFactory .NewResourceGroupsClient (), networkClientFactory , resourceGroupName , false , timeout ); err != nil {
419431 return fmt .Errorf ("failed to cleanup resource group: %w" , err )
420432 }
421433
@@ -564,6 +576,44 @@ func (tc *perItOrDescribeTestContext) getARMSubscriptionsClientFactoryUnlocked()
564576 return tc .armSubscriptionsClientFactory , nil
565577}
566578
579+ func (tc * perItOrDescribeTestContext ) GetARMNetworkClientFactory (ctx context.Context ) (* armnetwork.ClientFactory , error ) {
580+ tc .contextLock .RLock ()
581+ if tc .armNetworkClientFactory != nil {
582+ defer tc .contextLock .RUnlock ()
583+ return tc .armNetworkClientFactory , nil
584+ }
585+ tc .contextLock .RUnlock ()
586+
587+ tc .contextLock .Lock ()
588+ defer tc .contextLock .Unlock ()
589+
590+ return tc .getARMNetworkClientFactoryUnlocked (ctx )
591+ }
592+
593+ func (tc * perItOrDescribeTestContext ) getARMNetworkClientFactoryUnlocked (ctx context.Context ) (* armnetwork.ClientFactory , error ) {
594+ if tc .armNetworkClientFactory != nil {
595+ return tc .armNetworkClientFactory , nil
596+ }
597+
598+ creds , err := tc .perBinaryInvocationTestContext .getAzureCredentials ()
599+ if err != nil {
600+ return nil , err
601+ }
602+
603+ // We already hold the lock, so we call the unlocked version
604+ subscriptionID , err := tc .getSubscriptionIDUnlocked (ctx )
605+ if err != nil {
606+ return nil , err
607+ }
608+
609+ clientFactory , err := armnetwork .NewClientFactory (subscriptionID , creds , tc .perBinaryInvocationTestContext .getClientFactoryOptions ())
610+ if err != nil {
611+ return nil , err
612+ }
613+ tc .armNetworkClientFactory = clientFactory
614+ return tc .armNetworkClientFactory , nil
615+ }
616+
567617func (tc * perItOrDescribeTestContext ) GetARMResourcesClientFactory (ctx context.Context ) (* armresources.ClientFactory , error ) {
568618 tc .contextLock .RLock ()
569619 if tc .armResourcesClientFactory != nil {
0 commit comments