Skip to content

Commit

Permalink
Fix stash clone pvc
Browse files Browse the repository at this point in the history
Signed-off-by: hmsayem <[email protected]>
  • Loading branch information
hmsayem committed Jan 28, 2022
1 parent cfada99 commit 8481230
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions pkg/clone_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,12 @@ func restorePVC(pvcName string, repository kmapi.ObjectReference) error {
APIVersion: core.SchemeGroupVersion.String(),
},
}
//ensurePVC(pvc.Name)

restoreSession, err := opt.newRestoreSession(fmt.Sprintf("%s-%s", pvcName, "restore"), dstNamespace)
if err != nil {
return err
}

// if driver is restic set target ref
// restoreSession.Spec.Target.Ref = opt.targetRef
klog.Infof("Creating RestoreSession: %s to the namespace: %s", restoreSession.Name, restoreSession.Namespace)
restoreSession, err = createRestoreSession(restoreSession)
if err != nil {
Expand Down
14 changes: 6 additions & 8 deletions pkg/create_restoresession.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import (
"context"
"fmt"

"stash.appscode.dev/apimachinery/apis"
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
v1beta1_util "stash.appscode.dev/apimachinery/client/clientset/versioned/typed/stash/v1beta1/util"
"stash.appscode.dev/stash/pkg/util"

vs "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
"github.com/spf13/cobra"
Expand All @@ -42,7 +40,7 @@ var (
# Create a RestoreSession
# stash create restore --namespace=demo <restore session name> [Flag]
# For Restic driver
stash create restoresession ss-restore --namespace=demo --repository=gcs-repo --target-apiversion=apps/v1 --target-kind=StatefulSet --target-name=stash-recovered --paths=/source/data --volume-mounts=source-data:/source/data
stash create restoresession ss-restore --namespace=demo --repositoryName==gcs-repo --target-apiversion=apps/v1 --target-kind=StatefulSet --target-name=stash-recovered --paths=/source/data --volume-mounts=source-data:/source/data
# For VolumeSnapshotter driver
stash create restoresession restore-pvc --namespace=demo --driver=VolumeSnapshotter --replica=3 --claim.name=restore-data-restore-demo-${POD_ORDINAL} --claim.access-modes=ReadWriteOnce --claim.storageclass=standard --claim.size=1Gi --claim.datasource=source-data-stash-demo-0-1567146010`)
)
Expand Down Expand Up @@ -138,7 +136,6 @@ func (opt restoreSessionOption) newRestoreSession(name string, namespace string)
}
restoreSession.Spec.Task = v1beta1.TaskRef{Name: opt.task}
}

err := opt.setRestoreTarget(restoreSession)
if err != nil {
return nil, err
Expand Down Expand Up @@ -173,16 +170,17 @@ func (opt restoreSessionOption) setRestoreTarget(restoreSession *v1beta1.Restore
APIGroup: pointer.StringP(vs.GroupName),
}
} else {
if opt.targetRef.Kind != "" && util.BackupModel(opt.targetRef.Kind) == apis.ModelSidecar {
if opt.volumeClaimTemplate.name != "" && opt.volumeClaimTemplate.size != "" {
restoreSession.Spec.Target = &v1beta1.RestoreTarget{
Ref: opt.targetRef,
VolumeClaimTemplates: opt.getRestoredPVCTemplates(),
}

} else {
restoreSession.Spec.Target = &v1beta1.RestoreTarget{
VolumeClaimTemplates: opt.getRestoredPVCTemplates(),
Ref: opt.targetRef,
}

}

if len(opt.volumeMounts) > 0 {
volumeMounts, err := getVolumeMounts(opt.volumeMounts)
if err != nil {
Expand Down

0 comments on commit 8481230

Please sign in to comment.