expand volume.Spec to include full Volume and PV

This commit is contained in:
markturansky
2015-08-12 15:11:03 -04:00
parent b6f2f396ba
commit 0e7f73ad67
32 changed files with 148 additions and 142 deletions

View File

@@ -60,7 +60,8 @@ func (plugin *hostPathPlugin) Name() string {
}
func (plugin *hostPathPlugin) CanSupport(spec *volume.Spec) bool {
return spec.VolumeSource.HostPath != nil || spec.PersistentVolumeSource.HostPath != nil
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.HostPath != nil) ||
(spec.Volume != nil && spec.Volume.HostPath != nil)
}
func (plugin *hostPathPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
@@ -70,14 +71,14 @@ func (plugin *hostPathPlugin) GetAccessModes() []api.PersistentVolumeAccessMode
}
func (plugin *hostPathPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions, _ mount.Interface) (volume.Builder, error) {
if spec.VolumeSource.HostPath != nil {
if spec.Volume != nil && spec.Volume.HostPath != nil {
return &hostPathBuilder{
hostPath: &hostPath{path: spec.VolumeSource.HostPath.Path},
hostPath: &hostPath{path: spec.Volume.HostPath.Path},
readOnly: false,
}, nil
} else {
return &hostPathBuilder{
hostPath: &hostPath{path: spec.PersistentVolumeSource.HostPath.Path},
hostPath: &hostPath{path: spec.PersistentVolume.Spec.HostPath.Path},
readOnly: spec.ReadOnly,
}, nil
}
@@ -92,10 +93,10 @@ func (plugin *hostPathPlugin) NewRecycler(spec *volume.Spec) (volume.Recycler, e
}
func newRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) {
if spec.PersistentVolumeSource.HostPath == nil {
if spec.PersistentVolume == nil || spec.PersistentVolume.Spec.HostPath == nil {
return nil, fmt.Errorf("spec.PersistentVolumeSource.HostPath is nil")
}
return &hostPathRecycler{spec.Name, spec.PersistentVolumeSource.HostPath.Path, host}, nil
return &hostPathRecycler{spec.Name(), spec.PersistentVolume.Spec.HostPath.Path, host}, nil
}
// HostPath volumes represent a bare host file or directory mount.