mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
set fsGroup by securityContext.fsGroup in azure file
fix comments fix comments fix comments
This commit is contained in:
parent
eb3196b1b4
commit
c38e7589a4
@ -43,6 +43,7 @@ go_test(
|
|||||||
"//pkg/util/mount:go_default_library",
|
"//pkg/util/mount:go_default_library",
|
||||||
"//pkg/volume:go_default_library",
|
"//pkg/volume:go_default_library",
|
||||||
"//pkg/volume/testing:go_default_library",
|
"//pkg/volume/testing:go_default_library",
|
||||||
|
"//vendor/github.com/Azure/go-autorest/autorest/to:go_default_library",
|
||||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
|
@ -227,7 +227,7 @@ func (b *azureFileMounter) SetUpAt(dir string, fsGroup *int64) error {
|
|||||||
options = append(options, "ro")
|
options = append(options, "ro")
|
||||||
}
|
}
|
||||||
mountOptions = volume.JoinMountOptions(b.mountOptions, options)
|
mountOptions = volume.JoinMountOptions(b.mountOptions, options)
|
||||||
mountOptions = appendDefaultMountOptions(mountOptions)
|
mountOptions = appendDefaultMountOptions(mountOptions, fsGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = b.mounter.Mount(source, dir, "cifs", mountOptions)
|
err = b.mounter.Mount(source, dir, "cifs", mountOptions)
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -364,32 +365,55 @@ func TestGetSecretNameAndNamespaceForPV(t *testing.T) {
|
|||||||
func TestAppendDefaultMountOptions(t *testing.T) {
|
func TestAppendDefaultMountOptions(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
options []string
|
options []string
|
||||||
|
fsGroup *int64
|
||||||
expected []string
|
expected []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
options: []string{"dir_mode=0777"},
|
options: []string{"dir_mode=0777"},
|
||||||
expected: []string{"dir_mode=0777", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", vers, defaultVers)},
|
fsGroup: nil,
|
||||||
|
expected: []string{"dir_mode=0777",
|
||||||
|
fmt.Sprintf("%s=%s", fileMode, defaultFileMode),
|
||||||
|
fmt.Sprintf("%s=%s", vers, defaultVers)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
options: []string{"file_mode=0777"},
|
options: []string{"file_mode=0777"},
|
||||||
expected: []string{"file_mode=0777", fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=%s", vers, defaultVers)},
|
fsGroup: to.Int64Ptr(0),
|
||||||
|
expected: []string{"file_mode=0777",
|
||||||
|
fmt.Sprintf("%s=%s", dirMode, defaultDirMode),
|
||||||
|
fmt.Sprintf("%s=%s", vers, defaultVers),
|
||||||
|
fmt.Sprintf("%s=0", gid)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
options: []string{"vers=2.1"},
|
options: []string{"vers=2.1"},
|
||||||
expected: []string{"vers=2.1", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode)},
|
fsGroup: to.Int64Ptr(1000),
|
||||||
|
expected: []string{"vers=2.1",
|
||||||
|
fmt.Sprintf("%s=%s", fileMode, defaultFileMode),
|
||||||
|
fmt.Sprintf("%s=%s", dirMode, defaultDirMode),
|
||||||
|
fmt.Sprintf("%s=1000", gid)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
options: []string{""},
|
options: []string{""},
|
||||||
expected: []string{"", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=%s", vers, defaultVers)},
|
expected: []string{"", fmt.Sprintf("%s=%s",
|
||||||
|
fileMode, defaultFileMode),
|
||||||
|
fmt.Sprintf("%s=%s", dirMode, defaultDirMode),
|
||||||
|
fmt.Sprintf("%s=%s", vers, defaultVers)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
options: []string{"file_mode=0777", "dir_mode=0777"},
|
options: []string{"file_mode=0777", "dir_mode=0777"},
|
||||||
expected: []string{"file_mode=0777", "dir_mode=0777", fmt.Sprintf("%s=%s", vers, defaultVers)},
|
expected: []string{"file_mode=0777", "dir_mode=0777", fmt.Sprintf("%s=%s", vers, defaultVers)},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
options: []string{"gid=2000"},
|
||||||
|
fsGroup: to.Int64Ptr(1000),
|
||||||
|
expected: []string{"gid=2000",
|
||||||
|
fmt.Sprintf("%s=%s", fileMode, defaultFileMode),
|
||||||
|
fmt.Sprintf("%s=%s", dirMode, defaultDirMode),
|
||||||
|
"vers=3.0"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
result := appendDefaultMountOptions(test.options)
|
result := appendDefaultMountOptions(test.options, test.fsGroup)
|
||||||
if !reflect.DeepEqual(result, test.expected) {
|
if !reflect.DeepEqual(result, test.expected) {
|
||||||
t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected)
|
t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected)
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
fileMode = "file_mode"
|
fileMode = "file_mode"
|
||||||
dirMode = "dir_mode"
|
dirMode = "dir_mode"
|
||||||
|
gid = "gid"
|
||||||
vers = "vers"
|
vers = "vers"
|
||||||
defaultFileMode = "0755"
|
defaultFileMode = "0755"
|
||||||
defaultDirMode = "0755"
|
defaultDirMode = "0755"
|
||||||
@ -95,11 +96,12 @@ func (s *azureSvc) SetAzureCredentials(host volume.VolumeHost, nameSpace, accoun
|
|||||||
return secretName, err
|
return secretName, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether mountOptions contain file_mode and dir_mode, if not, append default mode
|
// check whether mountOptions contain file_mode, dir_mode, vers, gid, if not, append default mode
|
||||||
func appendDefaultMountOptions(mountOptions []string) []string {
|
func appendDefaultMountOptions(mountOptions []string, fsGroup *int64) []string {
|
||||||
fileModeFlag := false
|
fileModeFlag := false
|
||||||
dirModeFlag := false
|
dirModeFlag := false
|
||||||
versFlag := false
|
versFlag := false
|
||||||
|
gidFlag := false
|
||||||
|
|
||||||
for _, mountOption := range mountOptions {
|
for _, mountOption := range mountOptions {
|
||||||
if strings.HasPrefix(mountOption, fileMode) {
|
if strings.HasPrefix(mountOption, fileMode) {
|
||||||
@ -111,6 +113,9 @@ func appendDefaultMountOptions(mountOptions []string) []string {
|
|||||||
if strings.HasPrefix(mountOption, vers) {
|
if strings.HasPrefix(mountOption, vers) {
|
||||||
versFlag = true
|
versFlag = true
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(mountOption, gid) {
|
||||||
|
gidFlag = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allMountOptions := mountOptions
|
allMountOptions := mountOptions
|
||||||
@ -125,5 +130,9 @@ func appendDefaultMountOptions(mountOptions []string) []string {
|
|||||||
if !versFlag {
|
if !versFlag {
|
||||||
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", vers, defaultVers))
|
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", vers, defaultVers))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !gidFlag && fsGroup != nil {
|
||||||
|
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%d", gid, *fsGroup))
|
||||||
|
}
|
||||||
return allMountOptions
|
return allMountOptions
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user