Skip to content

Commit

Permalink
Delete the sleep-data configmap after the wake happens
Browse files Browse the repository at this point in the history
  • Loading branch information
azlyth committed Jun 3, 2024
1 parent 9ff0439 commit 80e3a9d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions operator/internal/controller/sleepschedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,6 @@ func (r *SleepScheduleReconciler) Reconcile(ctx context.Context, req ctrl.Reques
shouldSleep = now.After(sleepDatetime) && now.Before(wakeDatetime)
}

// If the app should be awake, clear the proxy data
if !shouldSleep {
configMap := &corev1.ConfigMap{}
err = r.Get(ctx, client.ObjectKey{Namespace: sleepSchedule.Namespace, Name: fmt.Sprintf("%s-sleep-data", objectName)}, configMap)
if err == nil {
err = r.Delete(ctx, configMap)
if err != nil {
log.Error(err, "failed to delete sleep-data configmap")
return ctrl.Result{}, err
}
}
}

// fmt.Println("Checking if the app should be awake or asleep")
// fmt.Println("now:", now)
// fmt.Println("wakeDatetime:", wakeDatetime)
Expand Down Expand Up @@ -194,6 +181,20 @@ func (r *SleepScheduleReconciler) Reconcile(ctx context.Context, req ctrl.Reques
r.wake(ctx, sleepSchedule)
}

// If the app should be awake, clear the sleep data
// NOTE: we have to do this after wake because sleep data is used to when waking
if !shouldSleep {
configMap := &corev1.ConfigMap{}
err = r.Get(ctx, client.ObjectKey{Namespace: sleepSchedule.Namespace, Name: fmt.Sprintf("%s-sleep-data", objectName)}, configMap)
if err == nil {
err = r.Delete(ctx, configMap)
if err != nil {
log.Error(err, "failed to delete sleep-data configmap")
return ctrl.Result{}, err
}
}
}

// Requeue to check again in 10 seconds
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}
Expand Down

0 comments on commit 80e3a9d

Please sign in to comment.