Skip to content

Commit

Permalink
Merge pull request #2723 from ZeroMagic/private-dns-zone
Browse files Browse the repository at this point in the history
fix: check private dns zone before creation
  • Loading branch information
k8s-ci-robot committed Nov 10, 2022
2 parents 41c4c14 + a17afbc commit fa92444
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/provider/azure_storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,21 @@ func (az *Cloud) EnsureStorageAccount(ctx context.Context, accountOptions *Accou
}

if accountOptions.CreatePrivateEndpoint {
// Create DNS zone first, this could make sure driver has write permission on vnetResourceGroup
if err := az.createPrivateDNSZone(ctx, vnetResourceGroup); err != nil {
return "", "", fmt.Errorf("Failed to create private DNS zone(%s) in resourceGroup(%s), error: %v", PrivateDNSZoneName, vnetResourceGroup, err)
if _, err := az.privatednsclient.Get(ctx, vnetResourceGroup, PrivateDNSZoneName); err != nil {
klog.V(2).Infof("get private dns zone %s returned with %v", PrivateDNSZoneName, err.Error())
// Create DNS zone first, this could make sure driver has write permission on vnetResourceGroup
if err := az.createPrivateDNSZone(ctx, vnetResourceGroup); err != nil {
return "", "", fmt.Errorf("Failed to create private DNS zone(%s) in resourceGroup(%s), error: %v", PrivateDNSZoneName, vnetResourceGroup, err)
}
}

// Create virtual link to the private DNS zone
vNetLinkName := accountName + "-vnetlink"
if err := az.createVNetLink(ctx, vNetLinkName, vnetResourceGroup, vnetName); err != nil {
return "", "", fmt.Errorf("Failed to create virtual link for vnet(%s) and DNS Zone(%s) in resourceGroup(%s), error: %v", vnetName, PrivateDNSZoneName, vnetResourceGroup, err)
if _, err := az.virtualNetworkLinksClient.Get(ctx, vnetResourceGroup, PrivateDNSZoneName, vNetLinkName); err != nil {
klog.V(2).Infof("get virtual link for vnet(%s) and DNS Zone(%s) returned with %v", vnetName, PrivateDNSZoneName, err.Error())
if err := az.createVNetLink(ctx, vNetLinkName, vnetResourceGroup, vnetName); err != nil {
return "", "", fmt.Errorf("Failed to create virtual link for vnet(%s) and DNS Zone(%s) in resourceGroup(%s), error: %v", vnetName, PrivateDNSZoneName, vnetResourceGroup, err)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/provider/azure_storageaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"
"github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage"
"github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -457,6 +458,7 @@ func TestEnsureStorageAccount(t *testing.T) {
cloud.SubnetsClient = mockSubnetsClient

mockPrivateDNSClient := mockprivatednsclient.NewMockInterface(ctrl)
mockPrivateDNSClient.EXPECT().Get(gomock.Any(), vnetResourceGroup, gomock.Any()).Return(privatedns.PrivateZone{}, &retry.Error{}).Times(1)
mockPrivateDNSClient.EXPECT().CreateOrUpdate(gomock.Any(), vnetResourceGroup, gomock.Any(), gomock.Any(), "", true).Return(nil).Times(1)
cloud.privatednsclient = mockPrivateDNSClient

Expand All @@ -469,6 +471,7 @@ func TestEnsureStorageAccount(t *testing.T) {
cloud.privateendpointclient = mockPrivateEndpointClient

mockVirtualNetworkLinksClient := mockvirtualnetworklinksclient.NewMockInterface(ctrl)
mockVirtualNetworkLinksClient.EXPECT().Get(gomock.Any(), vnetResourceGroup, gomock.Any(), gomock.Any()).Return(privatedns.VirtualNetworkLink{}, &retry.Error{}).Times(1)
mockVirtualNetworkLinksClient.EXPECT().CreateOrUpdate(gomock.Any(), vnetResourceGroup, gomock.Any(), gomock.Any(), gomock.Any(), "", false).Return(nil).Times(1)
cloud.virtualNetworkLinksClient = mockVirtualNetworkLinksClient
}
Expand Down

0 comments on commit fa92444

Please sign in to comment.