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
cd359ffa
Commit
cd359ffa
authored
May 10, 2015
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor volume interfaces to receive pod instead of ObjectReference
parent
738f403e
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
93 additions
and
88 deletions
+93
-88
volumes.go
pkg/kubelet/volumes.go
+5
-11
aws_ebs.go
pkg/volume/aws_ebs/aws_ebs.go
+2
-2
empty_dir.go
pkg/volume/empty_dir/empty_dir.go
+4
-4
empty_dir_test.go
pkg/volume/empty_dir/empty_dir_test.go
+8
-4
gce_pd.go
pkg/volume/gce_pd/gce_pd.go
+2
-2
gce_pd_test.go
pkg/volume/gce_pd/gce_pd_test.go
+2
-1
git_repo.go
pkg/volume/git_repo/git_repo.go
+8
-8
git_repo_test.go
pkg/volume/git_repo/git_repo_test.go
+4
-2
glusterfs.go
pkg/volume/glusterfs/glusterfs.go
+8
-8
glusterfs_test.go
pkg/volume/glusterfs/glusterfs_test.go
+2
-1
host_path.go
pkg/volume/host_path/host_path.go
+1
-1
host_path_test.go
pkg/volume/host_path/host_path_test.go
+2
-1
iscsi.go
pkg/volume/iscsi/iscsi.go
+2
-2
nfs.go
pkg/volume/nfs/nfs.go
+7
-7
nfs_test.go
pkg/volume/nfs/nfs_test.go
+2
-1
persistent_claim.go
pkg/volume/persistent_claim/persistent_claim.go
+3
-3
persistent_claim_test.go
pkg/volume/persistent_claim/persistent_claim_test.go
+4
-2
plugins.go
pkg/volume/plugins.go
+3
-3
secret.go
pkg/volume/secret/secret.go
+16
-18
secret_test.go
pkg/volume/secret/secret_test.go
+4
-3
testing.go
pkg/volume/testing.go
+4
-4
No files found.
pkg/kubelet/volumes.go
View file @
cd359ffa
...
...
@@ -56,8 +56,8 @@ func (vh *volumeHost) GetKubeClient() client.Interface {
return
vh
.
kubelet
.
kubeClient
}
func
(
vh
*
volumeHost
)
NewWrapperBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
b
,
err
:=
vh
.
kubelet
.
newVolumeBuilderFromPlugins
(
spec
,
pod
Ref
,
opts
,
mounter
)
func
(
vh
*
volumeHost
)
NewWrapperBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
b
,
err
:=
vh
.
kubelet
.
newVolumeBuilderFromPlugins
(
spec
,
pod
,
opts
,
mounter
)
if
err
==
nil
&&
b
==
nil
{
return
nil
,
errUnsupportedVolumeType
}
...
...
@@ -80,7 +80,7 @@ func (vh *volumeHost) NewWrapperCleaner(spec *volume.Spec, podUID types.UID, mou
return
c
,
nil
}
func
(
kl
*
Kubelet
)
newVolumeBuilderFromPlugins
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
kl
*
Kubelet
)
newVolumeBuilderFromPlugins
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
plugin
,
err
:=
kl
.
volumePluginMgr
.
FindPluginBySpec
(
spec
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"can't use volume plugins for %s: %v"
,
spew
.
Sprintf
(
"%#v"
,
*
spec
),
err
)
...
...
@@ -89,7 +89,7 @@ func (kl *Kubelet) newVolumeBuilderFromPlugins(spec *volume.Spec, podRef *api.Ob
// Not found but not an error
return
nil
,
nil
}
builder
,
err
:=
plugin
.
NewBuilder
(
spec
,
pod
Ref
,
opts
,
mounter
)
builder
,
err
:=
plugin
.
NewBuilder
(
spec
,
pod
,
opts
,
mounter
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to instantiate volume plugin for %s: %v"
,
spew
.
Sprintf
(
"%#v"
,
*
spec
),
err
)
}
...
...
@@ -102,12 +102,6 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
for
i
:=
range
pod
.
Spec
.
Volumes
{
volSpec
:=
&
pod
.
Spec
.
Volumes
[
i
]
podRef
,
err
:=
api
.
GetReference
(
pod
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error getting object reference for pod: %v"
,
pod
,
err
)
return
nil
,
err
}
rootContext
,
err
:=
kl
.
getRootDirContext
()
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -115,7 +109,7 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
// Try to use a plugin for this volume.
internal
:=
volume
.
NewSpecFromVolume
(
volSpec
)
builder
,
err
:=
kl
.
newVolumeBuilderFromPlugins
(
internal
,
pod
Ref
,
volume
.
VolumeOptions
{
rootContext
},
kl
.
mounter
)
builder
,
err
:=
kl
.
newVolumeBuilderFromPlugins
(
internal
,
pod
,
volume
.
VolumeOptions
{
rootContext
},
kl
.
mounter
)
if
err
!=
nil
{
glog
.
Errorf
(
"Could not create volume builder for pod %s: %v"
,
pod
.
UID
,
err
)
return
nil
,
err
...
...
pkg/volume/aws_ebs/aws_ebs.go
View file @
cd359ffa
...
...
@@ -68,9 +68,9 @@ func (plugin *awsElasticBlockStorePlugin) GetAccessModes() []api.AccessModeType
}
}
func
(
plugin
*
awsElasticBlockStorePlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
awsElasticBlockStorePlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
// Inject real implementations here, test through the internal function.
return
plugin
.
newBuilderInternal
(
spec
,
pod
Ref
.
UID
,
&
AWSDiskUtil
{},
mounter
)
return
plugin
.
newBuilderInternal
(
spec
,
pod
.
UID
,
&
AWSDiskUtil
{},
mounter
)
}
func
(
plugin
*
awsElasticBlockStorePlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
podUID
types
.
UID
,
manager
pdManager
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
...
...
pkg/volume/empty_dir/empty_dir.go
View file @
cd359ffa
...
...
@@ -71,11 +71,11 @@ func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool {
return
false
}
func
(
plugin
*
emptyDirPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
plugin
.
newBuilderInternal
(
spec
,
pod
Ref
,
mounter
,
&
realMountDetector
{
mounter
},
opts
)
func
(
plugin
*
emptyDirPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
plugin
.
newBuilderInternal
(
spec
,
pod
,
mounter
,
&
realMountDetector
{
mounter
},
opts
)
}
func
(
plugin
*
emptyDirPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
,
opts
volume
.
VolumeOptions
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
,
opts
volume
.
VolumeOptions
)
(
volume
.
Builder
,
error
)
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
...
...
@@ -85,7 +85,7 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, podRef *api.
medium
=
spec
.
VolumeSource
.
EmptyDir
.
Medium
}
return
&
emptyDir
{
podUID
:
pod
Ref
.
UID
,
podUID
:
pod
.
UID
,
volName
:
spec
.
Name
,
medium
:
medium
,
mounter
:
mounter
,
...
...
pkg/volume/empty_dir/empty_dir_test.go
View file @
cd359ffa
...
...
@@ -74,7 +74,8 @@ func TestPlugin(t *testing.T) {
}
mounter
:=
mount
.
FakeMounter
{}
mountDetector
:=
fakeMountDetector
{}
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mounter
,
&
mountDetector
,
volume
.
VolumeOptions
{
""
})
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
&
mounter
,
&
mountDetector
,
volume
.
VolumeOptions
{
""
})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -133,7 +134,8 @@ func TestPluginTmpfs(t *testing.T) {
}
mounter
:=
mount
.
FakeMounter
{}
mountDetector
:=
fakeMountDetector
{}
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mounter
,
&
mountDetector
,
volume
.
VolumeOptions
{
""
})
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
&
mounter
,
&
mountDetector
,
volume
.
VolumeOptions
{
""
})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -197,7 +199,8 @@ func TestPluginBackCompat(t *testing.T) {
spec
:=
&
api
.
Volume
{
Name
:
"vol1"
,
}
builder
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{
""
},
nil
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{
""
},
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -222,7 +225,8 @@ func TestPluginLegacy(t *testing.T) {
}
spec
:=
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}}
if
_
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
&
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mount
.
FakeMounter
{},
&
fakeMountDetector
{},
volume
.
VolumeOptions
{
""
});
err
==
nil
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
if
_
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
&
spec
),
pod
,
&
mount
.
FakeMounter
{},
&
fakeMountDetector
{},
volume
.
VolumeOptions
{
""
});
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
}
...
...
pkg/volume/gce_pd/gce_pd.go
View file @
cd359ffa
...
...
@@ -75,9 +75,9 @@ func (plugin *gcePersistentDiskPlugin) GetAccessModes() []api.AccessModeType {
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
// Inject real implementations here, test through the internal function.
return
plugin
.
newBuilderInternal
(
spec
,
pod
Ref
.
UID
,
&
GCEDiskUtil
{},
mounter
)
return
plugin
.
newBuilderInternal
(
spec
,
pod
.
UID
,
&
GCEDiskUtil
{},
mounter
)
}
func
(
plugin
*
gcePersistentDiskPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
podUID
types
.
UID
,
manager
pdManager
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
...
...
pkg/volume/gce_pd/gce_pd_test.go
View file @
cd359ffa
...
...
@@ -186,7 +186,8 @@ func TestPluginLegacy(t *testing.T) {
}
spec
:=
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{}}}
if
_
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{
""
},
nil
);
err
==
nil
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
if
_
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{
""
},
nil
);
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
}
...
...
pkg/volume/git_repo/git_repo.go
View file @
cd359ffa
...
...
@@ -67,13 +67,13 @@ func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool {
return
spec
.
VolumeSource
.
GitRepo
!=
nil
}
func
(
plugin
*
gitRepoPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
gitRepoPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
return
&
gitRepo
{
pod
Ref
:
*
podRef
,
pod
:
*
pod
,
volName
:
spec
.
Name
,
source
:
spec
.
VolumeSource
.
GitRepo
.
Repository
,
revision
:
spec
.
VolumeSource
.
GitRepo
.
Revision
,
...
...
@@ -91,7 +91,7 @@ func (plugin *gitRepoPlugin) NewCleaner(volName string, podUID types.UID, mounte
legacy
=
true
}
return
&
gitRepo
{
pod
Ref
:
api
.
ObjectReference
{
UID
:
podUID
},
pod
:
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}
},
volName
:
volName
,
plugin
:
plugin
,
legacyMode
:
legacy
,
...
...
@@ -103,7 +103,7 @@ func (plugin *gitRepoPlugin) NewCleaner(volName string, podUID types.UID, mounte
// These do not persist beyond the lifetime of a pod.
type
gitRepo
struct
{
volName
string
pod
Ref
api
.
ObjectReference
pod
api
.
Pod
source
string
revision
string
exec
exec
.
Interface
...
...
@@ -134,7 +134,7 @@ func (gr *gitRepo) SetUpAt(dir string) error {
}
// Wrap EmptyDir, let it do the setup.
wrapped
,
err
:=
gr
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
gr
.
pod
Ref
,
gr
.
opts
,
gr
.
mounter
)
wrapped
,
err
:=
gr
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
gr
.
pod
,
gr
.
opts
,
gr
.
mounter
)
if
err
!=
nil
{
return
err
}
...
...
@@ -172,7 +172,7 @@ func (gr *gitRepo) SetUpAt(dir string) error {
}
func
(
gr
*
gitRepo
)
getMetaDir
()
string
{
return
path
.
Join
(
gr
.
plugin
.
host
.
GetPodPluginDir
(
gr
.
pod
Ref
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
gitRepoPluginName
)),
gr
.
volName
)
return
path
.
Join
(
gr
.
plugin
.
host
.
GetPodPluginDir
(
gr
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
gitRepoPluginName
)),
gr
.
volName
)
}
func
(
gr
*
gitRepo
)
execCommand
(
command
string
,
args
[]
string
,
dir
string
)
([]
byte
,
error
)
{
...
...
@@ -186,7 +186,7 @@ func (gr *gitRepo) GetPath() string {
if
gr
.
legacyMode
{
name
=
gitRepoPluginLegacyName
}
return
gr
.
plugin
.
host
.
GetPodVolumeDir
(
gr
.
pod
Ref
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
gr
.
volName
)
return
gr
.
plugin
.
host
.
GetPodVolumeDir
(
gr
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
gr
.
volName
)
}
// TearDown simply deletes everything in the directory.
...
...
@@ -197,7 +197,7 @@ func (gr *gitRepo) TearDown() error {
// TearDownAt simply deletes everything in the directory.
func
(
gr
*
gitRepo
)
TearDownAt
(
dir
string
)
error
{
// Wrap EmptyDir, let it do the teardown.
wrapped
,
err
:=
gr
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
gr
.
pod
Ref
.
UID
,
gr
.
mounter
)
wrapped
,
err
:=
gr
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
gr
.
pod
.
UID
,
gr
.
mounter
)
if
err
!=
nil
{
return
err
}
...
...
pkg/volume/git_repo/git_repo_test.go
View file @
cd359ffa
...
...
@@ -119,7 +119,8 @@ func TestPlugin(t *testing.T) {
},
},
}
builder
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{
""
},
mount
.
New
())
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{
""
},
mount
.
New
())
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -175,7 +176,8 @@ func TestPluginLegacy(t *testing.T) {
}
spec
:=
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepoVolumeSource
{}}}
if
_
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{
""
},
nil
);
err
==
nil
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
if
_
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{
""
},
nil
);
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
}
...
...
pkg/volume/glusterfs/glusterfs.go
View file @
cd359ffa
...
...
@@ -64,19 +64,19 @@ func (plugin *glusterfsPlugin) GetAccessModes() []api.AccessModeType {
}
}
func
(
plugin
*
glusterfsPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
glusterfsPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
ep_name
:=
spec
.
VolumeSource
.
Glusterfs
.
EndpointsName
ns
:=
pod
Ref
.
Namespace
ns
:=
pod
.
Namespace
ep
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
Endpoints
(
ns
)
.
Get
(
ep_name
)
if
err
!=
nil
{
glog
.
Errorf
(
"Glusterfs: failed to get endpoints %s[%v]"
,
ep_name
,
err
)
return
nil
,
err
}
glog
.
V
(
1
)
.
Infof
(
"Glusterfs: endpoints %v"
,
ep
)
return
plugin
.
newBuilderInternal
(
spec
,
ep
,
pod
Ref
,
mounter
,
exec
.
New
())
return
plugin
.
newBuilderInternal
(
spec
,
ep
,
pod
,
mounter
,
exec
.
New
())
}
func
(
plugin
*
glusterfsPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
ep
*
api
.
Endpoints
,
pod
Ref
*
api
.
ObjectReference
,
mounter
mount
.
Interface
,
exe
exec
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
glusterfsPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
ep
*
api
.
Endpoints
,
pod
*
api
.
Pod
,
mounter
mount
.
Interface
,
exe
exec
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
&
glusterfs
{
volName
:
spec
.
Name
,
hosts
:
ep
,
...
...
@@ -84,7 +84,7 @@ func (plugin *glusterfsPlugin) newBuilderInternal(spec *volume.Spec, ep *api.End
readonly
:
spec
.
VolumeSource
.
Glusterfs
.
ReadOnly
,
mounter
:
mounter
,
exe
:
exe
,
pod
Ref
:
podRef
,
pod
:
pod
,
plugin
:
plugin
,
},
nil
}
...
...
@@ -97,7 +97,7 @@ func (plugin *glusterfsPlugin) newCleanerInternal(volName string, podUID types.U
return
&
glusterfs
{
volName
:
volName
,
mounter
:
mounter
,
pod
Ref
:
&
api
.
ObjectReference
{
UID
:
podUID
},
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}
},
plugin
:
plugin
,
},
nil
}
...
...
@@ -105,7 +105,7 @@ func (plugin *glusterfsPlugin) newCleanerInternal(volName string, podUID types.U
// Glusterfs volumes represent a bare host file or directory mount of an Glusterfs export.
type
glusterfs
struct
{
volName
string
pod
Ref
*
api
.
ObjectReference
pod
*
api
.
Pod
hosts
*
api
.
Endpoints
path
string
readonly
bool
...
...
@@ -142,7 +142,7 @@ func (glusterfsVolume *glusterfs) SetUpAt(dir string) error {
func
(
glusterfsVolume
*
glusterfs
)
GetPath
()
string
{
name
:=
glusterfsPluginName
return
glusterfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
glusterfsVolume
.
pod
Ref
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
glusterfsVolume
.
volName
)
return
glusterfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
glusterfsVolume
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
glusterfsVolume
.
volName
)
}
func
(
glusterfsVolume
*
glusterfs
)
TearDown
()
error
{
...
...
pkg/volume/glusterfs/glusterfs_test.go
View file @
cd359ffa
...
...
@@ -94,7 +94,8 @@ func TestPlugin(t *testing.T) {
func
(
cmd
string
,
args
...
string
)
exec
.
Cmd
{
return
exec
.
InitFakeCmd
(
&
fcmd
,
cmd
,
args
...
)
},
},
}
builder
,
err
:=
plug
.
(
*
glusterfsPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
ep
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mount
.
FakeMounter
{},
&
fake
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
(
*
glusterfsPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
ep
,
pod
,
&
mount
.
FakeMounter
{},
&
fake
)
volumePath
:=
builder
.
GetPath
()
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
...
...
pkg/volume/host_path/host_path.go
View file @
cd359ffa
...
...
@@ -58,7 +58,7 @@ func (plugin *hostPathPlugin) GetAccessModes() []api.AccessModeType {
}
}
func
(
plugin
*
hostPathPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
_
volume
.
VolumeOptions
,
_
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
hostPathPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
_
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
if
spec
.
VolumeSource
.
HostPath
!=
nil
{
return
&
hostPath
{
spec
.
VolumeSource
.
HostPath
.
Path
},
nil
}
else
{
...
...
pkg/volume/host_path/host_path_test.go
View file @
cd359ffa
...
...
@@ -68,7 +68,8 @@ func TestPlugin(t *testing.T) {
Name
:
"vol1"
,
VolumeSource
:
api
.
VolumeSource
{
HostPath
:
&
api
.
HostPathVolumeSource
{
"/vol1"
}},
}
builder
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{},
nil
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{},
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
pkg/volume/iscsi/iscsi.go
View file @
cd359ffa
...
...
@@ -72,9 +72,9 @@ func (plugin *ISCSIPlugin) GetAccessModes() []api.AccessModeType {
}
}
func
(
plugin
*
ISCSIPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
ISCSIPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
// Inject real implementations here, test through the internal function.
return
plugin
.
newBuilderInternal
(
spec
,
pod
Ref
.
UID
,
&
ISCSIUtil
{},
mounter
)
return
plugin
.
newBuilderInternal
(
spec
,
pod
.
UID
,
&
ISCSIUtil
{},
mounter
)
}
func
(
plugin
*
ISCSIPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
podUID
types
.
UID
,
manager
diskManager
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
...
...
pkg/volume/nfs/nfs.go
View file @
cd359ffa
...
...
@@ -64,18 +64,18 @@ func (plugin *nfsPlugin) GetAccessModes() []api.AccessModeType {
}
}
func
(
plugin
*
nfsPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
_
volume
.
VolumeOptions
,
_
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
plugin
.
newBuilderInternal
(
spec
,
pod
Ref
,
plugin
.
mounter
)
func
(
plugin
*
nfsPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
_
volume
.
VolumeOptions
,
_
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
plugin
.
newBuilderInternal
(
spec
,
pod
,
plugin
.
mounter
)
}
func
(
plugin
*
nfsPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
nfsPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
&
nfs
{
volName
:
spec
.
Name
,
server
:
spec
.
VolumeSource
.
NFS
.
Server
,
exportPath
:
spec
.
VolumeSource
.
NFS
.
Path
,
readOnly
:
spec
.
VolumeSource
.
NFS
.
ReadOnly
,
mounter
:
mounter
,
pod
Ref
:
podRef
,
pod
:
pod
,
plugin
:
plugin
,
},
nil
}
...
...
@@ -91,7 +91,7 @@ func (plugin *nfsPlugin) newCleanerInternal(volName string, podUID types.UID, mo
exportPath
:
""
,
readOnly
:
false
,
mounter
:
mounter
,
pod
Ref
:
&
api
.
ObjectReference
{
UID
:
podUID
},
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}
},
plugin
:
plugin
,
},
nil
}
...
...
@@ -99,7 +99,7 @@ func (plugin *nfsPlugin) newCleanerInternal(volName string, podUID types.UID, mo
// NFS volumes represent a bare host file or directory mount of an NFS export.
type
nfs
struct
{
volName
string
pod
Ref
*
api
.
ObjectReference
pod
*
api
.
Pod
server
string
exportPath
string
readOnly
bool
...
...
@@ -158,7 +158,7 @@ func (nfsVolume *nfs) SetUpAt(dir string) error {
func
(
nfsVolume
*
nfs
)
GetPath
()
string
{
name
:=
nfsPluginName
return
nfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
nfsVolume
.
pod
Ref
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
nfsVolume
.
volName
)
return
nfsVolume
.
plugin
.
host
.
GetPodVolumeDir
(
nfsVolume
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
nfsVolume
.
volName
)
}
func
(
nfsVolume
*
nfs
)
TearDown
()
error
{
...
...
pkg/volume/nfs/nfs_test.go
View file @
cd359ffa
...
...
@@ -78,7 +78,8 @@ func TestPlugin(t *testing.T) {
VolumeSource
:
api
.
VolumeSource
{
NFS
:
&
api
.
NFSVolumeSource
{
"localhost"
,
"/tmp"
,
false
}},
}
fake
:=
&
mount
.
FakeMounter
{}
builder
,
err
:=
plug
.
(
*
nfsPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
fake
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
(
*
nfsPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
fake
)
volumePath
:=
builder
.
GetPath
()
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
...
...
pkg/volume/persistent_claim/persistent_claim.go
View file @
cd359ffa
...
...
@@ -51,8 +51,8 @@ func (plugin *persistentClaimPlugin) CanSupport(spec *volume.Spec) bool {
return
spec
.
VolumeSource
.
PersistentVolumeClaimVolumeSource
!=
nil
}
func
(
plugin
*
persistentClaimPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
claim
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
PersistentVolumeClaims
(
pod
Ref
.
Namespace
)
.
Get
(
spec
.
VolumeSource
.
PersistentVolumeClaimVolumeSource
.
ClaimName
)
func
(
plugin
*
persistentClaimPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
claim
,
err
:=
plugin
.
host
.
GetKubeClient
()
.
PersistentVolumeClaims
(
pod
.
Namespace
)
.
Get
(
spec
.
VolumeSource
.
PersistentVolumeClaimVolumeSource
.
ClaimName
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error finding claim: %+v
\n
"
,
spec
.
VolumeSource
.
PersistentVolumeClaimVolumeSource
.
ClaimName
)
return
nil
,
err
...
...
@@ -68,7 +68,7 @@ func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, podRef *api.O
return
nil
,
err
}
builder
,
err
:=
plugin
.
host
.
NewWrapperBuilder
(
volume
.
NewSpecFromPersistentVolume
(
pv
),
pod
Ref
,
opts
,
mounter
)
builder
,
err
:=
plugin
.
host
.
NewWrapperBuilder
(
volume
.
NewSpecFromPersistentVolume
(
pv
),
pod
,
opts
,
mounter
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error creating builder for claim: %+v
\n
"
,
claim
.
Name
)
return
nil
,
err
...
...
pkg/volume/persistent_claim/persistent_claim_test.go
View file @
cd359ffa
...
...
@@ -169,7 +169,8 @@ func TestNewBuilder(t *testing.T) {
Name
:
"vol1"
,
VolumeSource
:
item
.
podVolume
,
}
builder
,
err
:=
plug
.
NewBuilder
(
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{},
nil
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -229,7 +230,8 @@ func TestNewBuilderClaimNotBound(t *testing.T) {
Name
:
"vol1"
,
VolumeSource
:
podVolume
,
}
builder
,
err
:=
plug
.
NewBuilder
(
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
volume
.
VolumeOptions
{},
nil
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
builder
,
err
:=
plug
.
NewBuilder
(
spec
,
pod
,
volume
.
VolumeOptions
{},
nil
)
if
builder
!=
nil
{
t
.
Errorf
(
"Expected a nil builder if the claim wasn't bound"
)
}
...
...
pkg/volume/plugins.go
View file @
cd359ffa
...
...
@@ -62,8 +62,8 @@ type VolumePlugin interface {
// NewBuilder creates a new volume.Builder from an API specification.
// Ownership of the spec pointer in *not* transferred.
// - spec: The api.Volume spec
// - pod
Ref: a reference to t
he enclosing pod
NewBuilder
(
spec
*
Spec
,
podRef
*
api
.
ObjectReference
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
// - pod
: T
he enclosing pod
NewBuilder
(
spec
*
Spec
,
podRef
*
api
.
Pod
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
// NewCleaner creates a new volume.Cleaner from recoverable state.
// - name: The volume name, as per the api.Volume spec.
...
...
@@ -106,7 +106,7 @@ type VolumeHost interface {
// the provided spec. This is used to implement volume plugins which
// "wrap" other plugins. For example, the "secret" volume is
// implemented in terms of the "emptyDir" volume.
NewWrapperBuilder
(
spec
*
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
NewWrapperBuilder
(
spec
*
Spec
,
pod
*
api
.
Pod
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
// NewWrapperCleaner finds an appropriate plugin with which to handle
// the provided spec. See comments on NewWrapperBuilder for more
...
...
pkg/volume/secret/secret.go
View file @
cd359ffa
...
...
@@ -44,6 +44,8 @@ type secretPlugin struct {
host
volume
.
VolumeHost
}
var
_
volume
.
VolumePlugin
=
&
secretPlugin
{}
func
(
plugin
*
secretPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
plugin
.
host
=
host
}
...
...
@@ -56,12 +58,8 @@ func (plugin *secretPlugin) CanSupport(spec *volume.Spec) bool {
return
spec
.
VolumeSource
.
Secret
!=
nil
}
func
(
plugin
*
secretPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
podRef
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
plugin
.
newBuilderInternal
(
spec
,
podRef
,
opts
,
mounter
)
}
func
(
plugin
*
secretPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
podRef
*
api
.
ObjectReference
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
&
secretVolume
{
spec
.
Name
,
*
podRef
,
plugin
,
spec
.
VolumeSource
.
Secret
.
SecretName
,
&
opts
,
mounter
},
nil
func
(
plugin
*
secretPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
return
&
secretVolume
{
spec
.
Name
,
*
pod
,
plugin
,
spec
.
VolumeSource
.
Secret
.
SecretName
,
&
opts
,
mounter
},
nil
}
func
(
plugin
*
secretPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
...
...
@@ -69,14 +67,14 @@ func (plugin *secretPlugin) NewCleaner(volName string, podUID types.UID, mounter
}
func
(
plugin
*
secretPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
return
&
secretVolume
{
volName
,
api
.
ObjectReference
{
UID
:
podUID
},
plugin
,
""
,
nil
,
mounter
},
nil
return
&
secretVolume
{
volName
,
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}
},
plugin
,
""
,
nil
,
mounter
},
nil
}
// secretVolume handles retrieving secrets from the API server
// and placing them into the volume on the host.
type
secretVolume
struct
{
volName
string
pod
Ref
api
.
ObjectReference
pod
api
.
Pod
plugin
*
secretPlugin
secretName
string
opts
*
volume
.
VolumeOptions
...
...
@@ -98,10 +96,10 @@ func (sv *secretVolume) SetUpAt(dir string) error {
return
nil
}
glog
.
V
(
3
)
.
Infof
(
"Setting up volume %v for pod %v at %v"
,
sv
.
volName
,
sv
.
pod
Ref
.
UID
,
dir
)
glog
.
V
(
3
)
.
Infof
(
"Setting up volume %v for pod %v at %v"
,
sv
.
volName
,
sv
.
pod
.
UID
,
dir
)
// Wrap EmptyDir, let it do the setup.
wrapped
,
err
:=
sv
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
sv
.
pod
Ref
,
*
sv
.
opts
,
sv
.
mounter
)
wrapped
,
err
:=
sv
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
sv
.
pod
,
*
sv
.
opts
,
sv
.
mounter
)
if
err
!=
nil
{
return
err
}
...
...
@@ -114,14 +112,14 @@ func (sv *secretVolume) SetUpAt(dir string) error {
return
fmt
.
Errorf
(
"Cannot setup secret volume %v because kube client is not configured"
,
sv
)
}
secret
,
err
:=
kubeClient
.
Secrets
(
sv
.
pod
Ref
.
Namespace
)
.
Get
(
sv
.
secretName
)
secret
,
err
:=
kubeClient
.
Secrets
(
sv
.
pod
.
Namespace
)
.
Get
(
sv
.
secretName
)
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't get secret %v/%v"
,
sv
.
pod
Ref
.
Namespace
,
sv
.
secretName
)
glog
.
Errorf
(
"Couldn't get secret %v/%v"
,
sv
.
pod
.
Namespace
,
sv
.
secretName
)
return
err
}
else
{
totalBytes
:=
totalSecretBytes
(
secret
)
glog
.
V
(
3
)
.
Infof
(
"Received secret %v/%v containing (%v) pieces of data, %v total bytes"
,
sv
.
pod
Ref
.
Namespace
,
sv
.
pod
.
Namespace
,
sv
.
secretName
,
len
(
secret
.
Data
),
totalBytes
)
...
...
@@ -129,7 +127,7 @@ func (sv *secretVolume) SetUpAt(dir string) error {
for
name
,
data
:=
range
secret
.
Data
{
hostFilePath
:=
path
.
Join
(
dir
,
name
)
glog
.
V
(
3
)
.
Infof
(
"Writing secret data %v/%v/%v (%v bytes) to host file %v"
,
sv
.
pod
Ref
.
Namespace
,
sv
.
secretName
,
name
,
len
(
data
),
hostFilePath
)
glog
.
V
(
3
)
.
Infof
(
"Writing secret data %v/%v/%v (%v bytes) to host file %v"
,
sv
.
pod
.
Namespace
,
sv
.
secretName
,
name
,
len
(
data
),
hostFilePath
)
err
:=
ioutil
.
WriteFile
(
hostFilePath
,
data
,
0444
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error writing secret data to host path: %v, %v"
,
hostFilePath
,
err
)
...
...
@@ -152,7 +150,7 @@ func totalSecretBytes(secret *api.Secret) int {
}
func
(
sv
*
secretVolume
)
GetPath
()
string
{
return
sv
.
plugin
.
host
.
GetPodVolumeDir
(
sv
.
pod
Ref
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
secretPluginName
),
sv
.
volName
)
return
sv
.
plugin
.
host
.
GetPodVolumeDir
(
sv
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
secretPluginName
),
sv
.
volName
)
}
func
(
sv
*
secretVolume
)
TearDown
()
error
{
...
...
@@ -160,10 +158,10 @@ func (sv *secretVolume) TearDown() error {
}
func
(
sv
*
secretVolume
)
TearDownAt
(
dir
string
)
error
{
glog
.
V
(
3
)
.
Infof
(
"Tearing down volume %v for pod %v at %v"
,
sv
.
volName
,
sv
.
pod
Ref
.
UID
,
dir
)
glog
.
V
(
3
)
.
Infof
(
"Tearing down volume %v for pod %v at %v"
,
sv
.
volName
,
sv
.
pod
.
UID
,
dir
)
// Wrap EmptyDir, let it do the teardown.
wrapped
,
err
:=
sv
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
sv
.
pod
Ref
.
UID
,
sv
.
mounter
)
wrapped
,
err
:=
sv
.
plugin
.
host
.
NewWrapperCleaner
(
wrappedVolumeSpec
,
sv
.
pod
.
UID
,
sv
.
mounter
)
if
err
!=
nil
{
return
err
}
...
...
@@ -171,5 +169,5 @@ func (sv *secretVolume) TearDownAt(dir string) error {
}
func
(
sv
*
secretVolume
)
getMetaDir
()
string
{
return
path
.
Join
(
sv
.
plugin
.
host
.
GetPodPluginDir
(
sv
.
pod
Ref
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
secretPluginName
)),
sv
.
volName
)
return
path
.
Join
(
sv
.
plugin
.
host
.
GetPodPluginDir
(
sv
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
secretPluginName
)),
sv
.
volName
)
}
pkg/volume/secret/secret_test.go
View file @
cd359ffa
...
...
@@ -60,7 +60,7 @@ func TestCanSupport(t *testing.T) {
func
TestPlugin
(
t
*
testing
.
T
)
{
var
(
testPodUID
=
"test_pod_uid"
testPodUID
=
types
.
UID
(
"test_pod_uid"
)
testVolumeName
=
"test_volume_name"
testNamespace
=
"test_secret_namespace"
testName
=
"test_secret_name"
...
...
@@ -97,7 +97,8 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Can't find the plugin by name"
)
}
builder
,
err
:=
plugin
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
volumeSpec
),
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
testPodUID
)},
volume
.
VolumeOptions
{},
&
mount
.
FakeMounter
{})
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
testPodUID
}}
builder
,
err
:=
plugin
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
volumeSpec
),
pod
,
volume
.
VolumeOptions
{},
&
mount
.
FakeMounter
{})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -139,7 +140,7 @@ func TestPlugin(t *testing.T) {
}
}
cleaner
,
err
:=
plugin
.
NewCleaner
(
testVolumeName
,
t
ypes
.
UID
(
testPodUID
)
,
mount
.
New
())
cleaner
,
err
:=
plugin
.
NewCleaner
(
testVolumeName
,
t
estPodUID
,
mount
.
New
())
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
...
...
pkg/volume/testing.go
View file @
cd359ffa
...
...
@@ -56,12 +56,12 @@ func (f *fakeVolumeHost) GetKubeClient() client.Interface {
return
f
.
kubeClient
}
func
(
f
*
fakeVolumeHost
)
NewWrapperBuilder
(
spec
*
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
{
func
(
f
*
fakeVolumeHost
)
NewWrapperBuilder
(
spec
*
Spec
,
pod
*
api
.
Pod
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
{
plug
,
err
:=
f
.
pluginMgr
.
FindPluginBySpec
(
spec
)
if
err
!=
nil
{
return
nil
,
err
}
return
plug
.
NewBuilder
(
spec
,
pod
Ref
,
opts
,
mounter
)
return
plug
.
NewBuilder
(
spec
,
pod
,
opts
,
mounter
)
}
func
(
f
*
fakeVolumeHost
)
NewWrapperCleaner
(
spec
*
Spec
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
Cleaner
,
error
)
{
...
...
@@ -96,8 +96,8 @@ func (plugin *FakeVolumePlugin) CanSupport(spec *Spec) bool {
return
true
}
func
(
plugin
*
FakeVolumePlugin
)
NewBuilder
(
spec
*
Spec
,
pod
Ref
*
api
.
ObjectReference
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
{
return
&
FakeVolume
{
pod
Ref
.
UID
,
spec
.
Name
,
plugin
},
nil
func
(
plugin
*
FakeVolumePlugin
)
NewBuilder
(
spec
*
Spec
,
pod
*
api
.
Pod
,
opts
VolumeOptions
,
mounter
mount
.
Interface
)
(
Builder
,
error
)
{
return
&
FakeVolume
{
pod
.
UID
,
spec
.
Name
,
plugin
},
nil
}
func
(
plugin
*
FakeVolumePlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
Cleaner
,
error
)
{
...
...
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