store

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildStateClean = BuildState{}
View Source
var EmptyReducer = Reducer(func(ctx context.Context, s *EngineState, action Action) {})

Functions

func ManifestTargetEndpoints added in v0.5.0

func ManifestTargetEndpoints(mt *ManifestTarget) (endpoints []string)

func NewLogActionLogger added in v0.8.9

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

func StateToView

func StateToView(s EngineState) view.View

Types

type Action

type Action interface {
	Action()
}

func AssertNoActionOfType added in v0.8.10

func AssertNoActionOfType(t testing.TB, typ reflect.Type, getActions func() []Action) Action

for use by tests (with a real channel-based store, NOT a TestingStore). Assert that we don't see an action of the given type

func WaitForAction added in v0.8.1

func WaitForAction(t testing.TB, typ reflect.Type, getActions func() []Action) Action

for use by tests (with a real channel-based store, NOT a TestingStore), to wait until an action of the specified type comes out of the given chan at some point we might want it to return the index it was found at, and then take an index, so that we can start searching from the next index

type AnalyticsNudgeSurfacedAction added in v0.8.7

type AnalyticsNudgeSurfacedAction struct{}

func (AnalyticsNudgeSurfacedAction) Action added in v0.8.7

type AnalyticsOptAction added in v0.8.4

type AnalyticsOptAction struct {
	Opt analytics.Opt
}

func (AnalyticsOptAction) Action added in v0.8.4

func (AnalyticsOptAction) Action()

type BuildResult

type BuildResult struct {
	// The image target that this built.
	TargetID model.TargetID

	// 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 container.ID

	// 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 NewContainerBuildResult added in v0.7.11

func NewContainerBuildResult(id model.TargetID, containerID container.ID) BuildResult

For docker-compose deploys that don't have any built images.

func NewImageBuildResult added in v0.7.11

func NewImageBuildResult(id model.TargetID, image reference.NamedTagged) BuildResult

For image targets. The container id will be added later.

func (BuildResult) HasImage

func (b BuildResult) HasImage() bool

func (BuildResult) IsEmpty

func (b BuildResult) IsEmpty() bool

func (BuildResult) IsInPlaceUpdate added in v0.8.6

func (b BuildResult) IsInPlaceUpdate() 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 BuildResultSet added in v0.5.1

type BuildResultSet map[model.TargetID]BuildResult

func (BuildResultSet) OneAndOnlyContainerID added in v0.7.11

func (set BuildResultSet) OneAndOnlyContainerID() container.ID

Returns a container ID iff it's the only container ID in the result set. If there are multiple container IDs, we have to give up.

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

	DeployInfo DeployInfo
}

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

func (b BuildState) LastImageAsString() string

func (BuildState) NeedsImageBuild added in v0.7.11

func (b BuildState) NeedsImageBuild() bool

Whether the image represented by this state needs to be built. If the image has already been built, and no files have been changed since then, then we can re-use the previous result.

func (BuildState) WithDeployTarget added in v0.4.3

func (b BuildState) WithDeployTarget(d DeployInfo) BuildState

type BuildStateSet added in v0.5.1

type BuildStateSet map[model.TargetID]BuildState

func (BuildStateSet) Empty added in v0.5.1

func (set BuildStateSet) Empty() bool

func (BuildStateSet) FilesChanged added in v0.5.1

func (set BuildStateSet) FilesChanged() []string

type BuildStatus added in v0.5.1

type BuildStatus struct {
	// Stores the times of all the pending changes,
	// so we can prioritize the oldest one first.
	// This map is mutable.
	PendingFileChanges map[string]time.Time

	LastSuccessfulResult BuildResult
}

TODO(nick): This will eventually implement TargetStatus

func (BuildStatus) IsEmpty added in v0.7.11

func (s BuildStatus) IsEmpty() bool

type ContainerInfo added in v0.7.11

type ContainerInfo struct {
	ID container.ID
	container.Name
}

The minimum info we need to retrieve logs for a container.

type DeployInfo added in v0.2.0

type DeployInfo struct {
	PodID         k8s.PodID
	ContainerID   container.ID
	ContainerName container.Name
	Namespace     k8s.Namespace
}

The information we need to find a ready container.

func NewDeployInfo added in v0.2.0

func NewDeployInfo(iTarget model.ImageTarget, deployID model.DeployID, podSet PodSet) DeployInfo

Check to see if there's a single, unambiguous Ready container in the given PodSet. If so, create a DeployInfo for that container.

func NewDeployInfoFromDC added in v0.7.11

func NewDeployInfoFromDC(state dockercompose.State) DeployInfo

func (DeployInfo) Empty added in v0.2.0

func (d DeployInfo) Empty() bool

type DirtyBit added in v0.8.0

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

func NewDirtyBit added in v0.8.0

func NewDirtyBit() *DirtyBit

func (*DirtyBit) FinishBuild added in v0.8.0

func (b *DirtyBit) FinishBuild(t DirtyStartToken)

func (*DirtyBit) IsDirty added in v0.8.0

func (b *DirtyBit) IsDirty() bool

func (*DirtyBit) MarkDirty added in v0.8.0

func (b *DirtyBit) MarkDirty()

Mark the bit as dirty. If the change happens and this is marked dirty later, that's usually ok. It just means IsDirty might have false positives (i.e., we do spurious builds).

func (*DirtyBit) StartBuildIfDirty added in v0.8.0

func (b *DirtyBit) StartBuildIfDirty() (DirtyStartToken, bool)

If the bit is currently marked dirty, returns a StartToken to pass to FinishBuild. Otherwise, return false.

type DirtyStartToken added in v0.8.0

type DirtyStartToken time.Time

type EngineState

type EngineState struct {
	TiltBuildInfo model.TiltBuild
	TiltStartTime time.Time

	// saved so that we can render in order
	ManifestDefinitionOrder []model.ManifestName

	// TODO(nick): This will eventually be a general Target index.
	ManifestTargets map[model.ManifestName]*ManifestTarget

	CurrentlyBuilding model.ManifestName
	WatchFiles        bool

	// How many builds were queued on startup (i.e., how many manifests there were
	// after initial Tiltfile load)
	InitialBuildsQueued 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

	// The user has indicated they want to exit
	UserExited bool

	// The full log stream for tilt. This might deserve gc or file storage at some point.
	Log model.Log `testdiff:"ignore"`

	TiltfilePath             string
	ConfigFiles              []string
	TiltIgnoreContents       string
	PendingConfigFileChanges map[string]time.Time

	// InitManifests is the list of manifest names that we were told to init from the CLI.
	InitManifests []model.ManifestName

	TriggerQueue []model.ManifestName

	LogTimestamps bool
	IsProfiling   bool

	LastTiltfileBuild    model.BuildRecord
	CurrentTiltfileBuild model.BuildRecord
	TiltfileCombinedLog  model.Log

	SailEnabled bool
	SailURL     string

	FirstTiltfileBuildCompleted bool

	// from GitHub
	LatestTiltBuild model.TiltBuild

	// Analytics Info
	AnalyticsOpt           analytics.Opt // changes to this field will propagate into the TiltAnalytics subscriber + we'll record them as user choice
	AnalyticsNudgeSurfaced bool          // this flag is set the first time we show the analytics nudge to the user.

	ObjectsByK8sUIDs map[k8s.UID]UIDMapValue
}

func NewState

func NewState() *EngineState

func (*EngineState) BuildStatus added in v0.5.1

func (e *EngineState) BuildStatus(id model.TargetID) BuildStatus

func (EngineState) DockerComposeConfigPath added in v0.4.1

func (s EngineState) DockerComposeConfigPath() string

DockerComposeConfigPath returns the path to the docker-compose yaml file of any docker-compose manifests on this EngineState. NOTE(maia): current assumption is only one d-c.yaml per run, so we take the path from the first d-c manifest we see.

func (EngineState) IsEmpty added in v0.4.1

func (e EngineState) IsEmpty() bool

func (EngineState) LastTiltfileError added in v0.2.0

func (e EngineState) LastTiltfileError() error

func (EngineState) Manifest added in v0.5.0

func (e EngineState) Manifest(mn model.ManifestName) (model.Manifest, bool)

func (*EngineState) ManifestNamesForTargetID added in v0.7.11

func (e *EngineState) ManifestNamesForTargetID(id model.TargetID) []model.ManifestName

func (EngineState) ManifestState added in v0.5.0

func (e EngineState) ManifestState(mn model.ManifestName) (*ManifestState, bool)

func (EngineState) ManifestStates

func (e EngineState) ManifestStates() []*ManifestState

Returns ManifestStates in a stable order

func (EngineState) Manifests

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

Returns Manifests in a stable order

func (EngineState) RelativeTiltfilePath added in v0.4.1

func (e EngineState) RelativeTiltfilePath() (string, error)

func (EngineState) Targets added in v0.5.0

func (e EngineState) Targets() []*ManifestTarget

Returns ManifestTargets in a stable order

func (*EngineState) UpsertManifestTarget added in v0.5.0

func (e *EngineState) UpsertManifestTarget(mt *ManifestTarget)

type ErrorAction added in v0.7.11

type ErrorAction struct {
	Error error
}

func NewErrorAction added in v0.7.11

func NewErrorAction(err error) ErrorAction

func (ErrorAction) Action added in v0.7.11

func (ErrorAction) Action()

type K8sEventAction added in v0.8.10

type K8sEventAction struct {
	Event *v1.Event
}

func NewK8sEventAction added in v0.8.10

func NewK8sEventAction(event *v1.Event) K8sEventAction

func (K8sEventAction) Action added in v0.8.10

func (K8sEventAction) Action()

func (K8sEventAction) ToLogAction added in v0.8.10

func (kEvt K8sEventAction) ToLogAction(mn model.ManifestName) LogAction

type LogAction added in v0.8.1

type LogAction interface {
	Action
	model.LogEvent

	// Ideally, all logs should be associated with a source.
	//
	// In practice, not all logs have an obvious source identifier,
	// so this might be empty.
	//
	// Right now, that source is a ManifestName. But in the future,
	// this might make more sense as another kind of identifier.
	//
	// (As of this writing, we have TargetID as an abstract build-time
	// source identifier, but no generic run-time source identifier)
	Source() model.ManifestName
}

type LogActionsFlag added in v0.2.0

type LogActionsFlag bool

type LogEvent added in v0.8.1

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

func NewGlobalLogEvent added in v0.8.9

func NewGlobalLogEvent(b []byte) LogEvent

func NewLogEvent added in v0.8.1

func NewLogEvent(mn model.ManifestName, b []byte) LogEvent

func (LogEvent) Action added in v0.8.9

func (LogEvent) Action()

func (LogEvent) Message added in v0.8.1

func (le LogEvent) Message() []byte

func (LogEvent) Source added in v0.8.9

func (le LogEvent) Source() model.ManifestName

func (LogEvent) Time added in v0.8.1

func (le LogEvent) Time() time.Time

type ManifestState

type ManifestState struct {
	Name model.ManifestName

	// k8s-specific state
	PodSet   PodSet
	LBs      map[k8s.ServiceName]*url.URL
	DeployID model.DeployID // ID we have assigned to the current deploy (helps find expected k8s objects)

	BuildStatuses map[model.TargetID]*BuildStatus

	// State of the running resource -- specific to type (e.g. k8s, docker-compose, etc.)
	ResourceState ResourceState

	PendingManifestChange time.Time

	// The current build
	CurrentBuild model.BuildRecord

	LastSuccessfulDeployTime time.Time

	// The last `BuildHistoryLimit` builds. The most recent build is first in the slice.
	BuildHistory []model.BuildRecord

	// If the pod isn't running this container then it's possible we're running stale code
	ExpectedContainerID container.ID
	// We detected stale code and are currently doing an image build
	NeedsRebuildFromCrash bool

	// If a pod had to be killed because it was crashing, we keep the old log
	// around for a little while so we can show it in the UX.
	CrashLog model.Log

	// The log stream for this resource
	CombinedLog model.Log `testdiff:"ignore"`

	// If this manifest was changed, which config files led to the most recent change in manifest definition
	ConfigFilesThatCausedChange []string

	K8sWarnEvents []k8s.EventWithEntity
}

func (*ManifestState) ActiveBuild added in v0.4.3

func (ms *ManifestState) ActiveBuild() model.BuildRecord

func (*ManifestState) AddCompletedBuild added in v0.4.1

func (ms *ManifestState) AddCompletedBuild(bs model.BuildRecord)

func (*ManifestState) BuildStatus added in v0.5.1

func (ms *ManifestState) BuildStatus(id model.TargetID) BuildStatus

func (*ManifestState) DCResourceState added in v0.4.1

func (ms *ManifestState) DCResourceState() dockercompose.State

func (*ManifestState) HasPendingChanges added in v0.4.1

func (ms *ManifestState) HasPendingChanges() (bool, time.Time)

Whether changes have been made to this Manifest's synced files or config since the last build.

Returns: bool: whether changes have been made Time: the time of the earliest change

func (*ManifestState) HasPendingChangesBefore added in v0.4.1

func (ms *ManifestState) HasPendingChangesBefore(highWaterMark time.Time) (bool, time.Time)

Like HasPendingChanges, but relative to a particular time.

func (*ManifestState) HasPendingFileChanges added in v0.7.11

func (ms *ManifestState) HasPendingFileChanges() bool

func (*ManifestState) IsDC added in v0.4.1

func (ms *ManifestState) IsDC() bool

func (*ManifestState) IsPendingTime added in v0.2.0

func (ms *ManifestState) IsPendingTime(t time.Time) bool

Whether a change at the given time should trigger a build. Used to determine if changes to synced files or config files should kick off a new build.

func (*ManifestState) LastBuild

func (ms *ManifestState) LastBuild() model.BuildRecord

func (*ManifestState) MostRecentPod added in v0.2.0

func (ms *ManifestState) MostRecentPod() Pod

func (*ManifestState) MutableBuildStatus added in v0.5.1

func (ms *ManifestState) MutableBuildStatus(id model.TargetID) *BuildStatus

func (*ManifestState) NextBuildReason added in v0.2.0

func (ms *ManifestState) NextBuildReason() model.BuildReason

func (*ManifestState) StartedFirstBuild added in v0.2.0

func (ms *ManifestState) StartedFirstBuild() bool

func (*ManifestState) TargetID added in v0.4.3

func (ms *ManifestState) TargetID() model.TargetID

type ManifestTarget added in v0.5.0

type ManifestTarget struct {
	Manifest model.Manifest
	State    *ManifestState
}

func NewManifestTarget added in v0.5.0

func NewManifestTarget(m model.Manifest) *ManifestTarget

func (ManifestTarget) Spec added in v0.5.0

func (t ManifestTarget) Spec() model.TargetSpec

func (ManifestTarget) Status added in v0.5.0

func (t ManifestTarget) Status() model.TargetStatus

type Pod

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

	// Set when we get ready to replace a pod. We may do the update in-place.
	UpdateStartTime time.Time

	// If a pod is being deleted, Kubernetes marks it as Running
	// until it actually gets removed.
	Deleting bool

	HasSynclet bool

	// The log for the currently active pod, if any
	CurrentLog model.Log `testdiff:"ignore"`

	// Corresponds to the deployed container.
	ContainerName     container.Name
	ContainerID       container.ID
	ContainerPorts    []int32
	ContainerReady    bool
	ContainerImageRef reference.Named

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

	// HACK(maia): eventually we'll want our model of the world to handle pods with
	// multiple containers (for logs, restart counts, port forwards, etc.). For now,
	// we need to ship log visibility into multiple containers. Here's the minimum
	// of info we need for that.
	ContainerInfos []ContainerInfo
}

func (Pod) Empty added in v0.2.0

func (p Pod) Empty() bool

func (Pod) Log

func (p Pod) Log() model.Log

type PodSet added in v0.2.0

type PodSet struct {
	Pods     map[k8s.PodID]*Pod
	DeployID model.DeployID // Deploy that these pods correspond to
}

func NewPodSet added in v0.2.0

func NewPodSet(pods ...Pod) PodSet

func (PodSet) ContainsID added in v0.2.0

func (s PodSet) ContainsID(id k8s.PodID) bool

func (PodSet) Len added in v0.2.0

func (s PodSet) Len() int

func (PodSet) MostRecentPod added in v0.2.0

func (s PodSet) MostRecentPod() Pod

Get the "most recent pod" from the PodSet. For most users, we believe there will be only one pod per manifest. So most of this time, this will return the only pod. And in other cases, it will return a reasonable, consistent default.

func (PodSet) PodList added in v0.2.0

func (s PodSet) PodList() []Pod

type RStore added in v0.2.0

type RStore interface {
	Dispatch(action Action)
	RLockState() EngineState
	RUnlockState()
}

Read-only store

type Reducer added in v0.1.0

type Reducer func(ctx context.Context, engineState *EngineState, action Action)

type ResourceState added in v0.4.1

type ResourceState interface {
	ResourceState()
}

type SetUpper added in v0.8.2

type SetUpper interface {
	SetUp(ctx context.Context)
}

Some subscribers need to do SetUp or TearDown. Both hold the subscriber lock, so should return quickly.

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(reducer Reducer, logActions LogActionsFlag) *Store

func NewStoreForTesting added in v0.1.0

func NewStoreForTesting() (st *Store, getActions func() []Action)

Returns a Store for testing that saves observed actions and makes them available via the return value `getActions`

func (*Store) AddSubscriber

func (s *Store) AddSubscriber(ctx context.Context, sub Subscriber)

func (*Store) Close

func (s *Store) Close()

func (*Store) Dispatch

func (s *Store) Dispatch(action Action)

func (*Store) LockMutableStateForTesting added in v0.1.0

func (s *Store) LockMutableStateForTesting() *EngineState

func (*Store) Loop added in v0.1.0

func (s *Store) Loop(ctx context.Context) error

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

func (s *Store) RemoveSubscriber(ctx context.Context, sub Subscriber) error

func (*Store) SetUpSubscribersForTesting added in v0.8.2

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

func (*Store) UnlockMutableState

func (s *Store) UnlockMutableState()

type Subscriber

type Subscriber interface {
	OnChange(ctx context.Context, st RStore)
}

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()

type SubscriberLifecycle added in v0.7.11

type SubscriberLifecycle interface {
	SetUpper
	TearDowner
}

Convenience interface for subscriber fulfilling both SetUpper and TearDowner

type TearDowner added in v0.8.2

type TearDowner interface {
	TearDown(ctx context.Context)
}

type TestingStore added in v0.2.0

type TestingStore struct {
	Actions []Action
	// contains filtered or unexported fields
}

func NewTestingStore added in v0.2.0

func NewTestingStore() *TestingStore

func (*TestingStore) Dispatch added in v0.2.0

func (s *TestingStore) Dispatch(action Action)

func (*TestingStore) RLockState added in v0.2.0

func (s *TestingStore) RLockState() EngineState

func (*TestingStore) RUnlockState added in v0.2.0

func (s *TestingStore) RUnlockState()

func (*TestingStore) SetState added in v0.2.0

func (s *TestingStore) SetState(state EngineState)

type UIDMapValue added in v0.8.9

type UIDMapValue struct {
	Manifest model.ManifestName
	Entity   k8s.K8sEntity
}

type YAMLManifestState added in v0.1.0

type YAMLManifestState struct {
	HasBeenDeployed bool

	CurrentApplyStartTime   time.Time
	LastError               error
	LastApplyFinishTime     time.Time
	LastSuccessfulApplyTime time.Time
	LastApplyStartTime      time.Time
}

func NewYAMLManifestState added in v0.1.0

func NewYAMLManifestState() *YAMLManifestState

func (*YAMLManifestState) ActiveBuild added in v0.4.3

func (s *YAMLManifestState) ActiveBuild() model.BuildRecord

func (*YAMLManifestState) LastBuild added in v0.4.3

func (s *YAMLManifestState) LastBuild() model.BuildRecord

func (*YAMLManifestState) TargetID added in v0.4.3

func (s *YAMLManifestState) TargetID() model.TargetID

Jump to

Keyboard shortcuts

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