Skip to content

Commit

Permalink
store: add actions and reducers for syncing dockercompose api objects (
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks authored Mar 14, 2022
1 parent 6d137e5 commit b1ac829
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
4 changes: 4 additions & 0 deletions internal/controllers/core/dockercomposeservice/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/tilt-dev/tilt/internal/docker"
"github.com/tilt-dev/tilt/internal/dockercompose"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/internal/store/dockercomposeservices"
"github.com/tilt-dev/tilt/pkg/apis"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/logger"
Expand Down Expand Up @@ -96,9 +97,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
}
r.clearResult(nn)

r.st.Dispatch(dockercomposeservices.NewDockerComposeServiceDeleteAction(nn.Name))
return ctrl.Result{}, nil
}

r.st.Dispatch(dockercomposeservices.NewDockerComposeServiceUpsertAction(&obj))

// Get configmap's disable status
ctx = store.MustObjectLogHandler(ctx, r.st, &obj)
disableStatus, err := configmap.MaybeNewDisableStatus(ctx, r.ctrlClient, obj.Spec.DisableSource, obj.Status.DisableStatus)
Expand Down
5 changes: 5 additions & 0 deletions internal/engine/upper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/tilt-dev/tilt/internal/store/buildcontrols"
"github.com/tilt-dev/tilt/internal/store/clusters"
"github.com/tilt-dev/tilt/internal/store/configmaps"
"github.com/tilt-dev/tilt/internal/store/dockercomposeservices"
"github.com/tilt-dev/tilt/internal/store/filewatches"
"github.com/tilt-dev/tilt/internal/store/kubernetesapplys"
"github.com/tilt-dev/tilt/internal/store/kubernetesdiscoverys"
Expand Down Expand Up @@ -184,6 +185,10 @@ func upperReducerFn(ctx context.Context, state *store.EngineState, action store.
filewatches.HandleFileWatchUpsertAction(state, action)
case filewatches.FileWatchDeleteAction:
filewatches.HandleFileWatchDeleteAction(state, action)
case dockercomposeservices.DockerComposeServiceUpsertAction:
dockercomposeservices.HandleDockerComposeServiceUpsertAction(state, action)
case dockercomposeservices.DockerComposeServiceDeleteAction:
dockercomposeservices.HandleDockerComposeServiceDeleteAction(state, action)
case kubernetesapplys.KubernetesApplyUpsertAction:
kubernetesapplys.HandleKubernetesApplyUpsertAction(state, action)
case kubernetesapplys.KubernetesApplyDeleteAction:
Expand Down
23 changes: 23 additions & 0 deletions internal/store/dockercomposeservices/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dockercomposeservices

import "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"

type DockerComposeServiceUpsertAction struct {
DockerComposeService *v1alpha1.DockerComposeService
}

func NewDockerComposeServiceUpsertAction(obj *v1alpha1.DockerComposeService) DockerComposeServiceUpsertAction {
return DockerComposeServiceUpsertAction{DockerComposeService: obj}
}

func (DockerComposeServiceUpsertAction) Action() {}

type DockerComposeServiceDeleteAction struct {
Name string
}

func NewDockerComposeServiceDeleteAction(n string) DockerComposeServiceDeleteAction {
return DockerComposeServiceDeleteAction{Name: n}
}

func (DockerComposeServiceDeleteAction) Action() {}
14 changes: 14 additions & 0 deletions internal/store/dockercomposeservices/reducers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dockercomposeservices

import (
"github.com/tilt-dev/tilt/internal/store"
)

func HandleDockerComposeServiceUpsertAction(state *store.EngineState, action DockerComposeServiceUpsertAction) {
n := action.DockerComposeService.Name
state.DockerComposeServices[n] = action.DockerComposeService
}

func HandleDockerComposeServiceDeleteAction(state *store.EngineState, action DockerComposeServiceDeleteAction) {
delete(state.DockerComposeServices, action.Name)
}
22 changes: 12 additions & 10 deletions internal/store/engine_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,17 @@ type EngineState struct {

// API-server-based data models. Stored in EngineState
// to assist in migration.
Cmds map[string]*Cmd `json:"-"`
Tiltfiles map[string]*v1alpha1.Tiltfile `json:"-"`
FileWatches map[string]*v1alpha1.FileWatch `json:"-"`
KubernetesApplys map[string]*v1alpha1.KubernetesApply `json:"-"`
KubernetesDiscoverys map[string]*v1alpha1.KubernetesDiscovery `json:"-"`
UIResources map[string]*v1alpha1.UIResource `json:"-"`
ConfigMaps map[string]*v1alpha1.ConfigMap `json:"-"`
LiveUpdates map[string]*v1alpha1.LiveUpdate `json:"-"`
Clusters map[string]*v1alpha1.Cluster `json:"-"`
UIButtons map[string]*v1alpha1.UIButton `json:"-"`
Cmds map[string]*Cmd `json:"-"`
Tiltfiles map[string]*v1alpha1.Tiltfile `json:"-"`
FileWatches map[string]*v1alpha1.FileWatch `json:"-"`
KubernetesApplys map[string]*v1alpha1.KubernetesApply `json:"-"`
KubernetesDiscoverys map[string]*v1alpha1.KubernetesDiscovery `json:"-"`
UIResources map[string]*v1alpha1.UIResource `json:"-"`
ConfigMaps map[string]*v1alpha1.ConfigMap `json:"-"`
LiveUpdates map[string]*v1alpha1.LiveUpdate `json:"-"`
Clusters map[string]*v1alpha1.Cluster `json:"-"`
UIButtons map[string]*v1alpha1.UIButton `json:"-"`
DockerComposeServices map[string]*v1alpha1.DockerComposeService `json:"-"`
}

type CloudStatus struct {
Expand Down Expand Up @@ -540,6 +541,7 @@ func NewState() *EngineState {
ret.Tiltfiles = make(map[string]*v1alpha1.Tiltfile)
ret.FileWatches = make(map[string]*v1alpha1.FileWatch)
ret.KubernetesApplys = make(map[string]*v1alpha1.KubernetesApply)
ret.DockerComposeServices = make(map[string]*v1alpha1.DockerComposeService)
ret.KubernetesDiscoverys = make(map[string]*v1alpha1.KubernetesDiscovery)
ret.KubernetesResources = make(map[string]*k8sconv.KubernetesResource)
ret.UIResources = make(map[string]*v1alpha1.UIResource)
Expand Down

0 comments on commit b1ac829

Please sign in to comment.