mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
support mount options in azure file
use JoinMountOptions func add a new test case move const vars fix fmt issue
This commit is contained in:
parent
2de4562983
commit
badefda861
@ -222,11 +222,12 @@ func (b *azureFileMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||
} else {
|
||||
os.MkdirAll(dir, 0700)
|
||||
// parameters suggested by https://azure.microsoft.com/en-us/documentation/articles/storage-how-to-use-files-linux/
|
||||
options := []string{fmt.Sprintf("vers=3.0,username=%s,password=%s,dir_mode=0700,file_mode=0700", accountName, accountKey)}
|
||||
options := []string{fmt.Sprintf("vers=3.0,username=%s,password=%s", accountName, accountKey)}
|
||||
if b.readOnly {
|
||||
options = append(options, "ro")
|
||||
}
|
||||
mountOptions = volume.JoinMountOptions(b.mountOptions, options)
|
||||
mountOptions = appendDefaultMountOptions(mountOptions)
|
||||
}
|
||||
|
||||
err = b.mounter.Mount(source, dir, "cifs", mountOptions)
|
||||
|
@ -17,9 +17,11 @@ limitations under the License.
|
||||
package azure_file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -358,3 +360,34 @@ func TestGetSecretNameAndNamespaceForPV(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAppendDefaultMountOptions(t *testing.T) {
|
||||
tests := []struct {
|
||||
options []string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
options: []string{"dir_mode=0777"},
|
||||
expected: []string{"dir_mode=0777", fmt.Sprintf("%s=%s", fileModeName, defaultFileMode)},
|
||||
},
|
||||
{
|
||||
options: []string{"file_mode=0777"},
|
||||
expected: []string{"file_mode=0777", fmt.Sprintf("%s=%s", dirModeName, defaultDirMode)},
|
||||
},
|
||||
{
|
||||
options: []string{""},
|
||||
expected: []string{"", fmt.Sprintf("%s=%s", fileModeName, defaultFileMode), fmt.Sprintf("%s=%s", dirModeName, defaultDirMode)},
|
||||
},
|
||||
{
|
||||
options: []string{"file_mode=0777", "dir_mode=0777"},
|
||||
expected: []string{"file_mode=0777", "dir_mode=0777"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := appendDefaultMountOptions(test.options)
|
||||
if !reflect.DeepEqual(result, test.expected) {
|
||||
t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package azure_file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
@ -25,6 +26,13 @@ import (
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
)
|
||||
|
||||
const (
|
||||
fileModeName = "file_mode"
|
||||
dirModeName = "dir_mode"
|
||||
defaultFileMode = "700"
|
||||
defaultDirMode = "700"
|
||||
)
|
||||
|
||||
// Abstract interface to azure file operations.
|
||||
type azureUtil interface {
|
||||
GetAzureCredentials(host volume.VolumeHost, nameSpace, secretName string) (string, string, error)
|
||||
@ -84,3 +92,29 @@ func (s *azureSvc) SetAzureCredentials(host volume.VolumeHost, nameSpace, accoun
|
||||
}
|
||||
return secretName, err
|
||||
}
|
||||
|
||||
// check whether mountOptions contains file_mode and dir_mode, if not, append default mode
|
||||
func appendDefaultMountOptions(mountOptions []string) []string {
|
||||
fileModeFlag := false
|
||||
dirModeFlag := false
|
||||
|
||||
for _, mountOption := range mountOptions {
|
||||
if strings.HasPrefix(mountOption, fileModeName) {
|
||||
fileModeFlag = true
|
||||
}
|
||||
if strings.HasPrefix(mountOption, dirModeName) {
|
||||
dirModeFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
allMountOptions := mountOptions
|
||||
if !fileModeFlag {
|
||||
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", fileModeName, defaultFileMode))
|
||||
}
|
||||
|
||||
if !dirModeFlag {
|
||||
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", dirModeName, defaultDirMode))
|
||||
}
|
||||
|
||||
return allMountOptions
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user