Skip to content

Commit fc437fe

Browse files
committed
move logic
1 parent 447f6b4 commit fc437fe

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

internal/controller/amaltheasession_controller.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/getsentry/sentry-go"
27+
"github.com/oklog/ulid/v2"
2728

2829
appsv1 "k8s.io/api/apps/v1"
2930
corev1 "k8s.io/api/core/v1"
@@ -201,6 +202,18 @@ func (r *AmaltheaSessionReconciler) reconcileInner(ctx context.Context, req ctrl
201202
return ctrl.Result{Requeue: true}, nil
202203
}
203204

205+
// NEW
206+
// We need to handle run ID before generating children resources
207+
runID := amaltheasession.Status.RunId
208+
if amaltheasession.Spec.Hibernated {
209+
// The session is getting hibernated, unset the run ID
210+
runID = ""
211+
} else if runID == "" {
212+
// The session just got created or is being resumed, set the new run ID
213+
runID = ulid.Make().String()
214+
}
215+
amaltheasession.Status.RunId = runID
216+
204217
children, err := NewChildResources(amaltheasession, r.Configuration)
205218
if err != nil {
206219
log.Error(

internal/controller/children.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
amaltheadevv1alpha1 "github.com/SwissDataScienceCenter/amalthea/api/v1alpha1"
1111
"github.com/SwissDataScienceCenter/amalthea/internal/controller/config"
12-
"github.com/oklog/ulid/v2"
1312
appsv1 "k8s.io/api/apps/v1"
1413
batchv1 "k8s.io/api/batch/v1"
1514
v1 "k8s.io/api/core/v1"
@@ -824,14 +823,15 @@ func (c ChildResourceUpdates) Status(
824823

825824
hibernationDate := calculateHibernationDate(log, cr.GetCreationTimestamp(), cr.Status, cr.Spec.Culling)
826825

827-
runID := cr.Status.RunId
828-
if cr.Spec.Hibernated {
829-
// The session is getting hibernated, unset the run ID
830-
runID = ""
831-
} else if runID == "" {
832-
// The session just got created or is being resumed, set the new run ID
833-
runID = ulid.Make().String()
834-
}
826+
// NEW
827+
// runID := cr.Status.RunId
828+
// if cr.Spec.Hibernated {
829+
// // The session is getting hibernated, unset the run ID
830+
// runID = ""
831+
// } else if runID == "" {
832+
// // The session just got created or is being resumed, set the new run ID
833+
// runID = ulid.Make().String()
834+
// }
835835

836836
status := amaltheadevv1alpha1.AmaltheaSessionStatus{
837837
Conditions: Conditions(state, ctx, r, cr),

0 commit comments

Comments
 (0)