Skip to content

Commit

Permalink
fix(restore): adding support to restore in an encrypted pool for ZFS-…
Browse files Browse the repository at this point in the history
…LocalPV

Encrypted pool does not allow the volume to be pre created for the
restore purpose. Here changing the design to do the restore first
and then create the ZFSVolume object which will bind the volume
already created while doing restore.

Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Feb 17, 2021
1 parent 21c3638 commit 67b2a45
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/147-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adding support to restore in an encrypted pool for ZFS-LocalPV
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
)

replace (
github.com/openebs/zfs-localpv => github.com/pawanpraka1/zfs-localpv v0.0.0-20210216132356-3da301606743
k8s.io/api => k8s.io/api v0.15.12
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.15.12
k8s.io/apimachinery => k8s.io/apimachinery v0.15.13-beta.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,14 @@ github.com/opencontainers/runtime-spec v1.0.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/
github.com/opencontainers/selinux v0.0.0-20170621221121-4a2974bf1ee9/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs=
github.com/openebs/api v1.11.1-0.20200629052954-e52e2bcd8339 h1:T6IuGc8zikB4XG+s8QTyTruJ35s1fm/P41z1AGj2rkI=
github.com/openebs/api v1.11.1-0.20200629052954-e52e2bcd8339/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
github.com/openebs/lib-csi v0.0.0-20201218144414-a64be5d4731e h1:40mLG8RrhwHYSS3InWsWiYVcASRgGbLWrwJkP7TS0rA=
github.com/openebs/lib-csi v0.0.0-20201218144414-a64be5d4731e/go.mod h1:RqhCQqpcbFcAeNg54v9IOqLbY0/7S00WUa24ozC7cjI=
github.com/openebs/maya v0.0.0-20200411140727-1c81f9e017b0 h1:9o6+N3YkssQvUlmJnqNULSxsGFO/rb1we8MtYKr5ze4=
github.com/openebs/maya v0.0.0-20200411140727-1c81f9e017b0/go.mod h1:QQY9cOHKQwZ73qbv6O//UYUBLNV2S0MRDIfG7t5KOCk=
github.com/openebs/zfs-localpv v1.0.0 h1:aBXyYEFN+5NTGiqT6xnqLp1N34U8AUbh9vlhSA8BQnI=
github.com/openebs/zfs-localpv v1.0.0/go.mod h1:EvN06mQH8s6oGq4ybAs1DLqy0fVS3CDh7xmvPLBQtpE=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/pawanpraka1/zfs-localpv v0.0.0-20210216132356-3da301606743 h1:sOaikRC0siAReC7RLBNGk0MkLWJTqvFOabEbNWSbNnc=
github.com/pawanpraka1/zfs-localpv v0.0.0-20210216132356-3da301606743/go.mod h1:/gL8B1DN2eu1uBNK4cbypr8GEAnMmlf/rC7tH+yxREM=
github.com/pborman/uuid v0.0.0-20170612153648-e790cca94e6c/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
31 changes: 21 additions & 10 deletions pkg/zfs/plugin/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
restoreStatusInterval = 5
)

func (p *Plugin) createVolume(pvname string, bkpname string, bkpZV *apis.ZFSVolume) (*apis.ZFSVolume, error) {
func (p *Plugin) buildZFSVolume(pvname string, bkpname string, bkpZV *apis.ZFSVolume) (*apis.ZFSVolume, error) {
// get the target namespace
ns, err := velero.GetRestoreNamespace(bkpZV.Labels[VeleroNsKey], bkpname, p.Log)

Expand Down Expand Up @@ -97,22 +97,27 @@ func (p *Plugin) createVolume(pvname string, bkpname string, bkpZV *apis.ZFSVolu
rZV.Labels = map[string]string{VeleroVolKey: pvname, VeleroNsKey: ns}
rZV.Annotations = map[string]string{VeleroBkpKey: bkpname}

vol, err := volbuilder.NewKubeclient().WithNamespace(p.namespace).Create(rZV)
return rZV, nil
}

func (p *Plugin) createZFSVolume(rZV *apis.ZFSVolume) error {

_, err := volbuilder.NewKubeclient().WithNamespace(p.namespace).Create(rZV)
if err != nil {
p.Log.Errorf("zfs: create ZFSVolume failed vol %v err: %v", rZV, err)
return nil, err
return err
}

err = p.checkVolCreation(rZV.Name)
if err != nil {
p.Log.Errorf("zfs: checkVolCreation failed %s err: %v", rZV.Name, err)
return nil, err
return err
}

return vol, nil
return nil
}

func (p *Plugin) restoreZFSVolume(pvname, schdname, bkpname string) (*apis.ZFSVolume, error) {
func (p *Plugin) getZFSVolume(pvname, schdname, bkpname string) (*apis.ZFSVolume, error) {
bkpZV := &apis.ZFSVolume{}

filename := p.cl.GenerateRemoteFileWithSchd(pvname, schdname, bkpname)
Expand All @@ -126,7 +131,7 @@ func (p *Plugin) restoreZFSVolume(pvname, schdname, bkpname string) (*apis.ZFSVo
return nil, errors.Errorf("zfs: failed to decode zfsvolume file=%s", filename+".zfsvol")
}

return p.createVolume(pvname, bkpname, bkpZV)
return p.buildZFSVolume(pvname, bkpname, bkpZV)
}

func (p *Plugin) destroyZFSVolume(volname string) error {
Expand Down Expand Up @@ -216,6 +221,7 @@ func (p *Plugin) startRestore(zv *apis.ZFSVolume, bkpname string, port int) (str
WithNode(node).
WithStatus(apis.RSTZFSStatusInit).
WithRemote(serverAddr).
WithVolSpec(zv.Spec).
Build()

if err != nil {
Expand Down Expand Up @@ -343,7 +349,7 @@ func (p *Plugin) doRestore(snapshotID string, port int) (string, error) {

p.Log.Debugf("zfs: backup list for restore %v", bkpList)

zv, err := p.restoreZFSVolume(pvname, schdname, bkpname)
zv, err := p.getZFSVolume(pvname, schdname, bkpname)
if err != nil {
p.Log.Errorf("zfs: restore ZFSVolume failed vol %s bkp %s err %v", pvname, bkpname, err)
return "", err
Expand All @@ -354,12 +360,17 @@ func (p *Plugin) doRestore(snapshotID string, port int) (string, error) {
err = p.dataRestore(zv, pvname, schdname, bkp, port)

if err != nil {
// delete the volume
p.destroyZFSVolume(zv.Name)
p.Log.Errorf("zfs: error doRestore returning snap %s err %v", snapshotID, err)
return "", err
}
}

// restore done, create the ZFSVolume
err = p.createZFSVolume(zv)
if err != nil {
p.Log.Errorf("zfs: can not create ZFS Volume, snap %s err %v", snapshotID, err)
return "", err
}

return zv.Name, nil
}

0 comments on commit 67b2a45

Please sign in to comment.