engine

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2018 License: Apache-2.0 Imports: 34 Imported by: 0

README

Engine Design Doc

Engine is primarily a for loop that takes inputs from a variety of sources, updates state, and makes a decision based off of that state. The rough shape of the for loop is as follows:

state := &state{}
for {
    select {
        // sources like local filesystem, kubernetes, ui, etc
        case ev := <- fsCh:
            e.handleFsEvent(ev)
        case ev := <- k8sCh:
            e.handleK8sEvent(ev)
    }
    // decide what to do: start a pipeline, stop a pipeline
    actions := handle(state)
    // tell subscribers what we took
    updateSubscribers(actions, state.copy())
}

When state changes, and only when state changes, can we make decisions about what to do. Only after actions have been taken do we tell subscribers.

Rules

  • No blocking I/O in the for loop
  • No long operations in the for loop
  • Actions taken in handle shouldn’t directly send to channels that this for selects on.

Documentation

Index

Constants

View Source
const ManifestNameLabel = "tilt-manifest"
View Source
const TiltRunIDLabel = "tilt-runid"

Variables

View Source
var TiltRunID = uuid.New().String()
View Source
var UpperReducer = store.Reducer(func(ctx context.Context, state *store.EngineState, action store.Action) {
	var err error
	switch action := action.(type) {
	case InitAction:
		err = handleInitAction(ctx, state, action)
	case ErrorAction:
		err = action.Error
	case hud.ExitAction:
		handleExitAction(state)
	case manifestFilesChangedAction:
		handleFSEvent(ctx, state, action)
	case PodChangeAction:
		handlePodEvent(ctx, state, action.Pod)
	case ServiceChangeAction:
		handleServiceEvent(ctx, state, action)
	case PodLogAction:
		handlePodLogAction(state, action)
	case BuildCompleteAction:
		err = handleCompletedBuild(ctx, state, action)
	case hud.ShowErrorAction:
		showError(ctx, state, action.ResourceNumber)
	case BuildStartedAction:
		handleBuildStarted(ctx, state, action)
	case ManifestReloadedAction:
		handleManifestReloaded(ctx, state, action)
	case LogAction:
		handleLogAction(state, action)
	case GlobalYAMLManifestReloadedAction:
		handleGlobalYAMLManifestReloaded(ctx, state, action)
	case GlobalYAMLApplyStartedAction:
		handleGlobalYAMLApplyStarted(ctx, state, action)
	case GlobalYAMLApplyCompleteAction:
		handleGlobalYAMLApplyComplete(ctx, state, action)
	case GlobalYAMLApplyError:
		handleGlobalYAMLApplyError(ctx, state, action)
	default:
		err = fmt.Errorf("unrecognized action: %T", action)
	}

	if err != nil {
		state.PermanentError = err
	}
})

Functions

func ParseYAMLFromManifests

func ParseYAMLFromManifests(manifests ...model.Manifest) ([]k8s.K8sEntity, error)

func PopulatePortForwards

func PopulatePortForwards(m portForwardableManifest, pod store.Pod) []model.PortForward

Extract the port-forward specs from the manifest. If any of them have ContainerPort = 0, populate them with the default port in the pod spec. Quietly drop forwards that we can't populate.

func ProvideTimerMaker

func ProvideTimerMaker() timerMaker

func TiltRunLabel

func TiltRunLabel() k8s.LabelPair

Types

type BuildAndDeployer

type BuildAndDeployer interface {
	// BuildAndDeploy builds and deployed the specified manifest.
	//
	// Returns a BuildResult that expresses the output of the build.
	//
	// BuildResult can be used to construct a BuildState, which contains
	// the last successful build and the files changed since that build.
	BuildAndDeploy(ctx context.Context, manifest model.Manifest, currentState store.BuildState) (store.BuildResult, error)

	// PostProcessBuild gets any info about the build that we'll need for subsequent builds.
	// In general, we'll store this info ON the BuildAndDeployer that needs it.
	// Each implementation of PostProcessBuild is responsible for executing long-running steps async.
	PostProcessBuild(ctx context.Context, result, prevResult store.BuildResult)
}

type BuildCompleteAction

type BuildCompleteAction struct {
	Result store.BuildResult
	Error  error
}

func NewBuildCompleteAction

func NewBuildCompleteAction(result store.BuildResult, err error) BuildCompleteAction

func (BuildCompleteAction) Action

func (BuildCompleteAction) Action()

type BuildController

type BuildController struct {
	// contains filtered or unexported fields
}

func NewBuildController

func NewBuildController(b BuildAndDeployer) *BuildController

func (*BuildController) DisableForTesting added in v0.1.0

func (c *BuildController) DisableForTesting()

func (*BuildController) OnChange

func (c *BuildController) OnChange(ctx context.Context, st *store.Store)

type BuildStartedAction

type BuildStartedAction struct {
	Manifest     model.Manifest
	StartTime    time.Time
	FilesChanged []string
}

func (BuildStartedAction) Action

func (BuildStartedAction) Action()

type CompositeBuildAndDeployer

type CompositeBuildAndDeployer struct {
	// contains filtered or unexported fields
}

CompositeBuildAndDeployer tries to run each builder in order. If a builder emits an error, it uses the FallbackTester to determine whether the error is critical enough to stop the whole pipeline, or to fallback to the next builder.

func NewCompositeBuildAndDeployer

func NewCompositeBuildAndDeployer(builders BuildOrder, shouldFallBack FallbackTester) *CompositeBuildAndDeployer

func (*CompositeBuildAndDeployer) BuildAndDeploy

func (composite *CompositeBuildAndDeployer) BuildAndDeploy(ctx context.Context, manifest model.Manifest, currentState store.BuildState) (store.BuildResult, error)

func (*CompositeBuildAndDeployer) PostProcessBuild

func (composite *CompositeBuildAndDeployer) PostProcessBuild(ctx context.Context, result, prevResult store.BuildResult)

type DeployDiscovery

type DeployDiscovery struct {
	// contains filtered or unexported fields
}

Looks up containers after they've been deployed.

func NewDeployDiscovery

func NewDeployDiscovery(kCli k8s.Client, store *store.Store) *DeployDiscovery

func (*DeployDiscovery) DeployInfoForImageBlocking

func (d *DeployDiscovery) DeployInfoForImageBlocking(ctx context.Context, img reference.NamedTagged) (DeployInfo, error)

func (*DeployDiscovery) EnsureDeployInfoFetchStarted

func (d *DeployDiscovery) EnsureDeployInfoFetchStarted(ctx context.Context, img reference.NamedTagged, ns k8s.Namespace)

func (*DeployDiscovery) ForgetImage

func (d *DeployDiscovery) ForgetImage(img reference.NamedTagged) DeployInfo

Returns the deploy info that was forgotten, if any.

type DeployInfo

type DeployInfo struct {
	// contains filtered or unexported fields
}

func (DeployInfo) Empty

func (d DeployInfo) Empty() bool

type ErrorAction

type ErrorAction struct {
	Error error
}

func NewErrorAction

func NewErrorAction(err error) ErrorAction

func (ErrorAction) Action

func (ErrorAction) Action()

type FallbackTester

type FallbackTester func(error) bool

func DefaultShouldFallBack

func DefaultShouldFallBack() FallbackTester

type FsWatcherMaker

type FsWatcherMaker func() (watch.Notify, error)

func ProvideFsWatcherMaker

func ProvideFsWatcherMaker() FsWatcherMaker

type GlobalYAMLApplyCompleteAction added in v0.1.0

type GlobalYAMLApplyCompleteAction struct{}

func (GlobalYAMLApplyCompleteAction) Action added in v0.1.0

type GlobalYAMLApplyError added in v0.1.0

type GlobalYAMLApplyError struct {
	Error error
}

func (GlobalYAMLApplyError) Action added in v0.1.0

func (GlobalYAMLApplyError) Action()

type GlobalYAMLApplyStartedAction added in v0.1.0

type GlobalYAMLApplyStartedAction struct{}

func (GlobalYAMLApplyStartedAction) Action added in v0.1.0

type GlobalYAMLBuildController added in v0.1.0

type GlobalYAMLBuildController struct {
	// contains filtered or unexported fields
}

func NewGlobalYAMLBuildController added in v0.1.0

func NewGlobalYAMLBuildController(k8sClient k8s.Client) *GlobalYAMLBuildController

func (*GlobalYAMLBuildController) OnChange added in v0.1.0

func (c *GlobalYAMLBuildController) OnChange(ctx context.Context, st *store.Store)

type GlobalYAMLManifestReloadedAction added in v0.1.0

type GlobalYAMLManifestReloadedAction struct {
	GlobalYAML model.YAMLManifest
}

func (GlobalYAMLManifestReloadedAction) Action added in v0.1.0

type HudStoppedAction added in v0.1.0

type HudStoppedAction struct {
	// contains filtered or unexported fields
}

func NewHudStoppedAction added in v0.1.0

func NewHudStoppedAction(err error) HudStoppedAction

func (HudStoppedAction) Action added in v0.1.0

func (HudStoppedAction) Action()

type ImageBuildAndDeployer

type ImageBuildAndDeployer struct {
	// contains filtered or unexported fields
}

func NewImageBuildAndDeployer

func NewImageBuildAndDeployer(b build.ImageBuilder, k8sClient k8s.Client, env k8s.Env, analytics analytics.Analytics, updateMode UpdateMode) *ImageBuildAndDeployer

func (*ImageBuildAndDeployer) BuildAndDeploy

func (ibd *ImageBuildAndDeployer) BuildAndDeploy(ctx context.Context, manifest model.Manifest, state store.BuildState) (br store.BuildResult, err error)

func (*ImageBuildAndDeployer) PostProcessBuild

func (ibd *ImageBuildAndDeployer) PostProcessBuild(ctx context.Context, result, previousResult store.BuildResult)

func (*ImageBuildAndDeployer) SetInjectSynclet

func (ibd *ImageBuildAndDeployer) SetInjectSynclet(inject bool)

Turn on synclet injection. Should be called before any builds.

type ImageController added in v0.1.0

type ImageController struct {
	// contains filtered or unexported fields
}

Handles image garbage collection.

func NewImageController added in v0.1.0

func NewImageController(reaper build.ImageReaper) *ImageController

func (*ImageController) OnChange added in v0.1.0

func (c *ImageController) OnChange(ctx context.Context, store *store.Store)

type InitAction

type InitAction struct {
	WatchMounts        bool
	Manifests          []model.Manifest
	GlobalYAMLManifest model.YAMLManifest
	TiltfilePath       string
}

func (InitAction) Action

func (InitAction) Action()

type LocalContainerBuildAndDeployer

type LocalContainerBuildAndDeployer struct {
	// contains filtered or unexported fields
}

func (*LocalContainerBuildAndDeployer) BuildAndDeploy

func (cbd *LocalContainerBuildAndDeployer) BuildAndDeploy(ctx context.Context, manifest model.Manifest, state store.BuildState) (result store.BuildResult, err error)

func (*LocalContainerBuildAndDeployer) PostProcessBuild

func (cbd *LocalContainerBuildAndDeployer) PostProcessBuild(ctx context.Context, result, previousResult store.BuildResult)

type LogAction added in v0.1.0

type LogAction struct {
	Log []byte
}

func (LogAction) Action added in v0.1.0

func (LogAction) Action()

type ManifestReloadedAction

type ManifestReloadedAction struct {
	OldManifest model.Manifest
	NewManifest model.Manifest
	Error       error
}

func (ManifestReloadedAction) Action

func (ManifestReloadedAction) Action()

type PodChangeAction

type PodChangeAction struct {
	Pod *v1.Pod
}

func NewPodChangeAction

func NewPodChangeAction(pod *v1.Pod) PodChangeAction

func (PodChangeAction) Action

func (PodChangeAction) Action()

type PodLogAction

type PodLogAction struct {
	ManifestName model.ManifestName

	PodID k8s.PodID
	Log   []byte
}

func (PodLogAction) Action

func (PodLogAction) Action()

type PodLogActionWriter

type PodLogActionWriter struct {
	// contains filtered or unexported fields
}

func (PodLogActionWriter) Write

func (w PodLogActionWriter) Write(p []byte) (n int, err error)

type PodLogManager

type PodLogManager struct {
	// contains filtered or unexported fields
}

Collects logs from deployed containers.

func NewPodLogManager

func NewPodLogManager(kClient k8s.Client) *PodLogManager

func (*PodLogManager) OnChange

func (m *PodLogManager) OnChange(ctx context.Context, st *store.Store)

type PodLogWatch

type PodLogWatch struct {
	// contains filtered or unexported fields
}

type PodWatcher

type PodWatcher struct {
	// contains filtered or unexported fields
}

func NewPodWatcher

func NewPodWatcher(kCli k8s.Client) *PodWatcher

func (*PodWatcher) OnChange

func (w *PodWatcher) OnChange(ctx context.Context, st *store.Store)

type PodWatcherMaker

type PodWatcherMaker func(context.Context, *store.Store) error

type PortForwardController

type PortForwardController struct {
	// contains filtered or unexported fields
}

func NewPortForwardController

func NewPortForwardController(kClient k8s.Client) *PortForwardController

func (*PortForwardController) OnChange

func (m *PortForwardController) OnChange(ctx context.Context, st *store.Store)

type ServiceChangeAction

type ServiceChangeAction struct {
	Service *v1.Service
	URL     *url.URL
}

func NewServiceChangeAction

func NewServiceChangeAction(service *v1.Service, url *url.URL) ServiceChangeAction

func (ServiceChangeAction) Action

func (ServiceChangeAction) Action()

type ServiceWatcher

type ServiceWatcher struct {
	// contains filtered or unexported fields
}

func NewServiceWatcher

func NewServiceWatcher(kCli k8s.Client, nodeIP k8s.NodeIP) *ServiceWatcher

func (*ServiceWatcher) OnChange

func (w *ServiceWatcher) OnChange(ctx context.Context, st *store.Store)

type ServiceWatcherMaker

type ServiceWatcherMaker func(context.Context, *store.Store) error

type SyncletBuildAndDeployer

type SyncletBuildAndDeployer struct {
	// contains filtered or unexported fields
}

func (*SyncletBuildAndDeployer) BuildAndDeploy

func (sbd *SyncletBuildAndDeployer) BuildAndDeploy(ctx context.Context, manifest model.Manifest, state store.BuildState) (store.BuildResult, error)

func (*SyncletBuildAndDeployer) PostProcessBuild

func (sbd *SyncletBuildAndDeployer) PostProcessBuild(ctx context.Context, result, previousResult store.BuildResult)

type SyncletManager

type SyncletManager struct {
	// contains filtered or unexported fields
}

func NewSyncletManager

func NewSyncletManager(kCli k8s.Client) SyncletManager

func NewSyncletManagerForTests

func NewSyncletManagerForTests(kCli k8s.Client, fakeCli synclet.SyncletClient) SyncletManager

func (SyncletManager) ClientForPod

func (sm SyncletManager) ClientForPod(ctx context.Context, podID k8s.PodID, ns k8s.Namespace) (synclet.SyncletClient, error)

func (SyncletManager) ForgetPod

func (sm SyncletManager) ForgetPod(ctx context.Context, podID k8s.PodID) error

type UpdateMode

type UpdateMode string
var (
	// Auto-pick the build mode based on
	UpdateModeAuto UpdateMode = "auto"

	// Only do image builds
	UpdateModeImage UpdateMode = "image"

	// Only do image builds from scratch
	UpdateModeNaive UpdateMode = "naive"

	// Deploy a synclet to make container updates faster
	UpdateModeSynclet UpdateMode = "synclet"

	// Update containers in-place. This mode only works with DockerForDesktop and Minikube.
	// If you try to use this mode with a different K8s cluster type, we will return an error
	UpdateModeContainer UpdateMode = "container"
)

func ProvideUpdateMode

func ProvideUpdateMode(flag UpdateModeFlag, env k8s.Env) (UpdateMode, error)

type UpdateModeFlag

type UpdateModeFlag UpdateMode

A type to bind to flag values that need validation.

type Upper

type Upper struct {
	// contains filtered or unexported fields
}

TODO(nick): maybe this should be called 'BuildEngine' or something? Upper seems like a poor and undescriptive name.

func (Upper) Dispatch added in v0.1.0

func (u Upper) Dispatch(action store.Action)

func (Upper) Start added in v0.1.0

func (u Upper) Start(ctx context.Context, args []string, watchMounts bool) error

func (Upper) StartForTesting added in v0.1.0

func (u Upper) StartForTesting(ctx context.Context, manifests []model.Manifest,
	globalYAML model.YAMLManifest, watchMounts bool, tiltfilePath string) error

type WatchManager

type WatchManager struct {
	// contains filtered or unexported fields
}

func NewWatchManager

func NewWatchManager(watcherMaker FsWatcherMaker, timerMaker timerMaker) *WatchManager

func (*WatchManager) OnChange

func (w *WatchManager) OnChange(ctx context.Context, st *store.Store)

type WatchableManifest added in v0.1.0

type WatchableManifest interface {
	Dependencies() []string
	ManifestName() model.ManifestName
	ConfigMatcher() (model.PathMatcher, error)
	LocalRepos() []model.LocalGithubRepo
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL