Skip to content

fix: huge storage account list usage #480

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,40 @@ func (d *Driver) getSubnetResourceID() string {

return fmt.Sprintf(subnetTemplate, subsID, rg, d.cloud.VnetName, d.cloud.SubnetName)
}

// appendDefaultMountOptions return mount options combined with mountOptions and defaultMountOptions
func appendDefaultMountOptions(mountOptions []string, tmpPath, containerName string) []string {
var defaultMountOptions = map[string]string{
"--pre-mount-validate": "true",
"--use-https": "true",
"--tmp-path": tmpPath,
"--container-name": containerName,
// prevent billing charges on mounting
"--cancel-list-on-mount-seconds": "60",
}

// stores the mount options already included in mountOptions
included := make(map[string]bool)

for _, mountOption := range mountOptions {
for k := range defaultMountOptions {
if strings.HasPrefix(mountOption, k) {
included[k] = true
}
}
}

allMountOptions := mountOptions

for k, v := range defaultMountOptions {
if _, isIncluded := included[k]; !isIncluded {
if v != "" {
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", k, v))
} else {
allMountOptions = append(allMountOptions, k)
}
}
}

return allMountOptions
}
45 changes: 45 additions & 0 deletions pkg/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"os"
"reflect"
"sort"
"testing"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-02-01/storage"
Expand Down Expand Up @@ -773,3 +774,47 @@ func TestSetAzureCredentials(t *testing.T) {
}
}
}

func TestAppendDefaultMountOptions(t *testing.T) {
tests := []struct {
options []string
tmpPath string
containerName string
expected []string
}{
{
options: []string{"targetPath"},
tmpPath: "/tmp",
containerName: "containerName",
expected: []string{"--cancel-list-on-mount-seconds=60",
"--container-name=containerName",
"--pre-mount-validate=true",
"--tmp-path=/tmp",
"--use-https=true",
"targetPath",
},
},
{
options: []string{"targetPath", "--cancel-list-on-mount-seconds=0", "--pre-mount-validate=false"},
tmpPath: "/tmp",
containerName: "containerName",
expected: []string{"--cancel-list-on-mount-seconds=0",
"--container-name=containerName",
"--pre-mount-validate=false",
"--tmp-path=/tmp",
"--use-https=true",
"targetPath",
},
},
}

for _, test := range tests {
result := appendDefaultMountOptions(test.options, test.tmpPath, test.containerName)
sort.Strings(result)
sort.Strings(test.expected)

if !reflect.DeepEqual(result, test.expected) {
t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected)
}
}
}
7 changes: 4 additions & 3 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
}

// Get mountOptions that the volume will be formatted and mounted with
mountOptions := util.JoinMountOptions(mountFlags, []string{"--use-https=true"})
mountOptions := mountFlags
if ephemeralVol {
mountOptions = util.JoinMountOptions(mountOptions, strings.Split(ephemeralVolMountOptions, ","))
}

// set different tmp-path with time info
tmpPath := fmt.Sprintf("%s/%s#%d", "/mnt", volumeID, time.Now().Unix())
args := fmt.Sprintf("%s --pre-mount-validate=true --tmp-path=%s --container-name=%s", targetPath, tmpPath, containerName)
mountOptions = appendDefaultMountOptions(mountOptions, tmpPath, containerName)

args := targetPath
for _, opt := range mountOptions {
args = args + " " + opt
}
Expand Down