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
c0d49450
Commit
c0d49450
authored
Dec 10, 2015
by
harry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix volume wrapper doesn't have name
Integration test
parent
7ca0fa43
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
215 additions
and
46 deletions
+215
-46
integration.go
cmd/integration/integration.go
+87
-4
downwardapi.go
pkg/volume/downwardapi/downwardapi.go
+10
-8
downwardapi_test.go
pkg/volume/downwardapi/downwardapi_test.go
+31
-11
git_repo.go
pkg/volume/git_repo/git_repo.go
+6
-7
git_repo_test.go
pkg/volume/git_repo/git_repo_test.go
+21
-5
secret.go
pkg/volume/secret/secret.go
+25
-10
secret_test.go
pkg/volume/secret/secret_test.go
+11
-1
volume.go
pkg/volume/volume.go
+24
-0
No files found.
cmd/integration/integration.go
View file @
c0d49450
...
...
@@ -55,7 +55,10 @@ import (
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/empty_dir"
"k8s.io/kubernetes/pkg/volume/git_repo"
"k8s.io/kubernetes/pkg/volume/secret"
"k8s.io/kubernetes/plugin/pkg/scheduler"
_
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
"k8s.io/kubernetes/plugin/pkg/scheduler/factory"
...
...
@@ -211,7 +214,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
10250
,
/* KubeletPort */
0
,
/* ReadOnlyPort */
api
.
NamespaceDefault
,
empty_dir
.
P
robeVolumePlugins
(),
p
robeVolumePlugins
(),
nil
,
cadvisorInterface
,
configFilePath
,
...
...
@@ -244,7 +247,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
10251
,
/* KubeletPort */
0
,
/* ReadOnlyPort */
api
.
NamespaceDefault
,
empty_dir
.
P
robeVolumePlugins
(),
p
robeVolumePlugins
(),
nil
,
cadvisorInterface
,
""
,
...
...
@@ -265,6 +268,16 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
return
apiServer
.
URL
,
configFilePath
}
// The list of plugins to probe in this test
func
probeVolumePlugins
()
[]
volume
.
VolumePlugin
{
allPlugins
:=
[]
volume
.
VolumePlugin
{}
allPlugins
=
append
(
allPlugins
,
empty_dir
.
ProbeVolumePlugins
()
...
)
allPlugins
=
append
(
allPlugins
,
git_repo
.
ProbeVolumePlugins
()
...
)
allPlugins
=
append
(
allPlugins
,
secret
.
ProbeVolumePlugins
()
...
)
return
allPlugins
}
func
makeTempDirOrDie
(
prefix
string
,
baseDir
string
)
string
{
if
baseDir
==
""
{
baseDir
=
"/tmp"
...
...
@@ -989,6 +1002,7 @@ func main() {
runServiceTest
,
runAPIVersionsTest
,
runMasterServiceTest
,
runWrapperVolumesPluginsTest
,
func
(
c
*
client
.
Client
)
{
runSelfLinkTestOnNamespace
(
c
,
api
.
NamespaceDefault
)
runSelfLinkTestOnNamespace
(
c
,
"other"
)
...
...
@@ -1038,8 +1052,8 @@ func main() {
// 1 pod infra container + 1 container from the service test.
// The total number of container created is 9
if
len
(
createdConts
)
!=
1
2
{
glog
.
Fatalf
(
"Expected 1
2
containers; got %v
\n\n
list of created containers:
\n\n
%#v
\n\n
Docker 1 Created:
\n\n
%#v
\n\n
Docker 2 Created:
\n\n
%#v
\n\n
"
,
len
(
createdConts
),
createdConts
.
List
(),
fakeDocker1
.
Created
,
fakeDocker2
.
Created
)
if
len
(
createdConts
)
!=
1
4
{
glog
.
Fatalf
(
"Expected 1
4
containers; got %v
\n\n
list of created containers:
\n\n
%#v
\n\n
Docker 1 Created:
\n\n
%#v
\n\n
Docker 2 Created:
\n\n
%#v
\n\n
"
,
len
(
createdConts
),
createdConts
.
List
(),
fakeDocker1
.
Created
,
fakeDocker2
.
Created
)
}
glog
.
Infof
(
"OK - found created containers: %#v"
,
createdConts
.
List
())
...
...
@@ -1097,3 +1111,72 @@ const (
}
}`
)
// This is a test to make sure multiple empty_dir wrapper based volumes should not affect each other
func
runWrapperVolumesPluginsTest
(
client
*
client
.
Client
)
{
// Make a secret object.
ns
:=
api
.
NamespaceDefault
s
:=
api
.
Secret
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"secret-name"
,
Namespace
:
ns
,
},
Data
:
map
[
string
][]
byte
{
"data"
:
[]
byte
(
"value1
\n
"
),
},
}
if
_
,
err
:=
client
.
Secrets
(
s
.
Namespace
)
.
Create
(
&
s
);
err
!=
nil
{
glog
.
Fatalf
(
"unable to create test secret: %v"
,
err
)
}
pod
:=
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"vol-container"
,
Image
:
"kubernetes/pause"
,
VolumeMounts
:
[]
api
.
VolumeMount
{
{
Name
:
"vol-secret"
,
MountPath
:
"/fake/path-1"
,
ReadOnly
:
true
,
},
{
Name
:
"vol-git"
,
MountPath
:
"/fake/path-2"
,
},
},
},
},
Volumes
:
[]
api
.
Volume
{
{
Name
:
"vol-secret"
,
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
SecretName
:
"secret-name"
,
},
},
},
{
Name
:
"vol-git"
,
VolumeSource
:
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepoVolumeSource
{
Repository
:
"https://github.com/kubernetes/kubedash"
,
},
},
},
},
},
}
pod
.
ObjectMeta
.
Name
=
"wrappedvolumes.foo"
foo
,
err
:=
client
.
Pods
(
api
.
NamespaceDefault
)
.
Create
(
pod
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Failed to create pod: %v, %v"
,
pod
,
err
)
}
if
err
:=
wait
.
Poll
(
time
.
Second
,
longTestTimeout
,
podRunning
(
client
,
foo
.
Namespace
,
foo
.
Name
));
err
!=
nil
{
glog
.
Fatalf
(
"FAILED: pod never started running %v"
,
err
)
}
glog
.
Info
(
"empty_dir wrapper based volumes doesn't affect each other: test passed."
)
}
pkg/volume/downwardapi/downwardapi.go
View file @
c0d49450
...
...
@@ -70,6 +70,7 @@ func (plugin *downwardAPIPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opt
pod
:
pod
,
podUID
:
pod
.
UID
,
plugin
:
plugin
,
wrappedVolumeSpec
:
volume
.
GetWrappedVolumeSpec
(
spec
.
Name
(),
downwardAPIPluginName
),
}
v
.
fieldReferenceFileNames
=
make
(
map
[
string
]
string
)
for
_
,
fileInfo
:=
range
spec
.
Volume
.
DownwardAPI
.
Items
{
...
...
@@ -81,7 +82,12 @@ func (plugin *downwardAPIPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opt
}
func
(
plugin
*
downwardAPIPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
return
&
downwardAPIVolumeCleaner
{
&
downwardAPIVolume
{
volName
:
volName
,
podUID
:
podUID
,
plugin
:
plugin
}},
nil
return
&
downwardAPIVolumeCleaner
{
&
downwardAPIVolume
{
volName
:
volName
,
podUID
:
podUID
,
plugin
:
plugin
,
wrappedVolumeSpec
:
volume
.
GetWrappedVolumeSpec
(
volName
,
downwardAPIPluginName
)},
},
nil
}
// downwardAPIVolume retrieves downward API data and placing them into the volume on the host.
...
...
@@ -92,11 +98,7 @@ type downwardAPIVolume struct {
podUID
types
.
UID
// TODO: remove this redundancy as soon NewCleaner func will have *api.POD and not only types.UID
plugin
*
downwardAPIPlugin
volume
.
MetricsNil
}
// This is the spec for the volume that this plugin wraps.
var
wrappedVolumeSpec
=
&
volume
.
Spec
{
Volume
:
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageMediumMemory
}}},
wrappedVolumeSpec
*
volume
.
Spec
}
// downwardAPIVolumeBuilder fetches info from downward API from the pod
...
...
@@ -130,7 +132,7 @@ func (b *downwardAPIVolumeBuilder) SetUp() error {
func
(
b
*
downwardAPIVolumeBuilder
)
SetUpAt
(
dir
string
)
error
{
glog
.
V
(
3
)
.
Infof
(
"Setting up a downwardAPI volume %v for pod %v/%v at %v"
,
b
.
volName
,
b
.
pod
.
Namespace
,
b
.
pod
.
Name
,
dir
)
// Wrap EmptyDir. Here we rely on the idempotency of the wrapped plugin to avoid repeatedly mounting
wrapped
,
err
:=
b
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
b
.
pod
,
*
b
.
opts
)
wrapped
,
err
:=
b
.
plugin
.
host
.
NewWrapperBuilder
(
b
.
wrappedVolumeSpec
,
b
.
pod
,
*
b
.
opts
)
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't setup downwardAPI volume %v for pod %v/%v: %s"
,
b
.
volName
,
b
.
pod
.
Namespace
,
b
.
pod
.
Name
,
err
.
Error
())
return
err
...
...
@@ -364,7 +366,7 @@ func (c *downwardAPIVolumeCleaner) TearDownAt(dir string) error {
glog
.
V
(
3
)
.
Infof
(
"Tearing down volume %v for pod %v at %v"
,
c
.
volName
,
c
.
podUID
,
dir
)
// Wrap EmptyDir, let it do the teardown.
wrapped
,
err
:=
c
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
c
.
podUID
)
wrapped
,
err
:=
c
.
plugin
.
host
.
NewWrapperCleaner
(
c
.
wrappedVolumeSpec
,
c
.
podUID
)
if
err
!=
nil
{
return
err
}
...
...
pkg/volume/downwardapi/downwardapi_test.go
View file @
c0d49450
...
...
@@ -39,12 +39,12 @@ func formatMap(m map[string]string) (fmtstr string) {
return
}
func
newTestHost
(
t
*
testing
.
T
,
client
client
.
Interface
,
basePath
string
)
volume
.
VolumeHost
{
func
newTestHost
(
t
*
testing
.
T
,
client
client
.
Interface
,
basePath
string
)
(
string
,
volume
.
VolumeHost
)
{
tempDir
,
err
:=
ioutil
.
TempDir
(
basePath
,
"downwardApi_volume_test."
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
}
return
volume
.
NewFakeVolumeHost
(
tempDir
,
client
,
empty_dir
.
ProbeVolumePlugins
())
return
tempDir
,
volume
.
NewFakeVolumeHost
(
tempDir
,
client
,
empty_dir
.
ProbeVolumePlugins
())
}
func
TestCanSupport
(
t
*
testing
.
T
)
{
...
...
@@ -54,7 +54,8 @@ func TestCanSupport(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
nil
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
nil
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
...
...
@@ -110,7 +111,8 @@ func TestLabels(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
rootDir
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -141,6 +143,17 @@ func TestLabels(t *testing.T) {
t
.
Errorf
(
"Failed to setup volume: %v"
,
err
)
}
// gitRepo volume should create it's own empty wrapper path
podWrapperMetadataDir
:=
fmt
.
Sprintf
(
"%v/pods/%v/plugins/kubernetes.io~empty-dir/wrapped_%v"
,
rootDir
,
testPodUID
,
testVolumeName
)
if
_
,
err
:=
os
.
Stat
(
podWrapperMetadataDir
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"SetUp() failed, empty-dir wrapper path was not created: %s"
,
podWrapperMetadataDir
)
}
else
{
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
}
}
var
data
[]
byte
data
,
err
=
ioutil
.
ReadFile
(
path
.
Join
(
volumePath
,
"labels"
))
if
err
!=
nil
{
...
...
@@ -189,7 +202,8 @@ func TestAnnotations(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -254,7 +268,8 @@ func TestName(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -320,7 +335,8 @@ func TestNamespace(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -379,7 +395,8 @@ func TestWriteTwiceNoUpdate(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -468,7 +485,8 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -577,7 +595,8 @@ func TestWriteWithUnixPath(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -656,7 +675,8 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
_
,
host
:=
newTestHost
(
t
,
fake
,
tmpDir
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
pkg/volume/git_repo/git_repo.go
View file @
c0d49450
...
...
@@ -64,6 +64,7 @@ func (plugin *gitRepoPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts vo
volName
:
spec
.
Name
(),
podUID
:
pod
.
UID
,
plugin
:
plugin
,
wrappedVolumeSpec
:
volume
.
GetWrappedVolumeSpec
(
spec
.
Name
(),
gitRepoPluginName
),
},
pod
:
*
pod
,
source
:
spec
.
Volume
.
GitRepo
.
Repository
,
...
...
@@ -80,6 +81,7 @@ func (plugin *gitRepoPlugin) NewCleaner(volName string, podUID types.UID) (volum
volName
:
volName
,
podUID
:
podUID
,
plugin
:
plugin
,
wrappedVolumeSpec
:
volume
.
GetWrappedVolumeSpec
(
volName
,
gitRepoPluginName
),
},
},
nil
}
...
...
@@ -90,6 +92,7 @@ type gitRepoVolume struct {
volName
string
podUID
types
.
UID
plugin
*
gitRepoPlugin
wrappedVolumeSpec
*
volume
.
Spec
volume
.
MetricsNil
}
...
...
@@ -128,11 +131,6 @@ func (b *gitRepoVolumeBuilder) SetUp() error {
return
b
.
SetUpAt
(
b
.
GetPath
())
}
// This is the spec for the volume that this plugin wraps.
var
wrappedVolumeSpec
=
&
volume
.
Spec
{
Volume
:
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}},
}
// SetUpAt creates new directory and clones a git repo.
func
(
b
*
gitRepoVolumeBuilder
)
SetUpAt
(
dir
string
)
error
{
if
volumeutil
.
IsReady
(
b
.
getMetaDir
())
{
...
...
@@ -140,7 +138,7 @@ func (b *gitRepoVolumeBuilder) SetUpAt(dir string) error {
}
// Wrap EmptyDir, let it do the setup.
wrapped
,
err
:=
b
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
b
.
pod
,
b
.
opts
)
wrapped
,
err
:=
b
.
plugin
.
host
.
NewWrapperBuilder
(
b
.
wrappedVolumeSpec
,
&
b
.
pod
,
b
.
opts
)
if
err
!=
nil
{
return
err
}
...
...
@@ -218,8 +216,9 @@ func (c *gitRepoVolumeCleaner) TearDown() error {
// TearDownAt simply deletes everything in the directory.
func
(
c
*
gitRepoVolumeCleaner
)
TearDownAt
(
dir
string
)
error
{
// Wrap EmptyDir, let it do the teardown.
wrapped
,
err
:=
c
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
c
.
podUID
)
wrapped
,
err
:=
c
.
plugin
.
host
.
NewWrapperCleaner
(
c
.
wrappedVolumeSpec
,
c
.
podUID
)
if
err
!=
nil
{
return
err
}
...
...
pkg/volume/git_repo/git_repo_test.go
View file @
c0d49450
...
...
@@ -32,17 +32,18 @@ import (
"k8s.io/kubernetes/pkg/volume/empty_dir"
)
func
newTestHost
(
t
*
testing
.
T
)
volume
.
VolumeHost
{
func
newTestHost
(
t
*
testing
.
T
)
(
string
,
volume
.
VolumeHost
)
{
tempDir
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"git_repo_test."
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
}
return
volume
.
NewFakeVolumeHost
(
tempDir
,
nil
,
empty_dir
.
ProbeVolumePlugins
())
return
tempDir
,
volume
.
NewFakeVolumeHost
(
tempDir
,
nil
,
empty_dir
.
ProbeVolumePlugins
())
}
func
TestCanSupport
(
t
*
testing
.
T
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
))
_
,
host
:=
newTestHost
(
t
)
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/git-repo"
)
if
err
!=
nil
{
...
...
@@ -218,7 +219,8 @@ func doTestPlugin(scenario struct {
allErrs
:=
[]
error
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
))
rootDir
,
host
:=
newTestHost
(
t
)
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/git-repo"
)
if
err
!=
nil
{
...
...
@@ -241,7 +243,8 @@ func doTestPlugin(scenario struct {
}
path
:=
builder
.
GetPath
()
if
!
strings
.
HasSuffix
(
path
,
"pods/poduid/volumes/kubernetes.io~git-repo/vol1"
)
{
suffix
:=
fmt
.
Sprintf
(
"pods/poduid/volumes/kubernetes.io~git-repo/%v"
,
scenario
.
vol
.
Name
)
if
!
strings
.
HasSuffix
(
path
,
suffix
)
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"Got unexpected path: %s"
,
path
))
return
allErrs
...
...
@@ -263,6 +266,19 @@ func doTestPlugin(scenario struct {
}
}
// gitRepo volume should create it's own empty wrapper path
podWrapperMetadataDir
:=
fmt
.
Sprintf
(
"%v/pods/poduid/plugins/kubernetes.io~empty-dir/wrapped_%v"
,
rootDir
,
scenario
.
vol
.
Name
)
if
_
,
err
:=
os
.
Stat
(
podWrapperMetadataDir
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"SetUp() failed, empty-dir wrapper path is not created: %s"
,
podWrapperMetadataDir
))
}
else
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"SetUp() failed: %v"
,
err
))
}
}
cleaner
,
err
:=
plug
.
NewCleaner
(
"vol1"
,
types
.
UID
(
"poduid"
))
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
...
...
pkg/volume/secret/secret.go
View file @
c0d49450
...
...
@@ -62,14 +62,33 @@ func (plugin *secretPlugin) CanSupport(spec *volume.Spec) bool {
func
(
plugin
*
secretPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Builder
,
error
)
{
return
&
secretVolumeBuilder
{
secretVolume
:
&
secretVolume
{
spec
.
Name
(),
pod
.
UID
,
plugin
,
plugin
.
host
.
GetMounter
(),
plugin
.
host
.
GetWriter
(),
volume
.
MetricsNil
{}},
secretVolume
:
&
secretVolume
{
spec
.
Name
(),
pod
.
UID
,
plugin
,
plugin
.
host
.
GetMounter
(),
plugin
.
host
.
GetWriter
(),
volume
.
MetricsNil
{},
volume
.
GetWrappedVolumeSpec
(
spec
.
Name
(),
secretPluginName
),
},
secretName
:
spec
.
Volume
.
Secret
.
SecretName
,
pod
:
*
pod
,
opts
:
&
opts
},
nil
opts
:
&
opts
,
},
nil
}
func
(
plugin
*
secretPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
return
&
secretVolumeCleaner
{
&
secretVolume
{
volName
,
podUID
,
plugin
,
plugin
.
host
.
GetMounter
(),
plugin
.
host
.
GetWriter
(),
volume
.
MetricsNil
{}}},
nil
return
&
secretVolumeCleaner
{
&
secretVolume
{
volName
,
podUID
,
plugin
,
plugin
.
host
.
GetMounter
(),
plugin
.
host
.
GetWriter
(),
volume
.
MetricsNil
{},
volume
.
GetWrappedVolumeSpec
(
volName
,
secretPluginName
),
},
},
nil
}
type
secretVolume
struct
{
...
...
@@ -79,6 +98,7 @@ type secretVolume struct {
mounter
mount
.
Interface
writer
ioutil
.
Writer
volume
.
MetricsNil
wrappedVolumeSpec
*
volume
.
Spec
}
var
_
volume
.
Volume
=
&
secretVolume
{}
...
...
@@ -111,11 +131,6 @@ func (b *secretVolumeBuilder) SetUp() error {
return
b
.
SetUpAt
(
b
.
GetPath
())
}
// This is the spec for the volume that this plugin wraps.
var
wrappedVolumeSpec
=
&
volume
.
Spec
{
Volume
:
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageMediumMemory
}}},
}
func
(
b
*
secretVolumeBuilder
)
getMetaDir
()
string
{
return
path
.
Join
(
b
.
plugin
.
host
.
GetPodPluginDir
(
b
.
podUID
,
util
.
EscapeQualifiedNameForDisk
(
secretPluginName
)),
b
.
volName
)
}
...
...
@@ -137,7 +152,7 @@ func (b *secretVolumeBuilder) SetUpAt(dir string) error {
glog
.
V
(
3
)
.
Infof
(
"Setting up volume %v for pod %v at %v"
,
b
.
volName
,
b
.
pod
.
UID
,
dir
)
// Wrap EmptyDir, let it do the setup.
wrapped
,
err
:=
b
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
b
.
pod
,
*
b
.
opts
)
wrapped
,
err
:=
b
.
plugin
.
host
.
NewWrapperBuilder
(
b
.
wrappedVolumeSpec
,
&
b
.
pod
,
*
b
.
opts
)
if
err
!=
nil
{
return
err
}
...
...
@@ -202,7 +217,7 @@ func (c *secretVolumeCleaner) TearDownAt(dir string) error {
glog
.
V
(
3
)
.
Infof
(
"Tearing down volume %v for pod %v at %v"
,
c
.
volName
,
c
.
podUID
,
dir
)
// Wrap EmptyDir, let it do the teardown.
wrapped
,
err
:=
c
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
c
.
podUID
)
wrapped
,
err
:=
c
.
plugin
.
host
.
NewWrapperCleaner
(
c
.
wrappedVolumeSpec
,
c
.
podUID
)
if
err
!=
nil
{
return
err
}
...
...
pkg/volume/secret/secret_test.go
View file @
c0d49450
...
...
@@ -74,7 +74,7 @@ func TestPlugin(t *testing.T) {
secret
=
secret
(
testNamespace
,
testName
)
client
=
testclient
.
NewSimpleFake
(
&
secret
)
pluginMgr
=
volume
.
VolumePluginMgr
{}
_
,
host
=
newTestHost
(
t
,
client
)
rootDir
,
host
=
newTestHost
(
t
,
client
)
)
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
host
)
...
...
@@ -110,6 +110,16 @@ func TestPlugin(t *testing.T) {
}
}
// secret volume should create it's own empty wrapper path
podWrapperMetadataDir
:=
fmt
.
Sprintf
(
"%v/pods/test_pod_uid/plugins/kubernetes.io~empty-dir/wrapped_test_volume_name"
,
rootDir
)
if
_
,
err
:=
os
.
Stat
(
podWrapperMetadataDir
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"SetUp() failed, empty-dir wrapper path is not created: %s"
,
podWrapperMetadataDir
)
}
else
{
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
}
}
doTestSecretDataInVolume
(
volumePath
,
secret
,
t
)
doTestCleanAndTeardown
(
plugin
,
testPodUID
,
testVolumeName
,
volumePath
,
t
)
}
...
...
pkg/volume/volume.go
View file @
c0d49450
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
volume
import
(
"fmt"
"io/ioutil"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
...
...
@@ -24,6 +25,10 @@ import (
"path"
)
const
(
randomLength
=
5
)
// Volume represents a directory used by pods or hosts on a node.
// All method implementations of methods in the volume interface must be idempotent.
type
Volume
interface
{
...
...
@@ -132,3 +137,22 @@ func RenameDirectory(oldPath, newName string) (string, error) {
}
return
newPath
,
nil
}
// Return the wrapper volume spec of specific volume plugin
func
GetWrappedVolumeSpec
(
volName
string
,
pluginName
string
)
*
Spec
{
// The name of wrapper volume is set to "wrapped_{wrapped_volume_name}"
wrapperVolumeName
:=
fmt
.
Sprintf
(
"wrapped_%v"
,
volName
)
var
volumeSpec
*
Spec
switch
pluginName
{
case
"kubernetes.io/downward-api"
,
"kubernetes.io/secret"
:
volumeSpec
=
&
Spec
{
Volume
:
&
api
.
Volume
{
Name
:
wrapperVolumeName
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageMediumMemory
}}},
}
case
"kubernetes.io/git-repo"
:
volumeSpec
=
&
Spec
{
Volume
:
&
api
.
Volume
{
Name
:
wrapperVolumeName
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}},
}
}
return
volumeSpec
}
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