Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin delete volume #9

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
// TODO wait for CSI VolumeSource API
PersistentVolumeSource: v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
//TODO use a unique volume handle
Driver: p.driverName,
VolumeHandle: rep.VolumeInfo.Id,
VolumeHandle: p.volumeIdToHandle(rep.VolumeInfo.Id),
},
},
},
Expand All @@ -253,7 +252,33 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
}

func (p *csiProvisioner) Delete(volume *v1.PersistentVolume) error {
glog.Infof("Provisioner %s Delete(..) called..")
// TODO wait for CSI VolumeSource API to get volume id
return nil
if volume == nil || volume.Spec.CSI == nil {
return fmt.Errorf("invalid CSI PV")
}
ann, ok := volume.Annotations[provisionerIDAnn]
if !ok {
return fmt.Errorf("identity annotation not found on PV")
}
if ann != p.identity {
return &controller.IgnoredError{Reason: "identity annotation on PV does not match ours"}
}
volumeId := p.volumeHandleToId(volume.Spec.CSI.VolumeHandle)
req := csi.DeleteVolumeRequest{
Version: &csiVersion,
VolumeId: volumeId,
}
ctx, cancel := context.WithTimeout(context.Background(), p.timeout)
defer cancel()

_, err := p.csiClient.DeleteVolume(ctx, &req)
return err
}

//TODO use a unique volume handle from and to Id
func (p *csiProvisioner) volumeIdToHandle(id string) string {
return id
}

func (p *csiProvisioner) volumeHandleToId(handle string) string {
return handle
}