Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
umagnus committed Jan 9, 2024
1 parent 4b4893d commit 0785325
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ var (
supportedFSGroupChangePolicyList = []string{FSGroupChangeNone, string(v1.FSGroupChangeAlways), string(v1.FSGroupChangeOnRootMismatch)}

retriableErrors = []string{accountNotProvisioned, tooManyRequests, shareBeingDeleted, clientThrottled}

defaultAzcopyCopyOptions = []string{"--recursive", "--check-length=false"}
)

// Driver implements all interfaces of CSI drivers
Expand Down Expand Up @@ -1022,7 +1024,8 @@ func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest
return err
case fileutil.AzcopyJobNotFound:
klog.V(2).Infof("copy fileshare %s to %s", srcFileShareName, dstFileShareName)
cmd := exec.Command("azcopy", "copy", srcPath, dstPath, "--recursive", "--check-length=false")
cmd := exec.Command("azcopy", "copy", srcPath, dstPath)
cmd.Args = append(cmd.Args, defaultAzcopyCopyOptions...)
if len(authAzcopyEnv) > 0 {
cmd.Env = append(os.Environ(), authAzcopyEnv...)
}
Expand All @@ -1034,7 +1037,9 @@ func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest
if sasToken, _, err = d.getAzcopyAuth(ctx, accountName, "", storageEndpointSuffix, accountOptions, secrets, secretName, secretNamespace, true); err != nil {
return err
}
out, copyErr = exec.Command("azcopy", "copy", srcPath+sasToken, dstPath+sasToken, "--recursive", "--check-length=false").CombinedOutput()
cmd := exec.Command("azcopy", "copy", srcPath+sasToken, dstPath+sasToken)
cmd.Args = append(cmd.Args, defaultAzcopyCopyOptions...)
out, copyErr = cmd.CombinedOutput()
}
if copyErr != nil {
klog.Warningf("CopyFileShare(%s, %s, %s) failed with error(%v): %v", resourceGroupName, accountName, dstFileShareName, copyErr, string(out))
Expand Down
4 changes: 2 additions & 2 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {

return authAzcopyEnv, nil
}
return []string{}, fmt.Errorf("service principle or managed identity are both not set")
return []string{}, fmt.Errorf("neither the service principal nor the managed identity has been set")
}

// getAzcopyAuth will only generate sas token for azcopy in following conditions:
Expand All @@ -1345,7 +1345,7 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {
// 4. parameter useSasToken is true
func (d *Driver) getAzcopyAuth(ctx context.Context, accountName, accountKey, storageEndpointSuffix string, accountOptions *azure.AccountOptions, secrets map[string]string, secretName, secretNamespace string, useSasToken bool) (string, []string, error) {
var authAzcopyEnv []string
if len(secrets) == 0 && len(secretName) == 0 {
if !useSasToken && len(secrets) == 0 && len(secretName) == 0 {
var err error
authAzcopyEnv, err = d.authorizeAzcopyWithIdentity()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ func TestAuthorizeAzcopyWithIdentity(t *testing.T) {
},
}
expectedAuthAzcopyEnv := []string{}
expectedErr := fmt.Errorf("service principle or managed identity are both not set")
expectedErr := fmt.Errorf("neither the service principal nor the managed identity has been set")
authAzcopyEnv, err := d.authorizeAzcopyWithIdentity()
if !reflect.DeepEqual(authAzcopyEnv, expectedAuthAzcopyEnv) || !reflect.DeepEqual(err, expectedErr) {
t.Errorf("Unexpected authAzcopyEnv: %v, Unexpected error: %v", authAzcopyEnv, err)
Expand Down

0 comments on commit 0785325

Please sign in to comment.