From d83e3f25fc0618e3d386c7ac937fe9c1cedecc78 Mon Sep 17 00:00:00 2001 From: Alex Cortelyou Date: Thu, 25 Jul 2024 17:03:10 -0700 Subject: [PATCH] fix: GetAzcopyJob check actual destination container name --- pkg/blob/controllerserver.go | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pkg/blob/controllerserver.go b/pkg/blob/controllerserver.go index fc6ac5d96..582d0ee2b 100644 --- a/pkg/blob/controllerserver.go +++ b/pkg/blob/controllerserver.go @@ -84,20 +84,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) return nil, status.Error(codes.InvalidArgument, err.Error()) } - volContentSource := req.GetVolumeContentSource() - if acquired := d.volumeLocks.TryAcquire(volName); !acquired { - // logging the job status if it's volume cloning - if volContentSource != nil { - jobState, percent, err := d.azcopy.GetAzcopyJob(volName, []string{}) - return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsWithAzcopyFmt, volName, jobState, percent, err) - } - return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volName) - } - defer d.volumeLocks.Release(volName) - volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes()) requestGiB := int(util.RoundUpGiB(volSizeBytes)) + volContentSource := req.GetVolumeContentSource() secrets := req.GetSecrets() // Parameters @@ -359,6 +349,17 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) GetLatestAccountKey: getLatestAccountKey, } + containerName = replaceWithMap(containerName, containerNameReplaceMap) + validContainerName := containerName + if validContainerName == "" { + validContainerName = volName + if containerNamePrefix != "" { + validContainerName = containerNamePrefix + "-" + volName + } + validContainerName = getValidContainerName(validContainerName, protocol) + setKeyValueInMap(parameters, containerNameField, validContainerName) + } + // Telemetry var volumeID string @@ -379,6 +380,16 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) // Volume Source + if acquired := d.volumeLocks.TryAcquire(volName); !acquired { + // logging the job status if it's volume cloning + if volContentSource != nil { + jobState, percent, err := d.azcopy.GetAzcopyJob(validContainerName, []string{}) + return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsWithAzcopyFmt, volName, jobState, percent, err) + } + return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volName) + } + defer d.volumeLocks.Release(volName) + var srcAzcopyAuthEnv []string var srcSubscriptionID, srcResourceGroupName, srcAccountName, srcContainerName, srcPath, srcAccountSASToken string if volContentSource != nil { @@ -469,17 +480,6 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) // Blob Container - // replace pv/pvc name namespace metadata in subDir - containerName = replaceWithMap(containerName, containerNameReplaceMap) - validContainerName := containerName - if validContainerName == "" { - validContainerName = volName - if containerNamePrefix != "" { - validContainerName = containerNamePrefix + "-" + volName - } - validContainerName = getValidContainerName(validContainerName, protocol) - setKeyValueInMap(parameters, containerNameField, validContainerName) - } klog.V(2).Infof("begin to create container(%s) on account(%s) type(%s) subsID(%s) rg(%s) location(%s) size(%d)", validContainerName, accountName, storageAccountType, subsID, resourceGroup, location, requestGiB) if err := d.CreateBlobContainer(ctx, subsID, resourceGroup, accountName, validContainerName, secrets); err != nil { return nil, status.Errorf(codes.Internal, "failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v", validContainerName, accountName, storageAccountType, resourceGroup, location, requestGiB, err)