engine

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2019 License: Apache-2.0 Imports: 39 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 ConfigsManifestName = "_ConfigsManifest"

TODO(maia): throw an error if you try to name a manifest this in your Tiltfile?

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, action)
	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 BuildLogAction:
		handleBuildLogAction(state, action)
	case BuildCompleteAction:
		err = handleCompletedBuild(ctx, state, action)
	case BuildStartedAction:
		handleBuildStarted(ctx, state, action)
	case LogAction:
		handleLogAction(state, action)
	case GlobalYAMLApplyStartedAction:
		handleGlobalYAMLApplyStarted(ctx, state, action)
	case GlobalYAMLApplyCompleteAction:
		handleGlobalYAMLApplyComplete(ctx, state, action)
	case ConfigsReloadStartedAction:
		handleConfigsReloadStarted(ctx, state, action)
	case ConfigsReloadedAction:
		handleConfigsReloaded(ctx, state, action)
	case DockerComposeEventAction:
		handleDockerComposeEvent(ctx, state, action)
	case DockerComposeLogAction:
		handleDockerComposeLogAction(state, action)
	case view.AppendToTriggerQueueAction:
		appendToTriggerQueue(state, action.Name)
	case hud.StartProfilingAction:
		handleStartProfilingAction(state)
	case hud.StopProfilingAction:
		handleStopProfilingAction(state)
	default:
		err = fmt.Errorf("unrecognized action: %T", action)
	}

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

Functions

func NewLogActionLogger added in v0.4.1

func NewLogActionLogger(ctx context.Context, dispatch func(action store.Action)) logger.Logger

func ParseYAMLFromManifests

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

func PopulatePortForwards

func PopulatePortForwards(m model.Manifest, 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)
}

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.RStore)

type BuildLogAction added in v0.2.0

type BuildLogAction struct {
	ManifestName model.ManifestName
	Log          []byte
}

func (BuildLogAction) Action added in v0.2.0

func (BuildLogAction) Action()

type BuildLogActionWriter added in v0.2.0

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

func (BuildLogActionWriter) Write added in v0.2.0

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

type BuildStartedAction

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

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) *CompositeBuildAndDeployer

func (*CompositeBuildAndDeployer) BuildAndDeploy

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

type ConfigsController added in v0.2.0

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

func NewConfigsController added in v0.2.0

func NewConfigsController() *ConfigsController

func (*ConfigsController) DisableForTesting added in v0.2.0

func (cc *ConfigsController) DisableForTesting(disabled bool)

func (*ConfigsController) OnChange added in v0.2.0

func (cc *ConfigsController) OnChange(ctx context.Context, st store.RStore)

type ConfigsReloadStartedAction added in v0.2.0

type ConfigsReloadStartedAction struct {
	FilesChanged map[string]bool
}

func (ConfigsReloadStartedAction) Action added in v0.2.0

func (ConfigsReloadStartedAction) Action()

type ConfigsReloadedAction added in v0.2.0

type ConfigsReloadedAction struct {
	Manifests   []model.Manifest
	GlobalYAML  model.YAMLManifest
	ConfigFiles []string

	StartTime  time.Time
	FinishTime time.Time
	Err        error
}

func (ConfigsReloadedAction) Action added in v0.2.0

func (ConfigsReloadedAction) Action()

type DockerComposeBuildAndDeployer added in v0.4.1

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

func NewDockerComposeBuildAndDeployer added in v0.4.1

func NewDockerComposeBuildAndDeployer(dcc dockercompose.DockerComposeClient) *DockerComposeBuildAndDeployer

func (*DockerComposeBuildAndDeployer) BuildAndDeploy added in v0.4.1

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

type DockerComposeEventAction added in v0.4.1

type DockerComposeEventAction struct {
	Event dockercompose.Event
}

func (DockerComposeEventAction) Action added in v0.4.1

func (DockerComposeEventAction) Action()

type DockerComposeEventWatcher added in v0.4.1

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

func NewDockerComposeEventWatcher added in v0.4.1

func NewDockerComposeEventWatcher(dcc dockercompose.DockerComposeClient) *DockerComposeEventWatcher

func (*DockerComposeEventWatcher) OnChange added in v0.4.1

func (w *DockerComposeEventWatcher) OnChange(ctx context.Context, st store.RStore)

type DockerComposeGlobalLogWriter added in v0.4.1

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

func (DockerComposeGlobalLogWriter) Write added in v0.4.1

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

type DockerComposeLogAction added in v0.4.1

type DockerComposeLogAction struct {
	ManifestName model.ManifestName
	Log          []byte
}

func (DockerComposeLogAction) Action added in v0.4.1

func (DockerComposeLogAction) Action()

type DockerComposeLogActionWriter added in v0.4.1

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

func (DockerComposeLogActionWriter) Write added in v0.4.1

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

type DockerComposeLogManager added in v0.4.1

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

Collects logs from running docker-compose services.

func NewDockerComposeLogManager added in v0.4.1

func NewDockerComposeLogManager(dcc dockercompose.DockerComposeClient) *DockerComposeLogManager

func (*DockerComposeLogManager) OnChange added in v0.4.1

func (m *DockerComposeLogManager) OnChange(ctx context.Context, st store.RStore)

type DontFallBackError added in v0.2.0

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

Something is wrong enough that we shouldn't bother falling back to other BaD's -- they won't work.

func DontFallBackErrorf added in v0.2.0

func DontFallBackErrorf(msg string, a ...interface{}) DontFallBackError

func WrapDontFallBackError added in v0.2.0

func WrapDontFallBackError(err error) DontFallBackError

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

type FsWatcherMaker

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

func ProvideFsWatcherMaker

func ProvideFsWatcherMaker() FsWatcherMaker

type GlobalYAMLApplyCompleteAction added in v0.1.0

type GlobalYAMLApplyCompleteAction struct {
	Error error
}

func (GlobalYAMLApplyCompleteAction) Action added in v0.1.0

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.RStore)

type HardCancelReader added in v0.2.0

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

A reader that will stop returning data after its context has been canceled.

If any data is read from the underlying stream after the cancel happens, throw the data out.

func NewHardCancelReader added in v0.2.0

func NewHardCancelReader(ctx context.Context, reader io.Reader) HardCancelReader

func (HardCancelReader) Read added in v0.2.0

func (r HardCancelReader) Read(b []byte) (int, error)

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,
	cacheBuilder build.CacheBuilder,
	k8sClient k8s.Client,
	env k8s.Env,
	analytics analytics.Analytics,
	updateMode UpdateMode,
	c build.Clock) *ImageBuildAndDeployer

func (*ImageBuildAndDeployer) BuildAndDeploy

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

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, st store.RStore)

type InitAction

type InitAction struct {
	WatchMounts        bool
	Manifests          []model.Manifest
	GlobalYAMLManifest model.YAMLManifest
	TiltfilePath       string
	ConfigFiles        []string
	InitManifests      []model.ManifestName
	TriggerMode        model.TriggerMode

	StartTime  time.Time
	FinishTime time.Time
	Err        error
}

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)

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.RStore)

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.RStore)

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.RStore)

type ProfilerManager added in v0.4.2

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

func NewProfilerManager added in v0.4.2

func NewProfilerManager() *ProfilerManager

func (*ProfilerManager) OnChange added in v0.4.2

func (p *ProfilerManager) OnChange(ctx context.Context, st store.RStore)

func (*ProfilerManager) Start added in v0.4.2

func (p *ProfilerManager) Start(ctx context.Context, filename string) error

func (*ProfilerManager) Stop added in v0.4.2

func (p *ProfilerManager) Stop(ctx context.Context) error

type RedirectToNextBuilder added in v0.2.0

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

Nothing is on fire, this is an expected case like a container builder being passed a build with no attached container. Don't need to show this to a user.

func RedirectToNextBuilderf added in v0.2.0

func RedirectToNextBuilderf(msg string, a ...interface{}) RedirectToNextBuilder

func WrapRedirectToNextBuilder added in v0.2.0

func WrapRedirectToNextBuilder(err error) RedirectToNextBuilder

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.RStore)

type ServiceWatcherMaker

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

type SyncletBuildAndDeployer

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

func NewSyncletBuildAndDeployer

func NewSyncletBuildAndDeployer(sm SyncletManager) *SyncletBuildAndDeployer

func (*SyncletBuildAndDeployer) BuildAndDeploy

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

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) OnChange added in v0.5.0

func (sm SyncletManager) OnChange(ctx context.Context, store store.RStore)

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) Init added in v0.4.1

func (u Upper) Init(ctx context.Context, action InitAction) error

func (Upper) Start added in v0.1.0

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

type WatchManager

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

func NewWatchManager

func NewWatchManager(watcherMaker FsWatcherMaker, timerMaker timerMaker) *WatchManager

func (*WatchManager) DisableForTesting added in v0.2.0

func (w *WatchManager) DisableForTesting()

func (*WatchManager) OnChange

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

type WatchableManifest added in v0.1.0

type WatchableManifest interface {
	ignore.IgnorableManifest
	Dependencies() []string
	ManifestName() model.ManifestName
}

Jump to

Keyboard shortcuts

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