From 649374ddb4b192b53fd37d305a58bbea800c6a5c Mon Sep 17 00:00:00 2001 From: markturansky Date: Wed, 29 Jul 2015 14:13:05 -0400 Subject: [PATCH] fixed newRecycler func for HostPath & NFS --- pkg/volume/host_path/host_path.go | 7 +++---- pkg/volume/nfs/nfs.go | 22 ++++++++-------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/pkg/volume/host_path/host_path.go b/pkg/volume/host_path/host_path.go index d9efc17e885..2ca9c46669d 100644 --- a/pkg/volume/host_path/host_path.go +++ b/pkg/volume/host_path/host_path.go @@ -86,11 +86,10 @@ func (plugin *hostPathPlugin) NewRecycler(spec *volume.Spec) (volume.Recycler, e } func newRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) { - if spec.VolumeSource.HostPath != nil { - return &hostPathRecycler{spec.Name, spec.VolumeSource.HostPath.Path, host}, nil - } else { - return &hostPathRecycler{spec.Name, spec.PersistentVolumeSource.HostPath.Path, host}, nil + if spec.PersistentVolumeSource.HostPath == nil { + return nil, fmt.Errorf("spec.PersistentVolumeSource.HostPath is nil") } + return &hostPathRecycler{spec.Name, spec.PersistentVolumeSource.HostPath.Path, host}, nil } // HostPath volumes represent a bare host file or directory mount. diff --git a/pkg/volume/nfs/nfs.go b/pkg/volume/nfs/nfs.go index 8776200b268..60689f107ea 100644 --- a/pkg/volume/nfs/nfs.go +++ b/pkg/volume/nfs/nfs.go @@ -223,21 +223,15 @@ func (c *nfsCleaner) TearDownAt(dir string) error { } func newRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) { - if spec.VolumeSource.HostPath != nil { - return &nfsRecycler{ - name: spec.Name, - server: spec.VolumeSource.NFS.Server, - path: spec.VolumeSource.NFS.Path, - host: host, - }, nil - } else { - return &nfsRecycler{ - name: spec.Name, - server: spec.PersistentVolumeSource.NFS.Server, - path: spec.PersistentVolumeSource.NFS.Path, - host: host, - }, nil + if spec.PersistentVolumeSource.NFS == nil { + return nil, fmt.Errorf("spec.PersistentVolumeSource.NFS is nil") } + return &nfsRecycler{ + name: spec.Name, + server: spec.PersistentVolumeSource.NFS.Server, + path: spec.PersistentVolumeSource.NFS.Path, + host: host, + }, nil } // nfsRecycler scrubs an NFS volume by running "rm -rf" on the volume in a pod.