Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support privateendpoint for blob-csi-driver #2992

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions pkg/provider/azure_storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ import (
const SkipMatchingTag = "skip-matching"
const LocationGlobal = "global"
const GroupIDFile = "file"
const privateDNSZoneNameFmt = "privatelink.file.%s"
const GroupIDBlob = "blob"
const privateDNSZoneNameFmt = "privatelink.%s.%s"

type StorageType string

const (
StorageTypeBlob StorageType = "blob"
StorageTypeFile StorageType = "file"
)

// AccountOptions contains the fields which are used to create storage account.
type AccountOptions struct {
Expand All @@ -48,6 +56,7 @@ type AccountOptions struct {
CreateAccount bool
EnableLargeFileShare bool
CreatePrivateEndpoint bool
StorageType StorageType
StorageEndpointSuffix string
DisableFileServiceDeleteRetentionPolicy bool
IsHnsEnabled *bool
Expand Down Expand Up @@ -163,10 +172,15 @@ func (az *Cloud) EnsureStorageAccount(ctx context.Context, accountOptions *Accou

var privateDNSZoneName string
if accountOptions.CreatePrivateEndpoint {
if accountOptions.StorageType == "" {
cvvz marked this conversation as resolved.
Show resolved Hide resolved
klog.V(2).Info("set StorageType as file when not specified")
accountOptions.StorageType = StorageTypeFile
}

if len(accountOptions.StorageEndpointSuffix) == 0 {
accountOptions.StorageEndpointSuffix = az.cloud.Environment.StorageEndpointSuffix
}
privateDNSZoneName = fmt.Sprintf(privateDNSZoneNameFmt, accountOptions.StorageEndpointSuffix)
privateDNSZoneName = fmt.Sprintf(privateDNSZoneNameFmt, accountOptions.StorageType, accountOptions.StorageEndpointSuffix)
}

if len(accountOptions.Tags) == 0 {
Expand Down Expand Up @@ -413,7 +427,7 @@ func (az *Cloud) createPrivateEndpoint(ctx context.Context, accountName string,
privateLinkServiceConnection := network.PrivateLinkServiceConnection{
Name: &privateLinkServiceConnectionName,
PrivateLinkServiceConnectionProperties: &network.PrivateLinkServiceConnectionProperties{
GroupIds: &[]string{GroupIDFile},
cvvz marked this conversation as resolved.
Show resolved Hide resolved
GroupIds: &[]string{GroupIDFile, GroupIDBlob},
PrivateLinkServiceID: accountID,
},
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/azure_storageaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func TestEnsureStorageAccount(t *testing.T) {
mockStorageAccountsClient bool
setAccountOptions bool
accessTier string
storageType StorageType
requireInfrastructureEncryption *bool
keyVaultURL *string
accountName string
Expand All @@ -390,6 +391,7 @@ func TestEnsureStorageAccount(t *testing.T) {
createPrivateEndpoint: true,
mockStorageAccountsClient: true,
setAccountOptions: true,
storageType: StorageTypeFile,
requireInfrastructureEncryption: to.BoolPtr(true),
keyVaultURL: to.StringPtr("keyVaultURL"),
resourceGroup: "rg",
Expand All @@ -404,6 +406,7 @@ func TestEnsureStorageAccount(t *testing.T) {
SubnetPropertiesFormatNil: true,
mockStorageAccountsClient: true,
setAccountOptions: true,
storageType: StorageTypeFile,
resourceGroup: "rg",
accountName: "accountname",
expectedErr: "could not get storage key for storage account",
Expand Down Expand Up @@ -485,6 +488,7 @@ func TestEnsureStorageAccount(t *testing.T) {
CreateAccount: test.createAccount,
SubscriptionID: test.subscriptionID,
AccessTier: test.accessTier,
StorageType: test.storageType,
}
}

Expand Down