Added Name alongside to Namespace to Session
This commit is contained in:
parent
729505a216
commit
e7bb4b1149
@ -21,6 +21,8 @@ type BackupSessionReconciler struct {
|
||||
func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||
r.Log = log.FromContext(ctx)
|
||||
r.Context = ctx
|
||||
r.Namespace = req.NamespacedName.Namespace
|
||||
r.Name = req.NamespacedName.Name
|
||||
|
||||
backupSession := formolv1alpha1.BackupSession{}
|
||||
err := r.Get(ctx, req.NamespacedName, &backupSession)
|
||||
@ -47,7 +49,6 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
}
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
r.Namespace = backupConf.Namespace
|
||||
|
||||
// we don't want a copy because we will modify and update it.
|
||||
var target formolv1alpha1.Target
|
||||
@ -96,7 +97,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
newSessionState = formolv1alpha1.Waiting
|
||||
switch target.BackupType {
|
||||
case formolv1alpha1.JobKind:
|
||||
if backupResult, err := r.backupJob(backupSession.Name, target); err != nil {
|
||||
if backupResult, err := r.backupJob(target); err != nil {
|
||||
r.Log.Error(err, "unable to run backup job", "target", targetName)
|
||||
newSessionState = formolv1alpha1.Failure
|
||||
} else {
|
||||
@ -106,7 +107,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
}
|
||||
case formolv1alpha1.OnlineKind:
|
||||
backupPaths := strings.Split(os.Getenv(formolv1alpha1.BACKUP_PATHS), string(os.PathListSeparator))
|
||||
if backupResult, result := r.backupPaths(backupSession.Name, backupPaths); result != nil {
|
||||
if backupResult, result := r.backupPaths(backupPaths); result != nil {
|
||||
r.Log.Error(result, "unable to backup paths", "target name", targetName, "paths", backupPaths)
|
||||
newSessionState = formolv1alpha1.Failure
|
||||
} else {
|
||||
|
||||
@ -23,13 +23,13 @@ type BackupResult struct {
|
||||
Duration float64
|
||||
}
|
||||
|
||||
func (r *BackupSessionReconciler) backupPaths(tag string, paths []string) (result BackupResult, err error) {
|
||||
func (r *BackupSessionReconciler) backupPaths(paths []string) (result BackupResult, err error) {
|
||||
if err = r.CheckRepo(); err != nil {
|
||||
r.Log.Error(err, "unable to setup repo", "repo", os.Getenv(formolv1alpha1.RESTIC_REPOSITORY))
|
||||
return
|
||||
}
|
||||
r.Log.V(0).Info("backing up paths", "paths", paths)
|
||||
cmd := exec.Command(RESTIC_EXEC, append([]string{"backup", "--json", "--tag", tag}, paths...)...)
|
||||
cmd := exec.Command(RESTIC_EXEC, append([]string{"backup", "--json", "--tag", r.Name}, paths...)...)
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
stderr, _ := cmd.StderrPipe()
|
||||
_ = cmd.Start()
|
||||
@ -55,7 +55,7 @@ func (r *BackupSessionReconciler) backupPaths(tag string, paths []string) (resul
|
||||
return
|
||||
}
|
||||
|
||||
func (r *BackupSessionReconciler) backupJob(tag string, target formolv1alpha1.Target) (result BackupResult, err error) {
|
||||
func (r *BackupSessionReconciler) backupJob(target formolv1alpha1.Target) (result BackupResult, err error) {
|
||||
paths := []string{}
|
||||
for _, container := range target.Containers {
|
||||
for _, job := range container.Job {
|
||||
@ -75,7 +75,7 @@ func (r *BackupSessionReconciler) backupJob(tag string, target formolv1alpha1.Ta
|
||||
paths = append(paths, container.SharePath)
|
||||
}
|
||||
}
|
||||
result, err = r.backupPaths(tag, paths)
|
||||
result, err = r.backupPaths(paths)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,8 @@ type RestoreSessionReconciler struct {
|
||||
func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||
r.Log = log.FromContext(ctx)
|
||||
r.Context = ctx
|
||||
r.Namespace = req.NamespacedName.Namespace
|
||||
r.Name = req.NamespacedName.Name
|
||||
|
||||
restoreSession := formolv1alpha1.RestoreSession{}
|
||||
err := r.Get(r.Context, req.NamespacedName, &restoreSession)
|
||||
@ -49,7 +51,6 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
||||
}
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
r.Namespace = backupConf.Namespace
|
||||
r.backupConf = backupConf
|
||||
|
||||
// we don't want a copy because we will modify and update it.
|
||||
|
||||
@ -27,6 +27,7 @@ type Session struct {
|
||||
Scheme *runtime.Scheme
|
||||
context.Context
|
||||
Namespace string
|
||||
Name string
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user