Fixed problems with the restoresession state machine
This commit is contained in:
parent
1e086c48c1
commit
92a397fe0f
@ -35,8 +35,9 @@ import (
|
|||||||
formolutils "github.com/desmo999r/formol/pkg/utils"
|
formolutils "github.com/desmo999r/formol/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
const (
|
||||||
RESTORESESSION = "restoresession"
|
RESTORESESSION string = "restoresession"
|
||||||
|
UPDATESTATUS string = "updatestatus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RestoreSessionReconciler reconciles a RestoreSession object
|
// RestoreSessionReconciler reconciles a RestoreSession object
|
||||||
@ -175,21 +176,27 @@ func (r *RestoreSessionReconciler) DeleteRestoreInitContainer(target formolv1alp
|
|||||||
func (r *RestoreSessionReconciler) CreateRestoreInitContainer(target formolv1alpha1.Target) error {
|
func (r *RestoreSessionReconciler) CreateRestoreInitContainer(target formolv1alpha1.Target) error {
|
||||||
log := r.Log.WithValues("createrestoreinitcontainer", target.Name)
|
log := r.Log.WithValues("createrestoreinitcontainer", target.Name)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var snapshotId string
|
|
||||||
for _, targetStatus := range r.BackupSession.Status.Targets {
|
|
||||||
if targetStatus.Name == target.Name && targetStatus.Kind == target.Kind {
|
|
||||||
snapshotId = targetStatus.SnapshotId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deployment := &appsv1.Deployment{}
|
deployment := &appsv1.Deployment{}
|
||||||
if err := r.Get(context.Background(), client.ObjectKey{
|
if err := r.Get(context.Background(), client.ObjectKey{
|
||||||
Namespace: r.BackupConf.Namespace,
|
Namespace: r.RestoreSession.Namespace,
|
||||||
Name: target.Name,
|
Name: target.Name,
|
||||||
}, deployment); err != nil {
|
}, deployment); err != nil {
|
||||||
log.Error(err, "unable to get deployment")
|
log.Error(err, "unable to get deployment")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.V(1).Info("got deployment", "namespace", deployment.Namespace, "name", deployment.Name)
|
log.V(1).Info("got deployment", "namespace", deployment.Namespace, "name", deployment.Name)
|
||||||
|
for _, initContainer := range deployment.Spec.Template.Spec.InitContainers {
|
||||||
|
if initContainer.Name == RESTORESESSION {
|
||||||
|
log.V(0).Info("there is already a restoresession initcontainer", "deployment", deployment.Spec.Template.Spec.InitContainers)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var snapshotId string
|
||||||
|
for _, targetStatus := range r.BackupSession.Status.Targets {
|
||||||
|
if targetStatus.Name == target.Name && targetStatus.Kind == target.Kind {
|
||||||
|
snapshotId = targetStatus.SnapshotId
|
||||||
|
}
|
||||||
|
}
|
||||||
restoreSessionEnv := []corev1.EnvVar{
|
restoreSessionEnv := []corev1.EnvVar{
|
||||||
corev1.EnvVar{
|
corev1.EnvVar{
|
||||||
Name: formolv1alpha1.TARGET_NAME,
|
Name: formolv1alpha1.TARGET_NAME,
|
||||||
@ -283,6 +290,10 @@ func (r *RestoreSessionReconciler) StatusUpdate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.V(0).Info("New restore. Start the first task", "task", targetStatus.Name)
|
log.V(0).Info("New restore. Start the first task", "task", targetStatus.Name)
|
||||||
|
if err := r.Status().Update(ctx, r.RestoreSession); err != nil {
|
||||||
|
log.Error(err, "unable to update restoresession")
|
||||||
|
return err
|
||||||
|
}
|
||||||
case formolv1alpha1.Running:
|
case formolv1alpha1.Running:
|
||||||
currentTargetStatus := r.RestoreSession.Status.Targets[len(r.RestoreSession.Status.Targets)-1]
|
currentTargetStatus := r.RestoreSession.Status.Targets[len(r.RestoreSession.Status.Targets)-1]
|
||||||
switch currentTargetStatus.SessionState {
|
switch currentTargetStatus.SessionState {
|
||||||
@ -311,6 +322,10 @@ func (r *RestoreSessionReconciler) StatusUpdate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := r.Status().Update(ctx, r.RestoreSession); err != nil {
|
||||||
|
log.Error(err, "unable to update restoresession")
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -320,7 +335,7 @@ func (r *RestoreSessionReconciler) StatusUpdate() error {
|
|||||||
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=restoresessions/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=restoresessions/status,verbs=get;update;patch
|
||||||
|
|
||||||
func (r *RestoreSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
func (r *RestoreSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
log := r.Log.WithValues("restoresession", req.NamespacedName)
|
log := r.Log.WithValues("restoresession", req.NamespacedName)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user