@@ -25,7 +25,7 @@ import (
2525 crdv1 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/apis/crd/v1"
2626 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/controller/cache"
2727 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/volume"
28- v1 "k8s.io/api/core/v1"
28+ "k8s.io/api/core/v1"
2929 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030 "k8s.io/apimachinery/pkg/runtime"
3131 "k8s.io/apimachinery/pkg/util/uuid"
@@ -129,13 +129,18 @@ func (vs *volumeSnapshotter) getPVFromVolumeSnapshot(uniqueSnapshotName string,
129129 }
130130
131131 pvName := pvc .Spec .VolumeName
132- pv , err := vs .coreClient . CoreV1 (). PersistentVolumes (). Get ( pvName , metav1. GetOptions {} )
132+ pv , err := vs .getPVFromName ( pvName )
133133 if err != nil {
134134 return nil , fmt .Errorf ("Failed to retrieve PV %s from the API server: %q" , pvName , err )
135135 }
136136 return pv , nil
137137}
138138
139+ // Helper function to get PV from PV name
140+ func (vs * volumeSnapshotter ) getPVFromName (pvName string ) (* v1.PersistentVolume , error ) {
141+ return vs .coreClient .CoreV1 ().PersistentVolumes ().Get (pvName , metav1.GetOptions {})
142+ }
143+
139144// TODO: cache the VolumeSnapshotData list since this is only needed when controller restarts, checks
140145// whether there is existing VolumeSnapshotData refers to the snapshot already.
141146// Helper function that looks up VolumeSnapshotData for a VolumeSnapshot named snapshotName
@@ -286,7 +291,11 @@ func (vs *volumeSnapshotter) deleteSnapshot(spec *crdv1.VolumeSnapshotDataSpec)
286291 return fmt .Errorf ("%s is not supported volume for %#v" , volumeType , spec )
287292 }
288293 source := spec .VolumeSnapshotDataSource
289- err := plugin .SnapshotDelete (& source , nil /* *v1.PersistentVolume */ )
294+ pv , err := vs .getPVFromName (spec .PersistentVolumeRef .Name )
295+ if err != nil {
296+ glog .Warningf ("failed to retrieve PV %s from the API server: %q" , spec .PersistentVolumeRef .Name , err )
297+ }
298+ err = plugin .SnapshotDelete (& source , pv )
290299 if err != nil {
291300 return fmt .Errorf ("failed to delete snapshot %#v, err: %v" , source , err )
292301 }
0 commit comments