engine

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 33 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()

Functions

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)

	// 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) 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 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 InitAction

type InitAction struct {
	WatchMounts bool
	Manifests   []model.Manifest
}

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 ManifestReloadedAction

type ManifestReloadedAction struct {
	OldManifest model.Manifest
	NewManifest model.Manifest
	Error       *manifestErr
}

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
}

func NewServiceChangeAction

func NewServiceChangeAction(service *v1.Service) ServiceChangeAction

func (ServiceChangeAction) Action

func (ServiceChangeAction) Action()

type ServiceWatcher

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

func NewServiceWatcher

func NewServiceWatcher(kCli k8s.Client) *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) CreateManifests

func (u Upper) CreateManifests(ctx context.Context, manifests []model.Manifest, watchMounts bool) error

func (Upper) RunHud

func (u Upper) RunHud(ctx context.Context) 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)

Jump to

Keyboard shortcuts

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