engine

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 55 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 DetectedOverflowErrMsg = `` /* 193-byte string literal not displayed */

Variables

View Source
var ConfigsTargetID = model.TargetID{
	Type: model.TargetTypeConfigs,
	Name: "singleton",
}
View Source
var UpperReducer = store.Reducer(upperReducerFn)

Functions

func IsDontFallBackError added in v0.10.0

func IsDontFallBackError(err error) bool

func NewErrorAction

func NewErrorAction(err error) store.ErrorAction

func NewImageAndCacheBuilder added in v0.6.0

func NewImageAndCacheBuilder(ib build.ImageBuilder, cb build.CacheBuilder, custb build.CustomBuilder, updateMode UpdateMode) *imageAndCacheBuilder

func NewTiltfileLogWriter added in v0.6.0

func NewTiltfileLogWriter(s store.RStore) *tiltfileLogWriter

func ParseYAMLFromManifests

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

func ProvideTimerMaker

func ProvideTimerMaker() timerMaker

Types

type AnalyticsReporter added in v0.7.11

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

func ProvideAnalyticsReporter added in v0.7.11

func ProvideAnalyticsReporter(a *analytics.TiltAnalytics, st *store.Store) *AnalyticsReporter

func (*AnalyticsReporter) OnChange added in v0.7.11

func (ar *AnalyticsReporter) OnChange(ctx context.Context, st store.RStore)

type BuildAndDeployer

type BuildAndDeployer interface {
	// BuildAndDeploy builds and deployed the specified target specs.
	//
	// Returns a BuildResult that expresses the outputs(s) of the build.
	//
	// BuildResult can be used to construct a set of BuildStates, which contain
	// the last successful builds of each target and the files changed since that build.
	BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, currentState store.BuildStateSet) (store.BuildResultSet, error)
}

type BuildCompleteAction

type BuildCompleteAction struct {
	Result store.BuildResultSet
	Error  error
}

func NewBuildCompleteAction

func NewBuildCompleteAction(result store.BuildResultSet, 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 BuildHandler added in v0.7.11

type BuildHandler func(
	target model.TargetSpec,
	state store.BuildState,
	depResults []store.BuildResult) (store.BuildResult, error)

Allows the caller to inject its own build strategy for dirty targets.

type BuildLogAction added in v0.2.0

type BuildLogAction struct {
	store.LogEvent
}

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 BuildOrder

type BuildOrder []BuildAndDeployer

func (BuildOrder) String added in v0.7.11

func (bo BuildOrder) String() string

type BuildStartedAction

type BuildStartedAction struct {
	ManifestName model.ManifestName
	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, st store.RStore, specs []model.TargetSpec, currentState store.BuildStateSet) (store.BuildResultSet, 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(tfl tiltfile.TiltfileLoader, dockerClient docker.Client) *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
	StartTime    time.Time
}

func (ConfigsReloadStartedAction) Action added in v0.2.0

func (ConfigsReloadStartedAction) Action()

type ConfigsReloadedAction added in v0.2.0

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

	FinishTime time.Time
	Err        error
	Warnings   []string
	Features   map[string]bool
	TeamName   string
}

func (ConfigsReloadedAction) Action added in v0.2.0

func (ConfigsReloadedAction) Action()

type DeployIDAction added in v0.7.11

type DeployIDAction struct {
	TargetID model.TargetID
	DeployID model.DeployID
}

func NewDeployIDAction added in v0.7.11

func NewDeployIDAction(id model.TargetID, dID model.DeployID) DeployIDAction

func NewDeployIDActionsForTargets added in v0.7.11

func NewDeployIDActionsForTargets(ids []model.TargetID, dID model.DeployID) []DeployIDAction

func (DeployIDAction) Action added in v0.7.11

func (DeployIDAction) 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, dc docker.Client,
	icb *imageAndCacheBuilder, c build.Clock) *DockerComposeBuildAndDeployer

func (*DockerComposeBuildAndDeployer) BuildAndDeploy added in v0.4.1

func (bd *DockerComposeBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, currentState store.BuildStateSet) (store.BuildResultSet, 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 DockerComposeLogAction added in v0.4.1

type DockerComposeLogAction struct {
	store.LogEvent
}

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 EventWatchManager added in v0.8.9

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

func NewEventWatchManager added in v0.8.9

func NewEventWatchManager(kClient k8s.Client, clock clockwork.Clock) *EventWatchManager

func (*EventWatchManager) OnChange added in v0.8.9

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

type FallbackTester

type FallbackTester func(error) bool

type FsWatcherMaker

type FsWatcherMaker func(paths []string, ignore watch.PathMatcher, l logger.Logger) (watch.Notify, error)

func ProvideFsWatcherMaker

func ProvideFsWatcherMaker() FsWatcherMaker

type GithubClientFactory added in v0.8.4

type GithubClientFactory func() github.Client

func NewGithubClientFactory added in v0.8.4

func NewGithubClientFactory() GithubClientFactory

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,
	customBuilder build.CustomBuilder,
	k8sClient k8s.Client,
	env k8s.Env,
	analytics *analytics.TiltAnalytics,
	updMode UpdateMode,
	c build.Clock,
	runtime container.Runtime,
	kp KINDPusher,
) *ImageBuildAndDeployer

func (*ImageBuildAndDeployer) BuildAndDeploy

func (ibd *ImageBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, stateSet store.BuildStateSet) (resultSet store.BuildResultSet, 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 ImageExistsChecker added in v0.9.2

type ImageExistsChecker func(ctx context.Context, namedTagged reference.NamedTagged) (bool, error)

type InitAction

type InitAction struct {
	WatchFiles    bool
	TiltfilePath  string
	ConfigFiles   []string
	InitManifests []model.ManifestName

	TiltBuild model.TiltBuild
	StartTime time.Time

	EnableSail bool

	AnalyticsOpt analytics.Opt

	CloudAddress string
	Token        token.Token
}

func (InitAction) Action

func (InitAction) Action()

type KINDPusher added in v0.7.11

type KINDPusher interface {
	PushToKIND(ctx context.Context, ref reference.NamedTagged, w io.Writer) error
}

func NewKINDPusher added in v0.7.11

func NewKINDPusher() KINDPusher

type LatestVersionAction added in v0.8.4

type LatestVersionAction struct {
	Build model.TiltBuild
}

func (LatestVersionAction) Action added in v0.8.4

func (LatestVersionAction) Action()

type LiveUpdateBuildAndDeployer added in v0.9.5

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

func (*LiveUpdateBuildAndDeployer) BuildAndDeploy added in v0.9.5

func (lubad *LiveUpdateBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, stateSet store.BuildStateSet) (store.BuildResultSet, error)

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
	ManifestName model.ManifestName

	// The UID that we matched against to associate this pod with Tilt.
	// Might be the Pod UID itself, or the UID of an ancestor.
	AncestorUID types.UID
}

func NewPodChangeAction

func NewPodChangeAction(pod *v1.Pod, mn model.ManifestName, ancestorUID types.UID) PodChangeAction

func (PodChangeAction) Action

func (PodChangeAction) Action()

type PodLogAction

type PodLogAction struct {
	store.LogEvent
	PodID k8s.PodID
}

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 PodWatch added in v0.7.1

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

func (PodWatch) Equal added in v0.10.5

func (pw PodWatch) Equal(other PodWatch) bool

type PodWatcher

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

func NewPodWatcher

func NewPodWatcher(kCli k8s.Client, ownerFetcher k8s.OwnerFetcher) *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. `level` indicates at what log level this error should be shown to the user

func RedirectToNextBuilderInfof added in v0.7.12

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

func SilentRedirectToNextBuilderf added in v0.7.12

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

func WrapRedirectToNextBuilder added in v0.2.0

func WrapRedirectToNextBuilder(err error, level logger.Level) RedirectToNextBuilder

type ServiceChangeAction

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

func NewServiceChangeAction

func NewServiceChangeAction(service *v1.Service, mn model.ManifestName, 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, ownerFetcher k8s.OwnerFetcher, 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 TargetQueue added in v0.7.11

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

A little data structure to help iterate through dirty targets in dependency order.

func NewImageTargetQueue added in v0.7.11

func NewImageTargetQueue(ctx context.Context, iTargets []model.ImageTarget, state store.BuildStateSet, imageExists ImageExistsChecker) (*TargetQueue, error)

func (*TargetQueue) CountDirty added in v0.7.11

func (q *TargetQueue) CountDirty() int

func (*TargetQueue) RunBuilds added in v0.7.11

func (q *TargetQueue) RunBuilds(handler BuildHandler) error

type TiltAnalyticsSubscriber added in v0.8.7

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

func NewTiltAnalyticsSubscriber added in v0.8.7

func NewTiltAnalyticsSubscriber(ta *analytics.TiltAnalytics) *TiltAnalyticsSubscriber

func (*TiltAnalyticsSubscriber) OnChange added in v0.8.7

func (sub *TiltAnalyticsSubscriber) OnChange(ctx context.Context, st store.RStore)

type TiltVersionChecker added in v0.8.4

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

func NewTiltVersionChecker added in v0.8.4

func NewTiltVersionChecker(ghcf GithubClientFactory, timerMaker timerMaker) *TiltVersionChecker

func (*TiltVersionChecker) OnChange added in v0.8.4

func (tvc *TiltVersionChecker) OnChange(ctx context.Context, st store.RStore)

type TiltfileLogAction added in v0.6.0

type TiltfileLogAction struct {
	store.LogEvent
}

func (TiltfileLogAction) Action added in v0.6.0

func (TiltfileLogAction) Action()

type UIDUpdateAction added in v0.8.9

type UIDUpdateAction struct {
	UID          types.UID
	EventType    watch.EventType
	ManifestName model.ManifestName
	Entity       k8s.K8sEntity
}

func (UIDUpdateAction) Action added in v0.8.9

func (UIDUpdateAction) Action()

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"

	// Use `kubectl exec`
	UpdateModeKubectlExec UpdateMode = "exec"
)

func ProvideUpdateMode

func ProvideUpdateMode(flag UpdateModeFlag, env k8s.Env, runtime container.Runtime) (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 NewUpper

func NewUpper(ctx context.Context, st *store.Store, subs []store.Subscriber) Upper

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,
	b model.TiltBuild,
	watch bool,
	fileName string,
	useActionWriter bool,
	sailMode model.SailMode,
	analyticsOpt analytics.Opt,
	token token.Token,
	cloudAddress 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 WatchableTarget added in v0.5.1

type WatchableTarget interface {
	ignore.IgnorableTarget
	Dependencies() []string
	ID() model.TargetID
}

If you modify this interface, you might also need to update the watchRulesMatch function below.

Jump to

Keyboard shortcuts

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