Skip to content

Commit

Permalink
review comment
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <[email protected]>
  • Loading branch information
pawanpraka1 committed Aug 26, 2020
1 parent e10fa83 commit 516b89d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions pkg/zfs/plugin/backup.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 the Velero contributors.
Copyright 2020 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,11 +101,11 @@ func (p *Plugin) getPrevSnap(volname, schdname string) (string, error) {
return "", nil
}

func (p *Plugin) createBackup(vol *apis.ZFSVolume, schdname string, snapname string) (string, error) {
func (p *Plugin) createBackup(vol *apis.ZFSVolume, schdname, snapname string) (string, error) {

bkpname := utils.GenerateSnapshotID(vol.Name, snapname)

p.Log.Infof("zfs: creating ZFSBackup vol = %s bkp = %s schd = %s", vol.Name, bkpname, schdname)
p.Log.Debugf("zfs: creating ZFSBackup vol = %s bkp = %s schd = %s", vol.Name, bkpname, schdname)

var err error
labels := map[string]string{}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (p *Plugin) doBackup(volumeID string, snapname string, schdname string) (st

go p.checkBackupStatus(bkpname)

p.Log.Infof("zfs: uploading Snapshot %s file %s", snapname, filename)
p.Log.Debugf("zfs: uploading Snapshot %s file %s", snapname, filename)
ok := p.cl.Upload(filename, size)
if !ok {
p.deleteBackup(bkpname)
Expand Down
10 changes: 5 additions & 5 deletions pkg/zfs/plugin/restore.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 the Velero contributors.
Copyright 2020 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ func (p *Plugin) createVolume(pvname string, bkpname string, bkpZV *apis.ZFSVolu
ns, err := velero.GetRestoreNamespace(bkpZV.Labels[VeleroNsKey], bkpname, p.Log)

if err != nil {
p.Log.Errorf("zfs: failed to get target ns pv %s bkpname %s err: %v", pvname, bkpname, err)
p.Log.Errorf("zfs: failed to get target ns for pv=%s, bkpname=%s err: %v", pvname, bkpname, err)
return nil, false, err
}

Expand All @@ -65,7 +65,7 @@ func (p *Plugin) createVolume(pvname string, bkpname string, bkpZV *apis.ZFSVolu
return vol, false, errors.Errorf("zfs: pv %s is already restored bkpname %s", pvname, bkpname)
}

p.Log.Infof("zfs: got existing volume %s for restore vol %s snap %s", vol.Name, pvname, bkpname)
p.Log.Debugf("zfs: got existing volume %s for restore vol %s snap %s", vol.Name, pvname, bkpname)
}

if vol == nil {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (p *Plugin) doRestore(snapshotID string) (string, error) {

if needRestore == false {
// volume has already been restored
p.Log.Infof("zfs: pv already restored vol %s => %s snap %s", volname, newvol, snapshotID)
p.Log.Debugf("zfs: pv already restored vol %s => %s snap %s", volname, newvol, snapshotID)
return newvol, nil
}

Expand All @@ -293,6 +293,6 @@ func (p *Plugin) doRestore(snapshotID string) (string, error) {
return "", err
}

p.Log.Infof("zfs: restore done vol %s => %s snap %s", volname, newvol, snapshotID)
p.Log.Debugf("zfs: restore done vol %s => %s snap %s", volname, newvol, snapshotID)
return newvol, nil
}
34 changes: 17 additions & 17 deletions pkg/zfs/plugin/zfs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 the Velero contributors.
Copyright 2020 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,10 +30,10 @@ import (
)

const (
// ZFSPV_NAMESPACE config key for OpenEBS namespace
ZFSPV_NAMESPACE = "namespace"
// ZFSPV_BACKUP config key for backup type full or incremental
ZFSPV_BACKUP = "backup"
// ZfsPvNamespace config key for OpenEBS namespace
ZfsPvNamespace = "namespace"
// ZfsPvBackup config key for backup type full or incremental
ZfsPvBackup = "backup"
backupStatusInterval = 5
)

Expand Down Expand Up @@ -64,21 +64,21 @@ type Plugin struct {
// configuration key-value pairs. It returns an error if the VolumeSnapshotter
// cannot be initialized from the provided config. Note that after v0.10.0, this will happen multiple times.
func (p *Plugin) Init(config map[string]string) error {
p.Log.Infof("zfs: Init called %v", config)
p.Log.Debugf("zfs: Init called %v", config)
p.config = config

p.remoteAddr, _ = utils.GetServerAddress()
if p.remoteAddr == "" {
return errors.New("zfs: error fetching Server address")
}

if ns, ok := config[ZFSPV_NAMESPACE]; ok {
if ns, ok := config[ZfsPvNamespace]; ok {
p.namespace = ns
} else {
p.namespace = "openebs" // default namespace
return errors.New("zfs: namespace not provided for ZFS-LocalPV")
}

if bkptype, ok := config[ZFSPV_BACKUP]; ok && bkptype == "incremental" {
if bkptype, ok := config[ZfsPvBackup]; ok && bkptype == "incremental" {
p.incremental = true
}

Expand Down Expand Up @@ -106,7 +106,7 @@ func (p *Plugin) Init(config map[string]string) error {

// CreateVolumeFromSnapshot creates a new volume from the specified snapshot
func (p *Plugin) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (string, error) {
p.Log.Infof("zfs: CreateVolumeFromSnapshot called snap %s", snapshotID)
p.Log.Debugf("zfs: CreateVolumeFromSnapshot called snap %s", snapshotID)

volumeID, err := p.doRestore(snapshotID)

Expand All @@ -122,28 +122,28 @@ func (p *Plugin) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ strin
// GetVolumeInfo returns the type and IOPS (if using provisioned IOPS) for
// the specified volume in the given availability zone.
func (p *Plugin) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error) {
p.Log.Infof("zfs: GetVolumeInfo called", volumeID, volumeAZ)
p.Log.Debugf("zfs: GetVolumeInfo called", volumeID, volumeAZ)
return "zfs-localpv", nil, nil
}

// IsVolumeReady Check if the volume is ready.
func (p *Plugin) IsVolumeReady(volumeID, volumeAZ string) (ready bool, err error) {
p.Log.Infof("zfs: IsVolumeReady called", volumeID, volumeAZ)
p.Log.Debugf("zfs: IsVolumeReady called", volumeID, volumeAZ)

return p.isVolumeReady(volumeID)
}

// CreateSnapshot creates a snapshot of the specified volume, and applies any provided
// set of tags to the snapshot.
func (p *Plugin) CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (string, error) {
p.Log.Infof("zfs: CreateSnapshot called", volumeID, volumeAZ, tags)
p.Log.Debugf("zfs: CreateSnapshot called", volumeID, volumeAZ, tags)

bkpname, ok := tags[VeleroBkpKey]
if !ok {
return "", errors.New("zfs: error get backup name")
}

schdname, ok := tags[VeleroSchdKey]
schdname, _ := tags[VeleroSchdKey]

snapshotID, err := p.doBackup(volumeID, bkpname, schdname)

Expand All @@ -158,7 +158,7 @@ func (p *Plugin) CreateSnapshot(volumeID, volumeAZ string, tags map[string]strin

// DeleteSnapshot deletes the specified volume snapshot.
func (p *Plugin) DeleteSnapshot(snapshotID string) error {
p.Log.Infof("zfs: DeleteSnapshot called %s", snapshotID)
p.Log.Debugf("zfs: DeleteSnapshot called %s", snapshotID)
if snapshotID == "" {
p.Log.Warning("zfs: Empty snapshotID")
return nil
Expand All @@ -169,7 +169,7 @@ func (p *Plugin) DeleteSnapshot(snapshotID string) error {

// GetVolumeID returns the specific identifier for the PersistentVolume.
func (p *Plugin) GetVolumeID(unstructuredPV runtime.Unstructured) (string, error) {
p.Log.Infof("zfs: GetVolumeID called %v", unstructuredPV)
p.Log.Debugf("zfs: GetVolumeID called %v", unstructuredPV)

pv := new(v1.PersistentVolume)
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredPV.UnstructuredContent(), pv); err != nil {
Expand All @@ -181,7 +181,7 @@ func (p *Plugin) GetVolumeID(unstructuredPV runtime.Unstructured) (string, error

// SetVolumeID sets the specific identifier for the PersistentVolume.
func (p *Plugin) SetVolumeID(unstructuredPV runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
p.Log.Infof("zfs: SetVolumeID called %v %s", unstructuredPV, volumeID)
p.Log.Debugf("zfs: SetVolumeID called %v %s", unstructuredPV, volumeID)

pv := new(v1.PersistentVolume)
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredPV.UnstructuredContent(), pv); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/zfs/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 the Velero contributors.
Copyright 2020 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 516b89d

Please sign in to comment.