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

fix(csi, local restore): add support for local restore of cStor CSI volume #108

Merged
merged 5 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion pkg/cstor/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ func (p *Plugin) sendRestoreRequest(vol *Volume) (*v1alpha1.CStorRestore, error)
// if apiserver is having version <=1.8 then it will return empty response
ok, err := isEmptyRestResponse(data)
if !ok && err == nil {
// TODO: for CSI base volume response type may be different
err = p.updateVolCASInfo(data, vol.volname)
if err != nil {
err = errors.Wrapf(err, "Error parsing restore API response")
Expand Down
20 changes: 12 additions & 8 deletions pkg/cstor/cstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,20 @@ func (p *Plugin) SetVolumeID(unstructuredPV runtime.Unstructured, volumeID strin
vol := p.volumes[volumeID]

if p.local {
fsType := pv.Spec.PersistentVolumeSource.ISCSI.FSType

pv.Spec.PersistentVolumeSource = v1.PersistentVolumeSource{
ISCSI: &vol.iscsi,
if !vol.isCSIVolume {
fsType := pv.Spec.PersistentVolumeSource.ISCSI.FSType
pv.Spec.PersistentVolumeSource = v1.PersistentVolumeSource{
ISCSI: &vol.iscsi,
}
// Set Old PV fsType
pv.Spec.PersistentVolumeSource.ISCSI.FSType = fsType
} else {
fsType := pv.Spec.PersistentVolumeSource.CSI.FSType
pv.Spec.PersistentVolumeSource.CSI.VolumeHandle = vol.volname
// Set Old PV fsType
pv.Spec.PersistentVolumeSource.CSI.FSType = fsType
mittachaitu marked this conversation as resolved.
Show resolved Hide resolved
}

// Set Old PV fsType
pv.Spec.PersistentVolumeSource.ISCSI.FSType = fsType
}

pv.Name = vol.volname

res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(pv)
Expand Down
32 changes: 21 additions & 11 deletions pkg/cstor/pv_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,33 @@ const (

func (p *Plugin) updateVolCASInfo(data []byte, volumeID string) error {
var cas v1alpha1.CASVolume

err := json.Unmarshal(data, &cas)
if err != nil {
return err
}
var iscsiPVSource v1.ISCSIPersistentVolumeSource

vol := p.volumes[volumeID]
if vol == nil {
return errors.Errorf("Volume{%s} not found in volume list", volumeID)
}
vol.iscsi = v1.ISCSIPersistentVolumeSource{
TargetPortal: cas.Spec.TargetPortal,
IQN: cas.Spec.Iqn,
Lun: cas.Spec.Lun,
FSType: cas.Spec.FSType,
ReadOnly: false,

if !vol.isCSIVolume {
err := json.Unmarshal(data, &cas)
if err != nil {
return err
}

vol.iscsi = v1.ISCSIPersistentVolumeSource{
TargetPortal: cas.Spec.TargetPortal,
IQN: cas.Spec.Iqn,
Lun: cas.Spec.Lun,
FSType: cas.Spec.FSType,
ReadOnly: false,
}
return nil
}
err := json.Unmarshal(data, &iscsiPVSource)
mittachaitu marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
vol.iscsi = iscsiPVSource
return nil
}

Expand Down