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
b22ff256
Unverified
Commit
b22ff256
authored
Jan 05, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass pod metadata to flex plugin
parent
dddc6b86
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
11 deletions
+49
-11
driver-call.go
pkg/volume/flexvolume/driver-call.go
+6
-0
mounter.go
pkg/volume/flexvolume/mounter.go
+7
-0
mounter_test.go
pkg/volume/flexvolume/mounter_test.go
+22
-3
plugin.go
pkg/volume/flexvolume/plugin.go
+9
-7
volume.go
pkg/volume/flexvolume/volume.go
+5
-1
No files found.
pkg/volume/flexvolume/driver-call.go
View file @
b22ff256
...
@@ -51,6 +51,12 @@ const (
...
@@ -51,6 +51,12 @@ const (
optionKeySecret
=
"kubernetes.io/secret"
optionKeySecret
=
"kubernetes.io/secret"
optionFSGroup
=
"kubernetes.io/fsGroup"
optionFSGroup
=
"kubernetes.io/fsGroup"
optionMountsDir
=
"kubernetes.io/mountsDir"
optionMountsDir
=
"kubernetes.io/mountsDir"
optionKeyPodName
=
"kubernetes.io/pod.name"
optionKeyPodNamespace
=
"kubernetes.io/pod.namespace"
optionKeyPodUID
=
"kubernetes.io/pod.uid"
optionKeyServiceAccountName
=
"kubernetes.io/serviceAccount.name"
)
)
const
(
const
(
...
...
pkg/volume/flexvolume/mounter.go
View file @
b22ff256
...
@@ -66,6 +66,13 @@ func (f *flexVolumeMounter) SetUpAt(dir string, fsGroup *types.UnixGroupID) erro
...
@@ -66,6 +66,13 @@ func (f *flexVolumeMounter) SetUpAt(dir string, fsGroup *types.UnixGroupID) erro
extraOptions
:=
make
(
map
[
string
]
string
)
extraOptions
:=
make
(
map
[
string
]
string
)
// pod metadata
extraOptions
[
optionKeyPodName
]
=
f
.
podName
extraOptions
[
optionKeyPodNamespace
]
=
f
.
podNamespace
extraOptions
[
optionKeyPodUID
]
=
string
(
f
.
podUID
)
// service account metadata
extraOptions
[
optionKeyServiceAccountName
]
=
f
.
podServiceAccountName
// Extract secret and pass it as options.
// Extract secret and pass it as options.
if
err
:=
addSecretsToOptions
(
extraOptions
,
f
.
spec
,
f
.
podNamespace
,
f
.
driverName
,
f
.
plugin
.
host
);
err
!=
nil
{
if
err
:=
addSecretsToOptions
(
extraOptions
,
f
.
spec
,
f
.
podNamespace
,
f
.
driverName
,
f
.
plugin
.
host
);
err
!=
nil
{
return
err
return
err
...
...
pkg/volume/flexvolume/mounter_test.go
View file @
b22ff256
...
@@ -19,6 +19,7 @@ package flexvolume
...
@@ -19,6 +19,7 @@ package flexvolume
import
(
import
(
"testing"
"testing"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
...
@@ -26,7 +27,16 @@ import (
...
@@ -26,7 +27,16 @@ import (
func
TestSetUpAt
(
t
*
testing
.
T
)
{
func
TestSetUpAt
(
t
*
testing
.
T
)
{
spec
:=
fakeVolumeSpec
()
spec
:=
fakeVolumeSpec
()
pod
:=
&
v1
.
Pod
{}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"my-pod"
,
Namespace
:
"my-ns"
,
UID
:
types
.
UID
(
"my-uid"
),
},
Spec
:
v1
.
PodSpec
{
ServiceAccountName
:
"my-sa"
,
},
}
mounter
:=
&
mount
.
FakeMounter
{}
mounter
:=
&
mount
.
FakeMounter
{}
plugin
,
rootDir
:=
testPlugin
()
plugin
,
rootDir
:=
testPlugin
()
...
@@ -34,12 +44,21 @@ func TestSetUpAt(t *testing.T) {
...
@@ -34,12 +44,21 @@ func TestSetUpAt(t *testing.T) {
plugin
.
runner
=
fakeRunner
(
plugin
.
runner
=
fakeRunner
(
// first call without fsGroup
// first call without fsGroup
assertDriverCall
(
t
,
successOutput
(),
mountCmd
,
rootDir
+
"/mount-dir"
,
assertDriverCall
(
t
,
successOutput
(),
mountCmd
,
rootDir
+
"/mount-dir"
,
specJson
(
plugin
,
spec
,
nil
)),
specJson
(
plugin
,
spec
,
map
[
string
]
string
{
optionKeyPodName
:
"my-pod"
,
optionKeyPodNamespace
:
"my-ns"
,
optionKeyPodUID
:
"my-uid"
,
optionKeyServiceAccountName
:
"my-sa"
,
})),
// second test has fsGroup
// second test has fsGroup
assertDriverCall
(
t
,
notSupportedOutput
(),
mountCmd
,
rootDir
+
"/mount-dir"
,
assertDriverCall
(
t
,
notSupportedOutput
(),
mountCmd
,
rootDir
+
"/mount-dir"
,
specJson
(
plugin
,
spec
,
map
[
string
]
string
{
specJson
(
plugin
,
spec
,
map
[
string
]
string
{
optionFSGroup
:
"42"
,
optionFSGroup
:
"42"
,
optionKeyPodName
:
"my-pod"
,
optionKeyPodNamespace
:
"my-ns"
,
optionKeyPodUID
:
"my-uid"
,
optionKeyServiceAccountName
:
"my-sa"
,
})),
})),
assertDriverCall
(
t
,
fakeVolumeNameOutput
(
"sdx"
),
getVolumeNameCmd
,
assertDriverCall
(
t
,
fakeVolumeNameOutput
(
"sdx"
),
getVolumeNameCmd
,
specJson
(
plugin
,
spec
,
nil
)),
specJson
(
plugin
,
spec
,
nil
)),
...
...
pkg/volume/flexvolume/plugin.go
View file @
b22ff256
...
@@ -108,13 +108,15 @@ func (plugin *flexVolumePlugin) newMounterInternal(spec *volume.Spec, pod *api.P
...
@@ -108,13 +108,15 @@ func (plugin *flexVolumePlugin) newMounterInternal(spec *volume.Spec, pod *api.P
source
,
readOnly
:=
getVolumeSource
(
spec
)
source
,
readOnly
:=
getVolumeSource
(
spec
)
return
&
flexVolumeMounter
{
return
&
flexVolumeMounter
{
flexVolume
:
&
flexVolume
{
flexVolume
:
&
flexVolume
{
driverName
:
source
.
Driver
,
driverName
:
source
.
Driver
,
execPath
:
plugin
.
getExecutable
(),
execPath
:
plugin
.
getExecutable
(),
mounter
:
mounter
,
mounter
:
mounter
,
plugin
:
plugin
,
plugin
:
plugin
,
podUID
:
pod
.
UID
,
podName
:
pod
.
Name
,
podNamespace
:
pod
.
Namespace
,
podUID
:
pod
.
UID
,
volName
:
spec
.
Name
(),
podNamespace
:
pod
.
Namespace
,
podServiceAccountName
:
pod
.
Spec
.
ServiceAccountName
,
volName
:
spec
.
Name
(),
},
},
runner
:
runner
,
runner
:
runner
,
spec
:
spec
,
spec
:
spec
,
...
...
pkg/volume/flexvolume/volume.go
View file @
b22ff256
...
@@ -30,10 +30,14 @@ type flexVolume struct {
...
@@ -30,10 +30,14 @@ type flexVolume struct {
// mounter provides the interface that is used to mount the actual
// mounter provides the interface that is used to mount the actual
// block device.
// block device.
mounter
mount
.
Interface
mounter
mount
.
Interface
// podName is the name of the pod, if available.
podName
string
// podUID is the UID of the pod.
// podUID is the UID of the pod.
podUID
types
.
UID
podUID
types
.
UID
// podNamespace is the namespace of the pod.
// podNamespace is the namespace of the pod
, if available
.
podNamespace
string
podNamespace
string
// podServiceAccountName is the service account name of the pod, if available.
podServiceAccountName
string
// volName is the name of the pod's volume.
// volName is the name of the pod's volume.
volName
string
volName
string
// the underlying plugin
// the underlying plugin
...
...
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