store

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: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildStateClean = BuildState{}

Functions

func StateToView

func StateToView(s EngineState) view.View

Types

type Action

type Action interface {
	Action()
}

type BuildResult

type BuildResult struct {
	// The name+tag of the image that the pod is running.
	//
	// The tag is derived from a content-addressable digest.
	Image reference.NamedTagged

	// If this build was a container build, containerID we built on top of
	ContainerID k8s.ContainerID

	// The namespace where the pod was deployed.
	Namespace k8s.Namespace

	// The k8s entities deployed alongside the image.
	Entities []k8s.K8sEntity

	// Some of our build engines replace the files in-place, rather
	// than building a new image. This captures how much the code
	// running on-pod has diverged from the original image.
	FilesReplacedSet map[string]bool
}

The results of a successful build.

func (BuildResult) HasImage

func (b BuildResult) HasImage() bool

func (BuildResult) IsEmpty

func (b BuildResult) IsEmpty() bool

func (BuildResult) ShallowCloneForContainerUpdate

func (b BuildResult) ShallowCloneForContainerUpdate(filesReplacedSet map[string]bool) BuildResult

Clone the build result and add new replaced files. Does not do a deep clone of the underlying entities.

type BuildState

type BuildState struct {
	// The last successful build.
	LastResult BuildResult

	// Files changed since the last result was build.
	// This must be liberal: it's ok if this has too many files, but not ok if it has too few.
	FilesChangedSet map[string]bool
}

The state of the system since the last successful build. This data structure should be considered immutable. All methods that return a new BuildState should first clone the existing build state.

func NewBuildState

func NewBuildState(result BuildResult, files []string) BuildState

func (BuildState) FilesChanged

func (b BuildState) FilesChanged() []string

Return the files changed since the last result in sorted order. The sorting helps ensure that this is deterministic, both for testing and for deterministic builds.

func (BuildState) FilesChangedSinceLastResultImage

func (b BuildState) FilesChangedSinceLastResultImage() ([]string, error)

Return the files changed since the last result's image in sorted order. The sorting helps ensure that this is deterministic, both for testing and for deterministic builds. Errors if there was no last result image.

func (BuildState) HasImage

func (b BuildState) HasImage() bool

func (BuildState) IsEmpty

func (b BuildState) IsEmpty() bool

A build state is empty if there are no previous results.

func (BuildState) LastImage

func (b BuildState) LastImage() reference.NamedTagged

type EngineState

type EngineState struct {
	// saved so that we can render in order
	ManifestDefinitionOrder []model.ManifestName

	ManifestStates    map[model.ManifestName]*ManifestState
	ManifestsToBuild  []model.ManifestName
	CurrentlyBuilding model.ManifestName
	WatchMounts       bool

	// How many builds were queued on startup (i.e., how many manifests there were)
	InitialBuildCount int

	// How many builds have been completed (pass or fail) since starting tilt
	CompletedBuildCount int

	// For synchronizing BuildController so that it's only
	// doing one action at a time. In the future, we might
	// want to allow it to parallelize builds better, but that
	// would require better tools for triaging output to different streams.
	BuildControllerActionCount int

	PermanentError error
}

func NewState

func NewState() *EngineState

func (EngineState) Manifests

func (s EngineState) Manifests() []model.Manifest

Returns the manifests in order.

type ManifestState

type ManifestState struct {
	LastBuild    BuildResult
	Manifest     model.Manifest
	Pod          Pod
	LBs          map[k8s.ServiceName]*url.URL
	HasBeenBuilt bool

	// TODO(nick): Maybe we should keep timestamps for the most
	// recent change to each file?
	PendingFileChanges map[string]bool

	CurrentlyBuildingFileChanges []string

	CurrentBuildStartTime     time.Time
	CurrentBuildLog           *bytes.Buffer
	LastSuccessfulDeployEdits []string
	LastError                 error
	LastBuildFinishTime       time.Time
	LastSuccessfulDeployTime  time.Time
	LastBuildDuration         time.Duration
	LastBuildLog              *bytes.Buffer
	QueueEntryTime            time.Time

	// If the pod isn't running this container then it's possible we're running stale code
	ExpectedContainerID k8s.ContainerID
	// We detected stale code and are currently doing an image build
	CrashRebuildInProg bool
	// we've observed changes to config file(s) and need to reload the manifest next time we start a build
	ConfigIsDirty bool
}

func NewManifestState

func NewManifestState(manifest model.Manifest) *ManifestState

func (*ManifestState) PendingFileChangesWithoutUnmountedConfigFiles

func (ms *ManifestState) PendingFileChangesWithoutUnmountedConfigFiles(ctx context.Context) (map[string]bool, error)

Returns a set of pending file changes, without config files that don't belong to mounts. (Changed config files show up in ms.PendingFileChanges and don't necessarily belong to any mounts/watched directories -- we don't want to run these files through a build b/c we'll pitch an error if we find un-mounted files at that point.)

type Pod

type Pod struct {
	PodID     k8s.PodID
	Namespace k8s.Namespace
	StartedAt time.Time
	Status    string
	Phase     v1.PodPhase

	// The log for the previously active pod, if any
	PreRestartLog []byte
	// The log for the currently active pod, if any
	CurrentLog []byte

	// Corresponds to the deployed container.
	ContainerName  k8s.ContainerName
	ContainerID    k8s.ContainerID
	ContainerPorts []int32
	ContainerReady bool

	// We want to show the user # of restarts since pod has been running current code,
	// i.e. OldRestarts - Total Restarts
	ContainerRestarts int
	OldRestarts       int // # times the pod restarted when it was running old code
}

func (Pod) Log

func (p Pod) Log() string

attempting to include the most recent crash, but no preceding crashes (e.g., we don't want to show the same panic 20x in a crash loop) if the current pod has crashed, then just print the current pod if the current pod is live, print the current pod plus the last pod

type Store

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

A central state store, modeled after the Reactive programming UX pattern. Terminology is borrowed liberally from Redux. These docs in particular are helpful: https://redux.js.org/introduction/threeprinciples https://redux.js.org/basics

func NewStore

func NewStore() *Store

func (*Store) Actions

func (s *Store) Actions() <-chan Action

func (*Store) AddSubscriber

func (s *Store) AddSubscriber(sub Subscriber)

func (*Store) Close

func (s *Store) Close()

func (*Store) Dispatch

func (s *Store) Dispatch(action Action)

func (*Store) LockMutableState

func (s *Store) LockMutableState() *EngineState

TODO(nick): Phase this out. Anyone that uses this should be implemented as a reducer.

func (*Store) NotifySubscribers

func (s *Store) NotifySubscribers(ctx context.Context)

Sends messages to all the subscribers asynchronously.

func (*Store) RLockState

func (s *Store) RLockState() EngineState

TODO(nick): Clone the state to ensure it's not mutated. For now, we use RW locks to simulate the same behavior, but the onus is on the caller to RUnlockState.

func (*Store) RUnlockState

func (s *Store) RUnlockState()

func (*Store) UnlockMutableState

func (s *Store) UnlockMutableState()

type Subscriber

type Subscriber interface {
	OnChange(ctx context.Context, store *Store)
}

A subscriber is notified whenever the state changes.

Subscribers do not need to be thread-safe. The Store will only call OnChange for a given subscriber when the last call completes.

Subscribers are only allowed to read state. If they want to modify state, they should call store.Dispatch()

Jump to

Keyboard shortcuts

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