Skip to content

Commit

Permalink
store: move the session actions into their own package (#5994)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <[email protected]>

Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Dec 20, 2022
1 parent 563471a commit b8fa225
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
33 changes: 17 additions & 16 deletions internal/engine/session/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
"github.com/tilt-dev/tilt/internal/controllers/apicmp"
"github.com/tilt-dev/tilt/internal/engine/buildcontrol"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/internal/store/sessions"
"github.com/tilt-dev/tilt/pkg/apis"
session "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/model"
)

Expand All @@ -36,7 +37,7 @@ type Controller struct {
// The last session object returned by the server.
// Note that the server may annotate and transform this
// on top of what we sent.
session *session.Session
session *v1alpha1.Session
}

var _ store.Subscriber = &Controller{}
Expand Down Expand Up @@ -86,7 +87,7 @@ func (c *Controller) initialize(ctx context.Context, st store.RStore) (bool, err
return true, nil
}

func (c *Controller) makeSession(st store.RStore) *session.Session {
func (c *Controller) makeSession(st store.RStore) *v1alpha1.Session {
state := st.RLockState()
defer st.RUnlockState()

Expand All @@ -96,14 +97,14 @@ func (c *Controller) makeSession(st store.RStore) *session.Session {
return nil
}

s := &session.Session{
s := &v1alpha1.Session{
ObjectMeta: metav1.ObjectMeta{
Name: "Tiltfile",
},
Spec: session.SessionSpec{
Spec: v1alpha1.SessionSpec{
TiltfilePath: tf.Spec.Path,
},
Status: session.SessionStatus{
Status: v1alpha1.SessionStatus{
PID: c.pid,
StartTime: apis.NewMicroTime(c.startTime),
},
Expand All @@ -113,19 +114,19 @@ func (c *Controller) makeSession(st store.RStore) *session.Session {
// the object on creation if it doesn't conform, so there's no additional validation/error-handling here
switch c.engineMode {
case store.EngineModeUp:
s.Spec.ExitCondition = session.ExitConditionManual
s.Spec.ExitCondition = v1alpha1.ExitConditionManual
case store.EngineModeCI:
s.Spec.ExitCondition = session.ExitConditionCI
s.Spec.ExitCondition = v1alpha1.ExitConditionCI
}

return s
}

func (c *Controller) makeLatestStatus(st store.RStore) *session.SessionStatus {
func (c *Controller) makeLatestStatus(st store.RStore) *v1alpha1.SessionStatus {
state := st.RLockState()
defer st.RUnlockState()

status := &session.SessionStatus{
status := &v1alpha1.SessionStatus{
PID: c.pid,
StartTime: apis.NewMicroTime(c.startTime),
}
Expand Down Expand Up @@ -154,7 +155,7 @@ func (c *Controller) makeLatestStatus(st store.RStore) *session.SessionStatus {
return status
}

func (c *Controller) handleLatestStatus(ctx context.Context, st store.RStore, newStatus *session.SessionStatus) error {
func (c *Controller) handleLatestStatus(ctx context.Context, st store.RStore, newStatus *v1alpha1.SessionStatus) error {
if apicmp.DeepEqual(c.session.Status, *newStatus) {
return nil
}
Expand All @@ -167,15 +168,15 @@ func (c *Controller) handleLatestStatus(ctx context.Context, st store.RStore, ne
}

c.session = updated
st.Dispatch(NewSessionUpdateStatusAction(updated))
st.Dispatch(sessions.NewSessionUpdateStatusAction(updated))

return nil
}

func processExitCondition(exitCondition session.ExitCondition, status *session.SessionStatus) {
if exitCondition == session.ExitConditionManual {
func processExitCondition(exitCondition v1alpha1.ExitCondition, status *v1alpha1.SessionStatus) {
if exitCondition == v1alpha1.ExitConditionManual {
return
} else if exitCondition != session.ExitConditionCI {
} else if exitCondition != v1alpha1.ExitConditionCI {
status.Done = true
status.Error = fmt.Sprintf("unsupported exit condition: %s", exitCondition)
}
Expand All @@ -193,7 +194,7 @@ func processExitCondition(exitCondition session.ExitCondition, status *session.S
}
if res.State.Waiting != nil {
allResourcesOK = false
} else if res.State.Active != nil && (!res.State.Active.Ready || res.Type == session.TargetTypeJob) {
} else if res.State.Active != nil && (!res.State.Active.Ready || res.Type == v1alpha1.TargetTypeJob) {
// jobs must run to completion
allResourcesOK = false
}
Expand Down
5 changes: 3 additions & 2 deletions internal/engine/session/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/tilt-dev/tilt/internal/k8s"
"github.com/tilt-dev/tilt/internal/k8s/testyaml"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/internal/store/sessions"
"github.com/tilt-dev/tilt/internal/store/tiltfiles"
"github.com/tilt-dev/tilt/internal/testutils/manifestbuilder"
"github.com/tilt-dev/tilt/internal/testutils/tempdir"
Expand Down Expand Up @@ -626,10 +627,10 @@ func (s *testStore) Dispatch(action store.Action) {

s.TestingStore.Dispatch(action)

a, ok := action.(SessionUpdateStatusAction)
a, ok := action.(sessions.SessionUpdateStatusAction)
if ok {
state := s.LockMutableStateForTesting()
HandleSessionUpdateStatusAction(state, a)
sessions.HandleSessionUpdateStatusAction(state, a)
s.UnlockMutableState()
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/engine/upper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
ctrltiltfile "github.com/tilt-dev/tilt/internal/controllers/core/tiltfile"
"github.com/tilt-dev/tilt/internal/engine/k8swatch"
"github.com/tilt-dev/tilt/internal/engine/local"
"github.com/tilt-dev/tilt/internal/engine/session"
"github.com/tilt-dev/tilt/internal/hud"
"github.com/tilt-dev/tilt/internal/hud/prompt"
"github.com/tilt-dev/tilt/internal/hud/server"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/tilt-dev/tilt/internal/store/kubernetesapplys"
"github.com/tilt-dev/tilt/internal/store/kubernetesdiscoverys"
"github.com/tilt-dev/tilt/internal/store/liveupdates"
"github.com/tilt-dev/tilt/internal/store/sessions"
"github.com/tilt-dev/tilt/internal/store/tiltfiles"
"github.com/tilt-dev/tilt/internal/store/uibuttons"
"github.com/tilt-dev/tilt/internal/store/uiresources"
Expand Down Expand Up @@ -160,8 +160,8 @@ func upperReducerFn(ctx context.Context, state *store.EngineState, action store.
handlePanicAction(state, action)
case store.LogAction:
handleLogAction(state, action)
case session.SessionUpdateStatusAction:
session.HandleSessionUpdateStatusAction(state, action)
case sessions.SessionUpdateStatusAction:
sessions.HandleSessionUpdateStatusAction(state, action)
case prompt.SwitchTerminalModeAction:
handleSwitchTerminalModeAction(state, action)
case server.OverrideTriggerModeAction:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package session
package sessions

import (
"errors"
Expand Down

0 comments on commit b8fa225

Please sign in to comment.