Skip to content

[release-1.24] feat: match source account as first priority in volume restore #1741

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}
var storageAccountType, subsID, resourceGroup, location, account, containerName, containerNamePrefix, protocol, customTags, secretName, secretNamespace, pvcNamespace, tagValueDelimiter string
var isHnsEnabled, requireInfraEncryption, enableBlobVersioning, createPrivateEndpoint, enableNfsV3, allowSharedKeyAccess *bool
var vnetResourceGroup, vnetName, subnetName, accessTier, networkEndpointType, storageEndpointSuffix, fsGroupChangePolicy string
var vnetResourceGroup, vnetName, subnetName, accessTier, networkEndpointType, storageEndpointSuffix, fsGroupChangePolicy, srcAccountName string
var matchTags, useDataPlaneAPI, getLatestAccountKey bool
var softDeleteBlobs, softDeleteContainers int32
var vnetResourceIDs []string
Expand Down Expand Up @@ -309,6 +309,25 @@
return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled")
}

requestName := "controller_create_volume"
if volContentSource != nil {
switch volContentSource.Type.(type) {
case *csi.VolumeContentSource_Snapshot:
return nil, status.Errorf(codes.InvalidArgument, "VolumeContentSource Snapshot is not yet implemented")
case *csi.VolumeContentSource_Volume:
requestName = "controller_create_volume_from_volume"
if volContentSource.GetVolume() != nil {
sourceID := volContentSource.GetVolume().VolumeId
_, srcAccountName, _, _, _, err = GetContainerInfo(sourceID) //nolint:dogsled
if err != nil {
klog.Errorf("failed to get source volume info from sourceID(%s), error: %v", sourceID, err)
} else {
klog.V(2).Infof("source volume account name: %s, sourceID: %s", srcAccountName, sourceID)
}
}
}
}

accountOptions := &azure.AccountOptions{
Name: account,
Type: storageAccountType,
Expand Down Expand Up @@ -336,6 +355,7 @@
SoftDeleteBlobs: softDeleteBlobs,
SoftDeleteContainers: softDeleteContainers,
GetLatestAccountKey: getLatestAccountKey,
SourceAccountName: srcAccountName,

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Build

unknown field SourceAccountName in struct literal of type provider.AccountOptions

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Go Lint

unknown field SourceAccountName in struct literal of type provider.AccountOptions) (typecheck)

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Go Lint

unknown field SourceAccountName in struct literal of type provider.AccountOptions) (typecheck)

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Go Lint

unknown field SourceAccountName in struct literal of type provider.AccountOptions) (typecheck)

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Go Lint

unknown field SourceAccountName in struct literal of type provider.AccountOptions (typecheck)

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

unknown field SourceAccountName in struct literal of type provider.AccountOptions

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / build (1.16.x, windows-latest)

unknown field SourceAccountName in struct literal of type provider.AccountOptions

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Build

unknown field SourceAccountName in struct literal of type provider.AccountOptions

Check failure on line 358 in pkg/blob/controllerserver.go

View workflow job for this annotation

GitHub Actions / Build

unknown field SourceAccountName in struct literal of type provider.AccountOptions
}

containerName = replaceWithMap(containerName, containerNameReplaceMap)
Expand All @@ -359,16 +379,6 @@
}
defer d.volumeLocks.Release(volName)

requestName := "controller_create_volume"
if volContentSource != nil {
switch volContentSource.Type.(type) {
case *csi.VolumeContentSource_Snapshot:
return nil, status.Errorf(codes.InvalidArgument, "VolumeContentSource Snapshot is not yet implemented")
case *csi.VolumeContentSource_Volume:
requestName = "controller_create_volume_from_volume"
}
}

var volumeID string
mc := metrics.NewMetricContext(blobCSIDriverName, requestName, d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
isOperationSucceeded := false
Expand Down Expand Up @@ -440,8 +450,7 @@
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to getAzcopyAuth on account(%s) rg(%s), error: %v", accountOptions.Name, accountOptions.ResourceGroup, err)
}
var copyErr error
copyErr = d.copyVolume(ctx, req, accountName, accountSASToken, authAzcopyEnv, validContainerName, secretNamespace, accountOptions, storageEndpointSuffix)
copyErr := d.copyVolume(ctx, req, accountName, accountSASToken, authAzcopyEnv, validContainerName, secretNamespace, accountOptions, storageEndpointSuffix)
if accountSASToken == "" && copyErr != nil && strings.Contains(copyErr.Error(), authorizationPermissionMismatch) {
klog.Warningf("azcopy copy failed with AuthorizationPermissionMismatch error, should assign \"Storage Blob Data Contributor\" role to controller identity, fall back to use sas token, original error: %v", copyErr)
accountSASToken, authAzcopyEnv, err := d.getAzcopyAuth(ctx, accountName, accountKey, storageEndpointSuffix, accountOptions, secrets, secretName, secretNamespace, true)
Expand Down
Loading