Skip to content

Commit

Permalink
fix: GetAzcopyJob check actual destination container name
Browse files Browse the repository at this point in the history
  • Loading branch information
acortelyou committed Jul 26, 2024
1 parent 6544a40 commit d83e3f2
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d83e3f2

Please sign in to comment.