Restore session with post restore steps works
This commit is contained in:
parent
df00c8f841
commit
2ba6e19f8d
3
Makefile
3
Makefile
@ -5,6 +5,9 @@ IMG ?= desmo999r/formolcli:latest
|
||||
formolcli: fmt vet
|
||||
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -o bin/formolcli main.go
|
||||
|
||||
test: fmt vet
|
||||
go test ./... -coverprofile cover.out
|
||||
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||
backupConf := &formolv1alpha1.BackupConfiguration{}
|
||||
if err := r.Get(ctx, client.ObjectKey{
|
||||
Namespace: backupSession.Namespace,
|
||||
Name: backupSession.Spec.Ref,
|
||||
Name: backupSession.Spec.Ref.Name,
|
||||
}, backupConf); err != nil {
|
||||
log.Error(err, "unable to get backupConfiguration")
|
||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
@ -65,7 +65,7 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||
log.V(0).Info("Start to run the backup initializing steps if any")
|
||||
result := formolv1alpha1.Running
|
||||
for _, step := range target.Steps {
|
||||
if step.Finalize != nil && *step.Finalize == false {
|
||||
if step.Finalize != nil && *step.Finalize == true {
|
||||
continue
|
||||
}
|
||||
function := &formolv1alpha1.Function{}
|
||||
@ -111,7 +111,7 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||
log.V(0).Info("Start to run the backup finalizing steps if any")
|
||||
result := formolv1alpha1.Success
|
||||
for _, step := range target.Steps {
|
||||
if step.Finalize != nil && *step.Finalize == false {
|
||||
if step.Finalize != nil && *step.Finalize == true {
|
||||
function := &formolv1alpha1.Function{}
|
||||
if err := r.Get(ctx, client.ObjectKey{
|
||||
Name: step.Name,
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
formolcliutils "github.com/desmo999r/formolcli/pkg/utils"
|
||||
"github.com/go-logr/logr"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"os"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
@ -34,15 +35,23 @@ func (r *RestoreSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
||||
backupSession := &formolv1alpha1.BackupSession{}
|
||||
if err := r.Get(ctx, client.ObjectKey{
|
||||
Namespace: restoreSession.Namespace,
|
||||
Name: restoreSession.Spec.Ref,
|
||||
Name: restoreSession.Spec.BackupSessionRef.Ref.Name,
|
||||
}, backupSession); err != nil {
|
||||
log.Error(err, "unable to get backupsession")
|
||||
return ctrl.Result{}, err
|
||||
if errors.IsNotFound(err) {
|
||||
backupSession = &formolv1alpha1.BackupSession{
|
||||
Spec: restoreSession.Spec.BackupSessionRef.Spec,
|
||||
Status: restoreSession.Spec.BackupSessionRef.Status,
|
||||
}
|
||||
log.V(1).Info("generated backupsession", "backupsession", backupSession)
|
||||
} else {
|
||||
log.Error(err, "unable to get backupsession", "restoresession", restoreSession.Spec)
|
||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
}
|
||||
}
|
||||
backupConf := &formolv1alpha1.BackupConfiguration{}
|
||||
if err := r.Get(ctx, client.ObjectKey{
|
||||
Namespace: backupSession.Namespace,
|
||||
Name: backupSession.Spec.Ref,
|
||||
Namespace: backupSession.Spec.Ref.Namespace,
|
||||
Name: backupSession.Spec.Ref.Name,
|
||||
}, backupConf); err != nil {
|
||||
log.Error(err, "unable to get backupConfiguration")
|
||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
@ -54,7 +63,7 @@ func (r *RestoreSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
||||
case formolv1alpha1.SidecarKind:
|
||||
if currentTarget.Name == deploymentName {
|
||||
switch currentTargetStatus.SessionState {
|
||||
case formolv1alpha1.Running:
|
||||
case formolv1alpha1.Finalize:
|
||||
log.V(0).Info("It's for us!")
|
||||
podName := os.Getenv(formolv1alpha1.POD_NAME)
|
||||
podNamespace := os.Getenv(formolv1alpha1.POD_NAMESPACE)
|
||||
|
||||
@ -29,7 +29,7 @@ func RestoreVolume(snapshotId string) error {
|
||||
if err := session.RestoreSessionUpdateTargetStatus(formolv1alpha1.Init); err != nil {
|
||||
return err
|
||||
}
|
||||
state := formolv1alpha1.Finalize
|
||||
state := formolv1alpha1.Waiting
|
||||
output, err := restic.RestorePaths(snapshotId)
|
||||
if err != nil {
|
||||
log.Error(err, "unable to restore volume", "output", string(output))
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
formolv1alpha1 "github.com/desmo999r/formol/api/v1alpha1"
|
||||
"github.com/go-logr/logr"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
@ -127,7 +128,10 @@ func CreateBackupSession(name string, namespace string) {
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: formolv1alpha1.BackupSessionSpec{
|
||||
Ref: name,
|
||||
Ref: corev1.ObjectReference{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
},
|
||||
},
|
||||
}
|
||||
log.V(1).Info("create backupsession", "backupSession", backupSession)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user