Skip to content

Commit

Permalink
init sub repo in storage account package
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinForReal committed Dec 13, 2024
1 parent ae8bf54 commit 595e806
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/provider/storage/azure_storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
privatedns "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/google/uuid"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -102,7 +101,7 @@ type accountWithLocation struct {
}
type AccountRepo struct {
azureconfig.Config
Environment azure.Environment
Environment *azclient.Environment
ComputeClientFactory azclient.ClientFactory
NetworkClientFactory azclient.ClientFactory
subnetRepo subnet.Repository
Expand All @@ -111,7 +110,7 @@ type AccountRepo struct {
lockMap *lockmap.LockMap
}

func NewRepository(config azureconfig.Config, env azure.Environment, computeClientFactory azclient.ClientFactory, networkClientFactory azclient.ClientFactory) (*AccountRepo, error) {
func NewRepository(config azureconfig.Config, env *azclient.Environment, computeClientFactory azclient.ClientFactory, networkClientFactory azclient.ClientFactory) (*AccountRepo, error) {
getter := func(_ context.Context, _ string) (*armstorage.Account, error) { return nil, nil }
storageAccountCache, err := cache.NewTimedCache(time.Minute, getter, config.DisableAPICallCache)
if err != nil {
Expand All @@ -121,12 +120,17 @@ func NewRepository(config azureconfig.Config, env azure.Environment, computeClie
if err != nil {
return nil, err
}
subnetRepo, err := subnet.NewRepo(networkClientFactory.GetSubnetClient())
if err != nil {
return nil, err
}
return &AccountRepo{
Config: config,
Environment: env,
fileServiceRepo: fileserviceRepo,
ComputeClientFactory: computeClientFactory,
NetworkClientFactory: networkClientFactory,
subnetRepo: subnetRepo,
storageAccountCache: storageAccountCache,
lockMap: lockmap.NewLockMap(),
}, nil
Expand Down Expand Up @@ -367,7 +371,7 @@ func (az *AccountRepo) EnsureStorageAccount(ctx context.Context, accountOptions
accountOptions.StorageType = StorageTypeFile
}

if len(accountOptions.StorageEndpointSuffix) == 0 {
if len(accountOptions.StorageEndpointSuffix) == 0 && az.Environment != nil {
accountOptions.StorageEndpointSuffix = az.Environment.StorageEndpointSuffix
}
privateDNSZoneName = fmt.Sprintf(privateDNSZoneNameFmt, accountOptions.StorageType, accountOptions.StorageEndpointSuffix)
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/storage/azure_storageaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.uber.org/mock/gomock"
"k8s.io/utils/ptr"

"sigs.k8s.io/cloud-provider-azure/pkg/azclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/accountclient/mock_accountclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/blobservicepropertiesclient/mock_blobservicepropertiesclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/cache"
Expand Down Expand Up @@ -501,6 +502,9 @@ func TestEnsureStorageAccount(t *testing.T) {
NetworkClientFactory: mock_azclient.NewMockClientFactory(ctrl),
subnetRepo: subnet.NewMockRepository(ctrl),
Config: config,
Environment: &azclient.Environment{
StorageEndpointSuffix: "storagesuffix",
},
}
mockBlobClient := mock_blobservicepropertiesclient.NewMockInterface(ctrl)
StorageAccountRepo.ComputeClientFactory.(*mock_azclient.MockClientFactory).EXPECT().GetBlobServicePropertiesClientForSub(gomock.Any()).Return(mockBlobClient, nil).AnyTimes()
Expand Down

0 comments on commit 595e806

Please sign in to comment.