mirror of https://github.com/k3s-io/k3s
Refactor volume interfaces to receive pod instead of ObjectReference
parent
738f403eea
commit
cd359ffa73
|
@ -56,8 +56,8 @@ func (vh *volumeHost) GetKubeClient() client.Interface {
|
|||
return vh.kubelet.kubeClient
|
||||
}
|
||||
|
||||
func (vh *volumeHost) NewWrapperBuilder(spec *volume.Spec, podRef *api.ObjectReference, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
b, err := vh.kubelet.newVolumeBuilderFromPlugins(spec, podRef, 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, podRef *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, podRef, 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, podRef, 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
|
||||
|
|
|
@ -68,9 +68,9 @@ func (plugin *awsElasticBlockStorePlugin) GetAccessModes() []api.AccessModeType
|
|||
}
|
||||
}
|
||||
|
||||
func (plugin *awsElasticBlockStorePlugin) NewBuilder(spec *volume.Spec, podRef *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, podRef.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) {
|
||||
|
|
|
@ -71,11 +71,11 @@ func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (plugin *emptyDirPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
return plugin.newBuilderInternal(spec, podRef, 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, podRef *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: podRef.UID,
|
||||
podUID: pod.UID,
|
||||
volName: spec.Name,
|
||||
medium: medium,
|
||||
mounter: mounter,
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -75,9 +75,9 @@ func (plugin *gcePersistentDiskPlugin) GetAccessModes() []api.AccessModeType {
|
|||
}
|
||||
}
|
||||
|
||||
func (plugin *gcePersistentDiskPlugin) NewBuilder(spec *volume.Spec, podRef *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, podRef.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) {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -67,13 +67,13 @@ func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool {
|
|||
return spec.VolumeSource.GitRepo != nil
|
||||
}
|
||||
|
||||
func (plugin *gitRepoPlugin) NewBuilder(spec *volume.Spec, podRef *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{
|
||||
podRef: *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{
|
||||
podRef: 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
|
||||
podRef 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.podRef, 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.podRef.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.podRef.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.podRef.UID, gr.mounter)
|
||||
wrapped, err := gr.plugin.host.NewWrapperCleaner(wrappedVolumeSpec, gr.pod.UID, gr.mounter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -64,19 +64,19 @@ func (plugin *glusterfsPlugin) GetAccessModes() []api.AccessModeType {
|
|||
}
|
||||
}
|
||||
|
||||
func (plugin *glusterfsPlugin) NewBuilder(spec *volume.Spec, podRef *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 := podRef.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, podRef, mounter, exec.New())
|
||||
return plugin.newBuilderInternal(spec, ep, pod, mounter, exec.New())
|
||||
}
|
||||
|
||||
func (plugin *glusterfsPlugin) newBuilderInternal(spec *volume.Spec, ep *api.Endpoints, podRef *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,
|
||||
podRef: 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,
|
||||
podRef: &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
|
||||
podRef *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.podRef.UID, util.EscapeQualifiedNameForDisk(name), glusterfsVolume.volName)
|
||||
return glusterfsVolume.plugin.host.GetPodVolumeDir(glusterfsVolume.pod.UID, util.EscapeQualifiedNameForDisk(name), glusterfsVolume.volName)
|
||||
}
|
||||
|
||||
func (glusterfsVolume *glusterfs) TearDown() error {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -58,7 +58,7 @@ func (plugin *hostPathPlugin) GetAccessModes() []api.AccessModeType {
|
|||
}
|
||||
}
|
||||
|
||||
func (plugin *hostPathPlugin) NewBuilder(spec *volume.Spec, podRef *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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -72,9 +72,9 @@ func (plugin *ISCSIPlugin) GetAccessModes() []api.AccessModeType {
|
|||
}
|
||||
}
|
||||
|
||||
func (plugin *ISCSIPlugin) NewBuilder(spec *volume.Spec, podRef *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, podRef.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) {
|
||||
|
|
|
@ -64,18 +64,18 @@ func (plugin *nfsPlugin) GetAccessModes() []api.AccessModeType {
|
|||
}
|
||||
}
|
||||
|
||||
func (plugin *nfsPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, _ volume.VolumeOptions, _ mount.Interface) (volume.Builder, error) {
|
||||
return plugin.newBuilderInternal(spec, podRef, 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, podRef *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,
|
||||
podRef: 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,
|
||||
podRef: &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
|
||||
podRef *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.podRef.UID, util.EscapeQualifiedNameForDisk(name), nfsVolume.volName)
|
||||
return nfsVolume.plugin.host.GetPodVolumeDir(nfsVolume.pod.UID, util.EscapeQualifiedNameForDisk(name), nfsVolume.volName)
|
||||
}
|
||||
|
||||
func (nfsVolume *nfs) TearDown() error {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -51,8 +51,8 @@ func (plugin *persistentClaimPlugin) CanSupport(spec *volume.Spec) bool {
|
|||
return spec.VolumeSource.PersistentVolumeClaimVolumeSource != nil
|
||||
}
|
||||
|
||||
func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, podRef *api.ObjectReference, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
claim, err := plugin.host.GetKubeClient().PersistentVolumeClaims(podRef.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), podRef, 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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
// - podRef: a reference to the enclosing pod
|
||||
NewBuilder(spec *Spec, podRef *api.ObjectReference, opts VolumeOptions, mounter mount.Interface) (Builder, error)
|
||||
// - pod: The 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, podRef *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
|
||||
|
|
|
@ -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
|
||||
podRef 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.podRef.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.podRef, *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.podRef.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.podRef.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.podRef.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.podRef.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.podRef.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.podRef.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.podRef.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.podRef.UID, util.EscapeQualifiedNameForDisk(secretPluginName)), sv.volName)
|
||||
return path.Join(sv.plugin.host.GetPodPluginDir(sv.pod.UID, util.EscapeQualifiedNameForDisk(secretPluginName)), sv.volName)
|
||||
}
|
||||
|
|
|
@ -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, types.UID(testPodUID), mount.New())
|
||||
cleaner, err := plugin.NewCleaner(testVolumeName, testPodUID, mount.New())
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Cleaner: %v", err)
|
||||
}
|
||||
|
|
|
@ -56,12 +56,12 @@ func (f *fakeVolumeHost) GetKubeClient() client.Interface {
|
|||
return f.kubeClient
|
||||
}
|
||||
|
||||
func (f *fakeVolumeHost) NewWrapperBuilder(spec *Spec, podRef *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, podRef, 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, podRef *api.ObjectReference, opts VolumeOptions, mounter mount.Interface) (Builder, error) {
|
||||
return &FakeVolume{podRef.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) {
|
||||
|
|
Loading…
Reference in New Issue