Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c38e7589
Commit
c38e7589
authored
Jan 16, 2018
by
andyzhangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set fsGroup by securityContext.fsGroup in azure file
fix comments fix comments fix comments
parent
eb3196b1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
12 deletions
+46
-12
BUILD
pkg/volume/azure_file/BUILD
+1
-0
azure_file.go
pkg/volume/azure_file/azure_file.go
+1
-1
azure_file_test.go
pkg/volume/azure_file/azure_file_test.go
+33
-9
azure_util.go
pkg/volume/azure_file/azure_util.go
+11
-2
No files found.
pkg/volume/azure_file/BUILD
View file @
c38e7589
...
@@ -43,6 +43,7 @@ go_test(
...
@@ -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",
...
...
pkg/volume/azure_file/azure_file.go
View file @
c38e7589
...
@@ -227,7 +227,7 @@ func (b *azureFileMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -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
)
...
...
pkg/volume/azure_file/azure_file_test.go
View file @
c38e7589
...
@@ -25,6 +25,7 @@ import (
...
@@ -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) {
...
@@ -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
)
}
}
...
...
pkg/volume/azure_file/azure_util.go
View file @
c38e7589
...
@@ -29,6 +29,7 @@ import (
...
@@ -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
...
@@ -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 {
...
@@ -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 {
...
@@ -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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment