store

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 19 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 ManifestStateEndpoints added in v0.2.0

func ManifestStateEndpoints(ms *ManifestState) (endpoints []string)

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

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

	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) WithDeployInfo added in v0.2.0

func (b BuildState) WithDeployInfo(d DeployInfo) BuildState

type DeployInfo added in v0.2.0

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

The information we need to find a ready container.

func NewDeployInfo added in v0.2.0

func NewDeployInfo(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 (DeployInfo) Empty added in v0.2.0

func (d DeployInfo) Empty() bool

type EngineState

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

	ManifestStates    map[model.ManifestName]*ManifestState
	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

	// 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 []byte `testdiff:"ignore"`

	// GlobalYAML is a special manifest that has no images, but has dependencies
	// and a bunch of YAML that is deployed when those dependencies change.
	// TODO(dmiller) in the future we may have many of these manifests, but for now it's a special case.
	GlobalYAML      model.YAMLManifest
	GlobalYAMLState *YAMLManifestState

	TiltfilePath             string
	ConfigFiles              []string
	PendingConfigFileChanges map[string]bool

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

	LastTiltfileBuild model.BuildStatus

	TriggerMode  model.TriggerMode
	TriggerQueue []model.ManifestName

	IsProfiling bool
}

func NewState

func NewState() *EngineState

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

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

Returns the manifests in order.

func (EngineState) RelativeTiltfilePath added in v0.4.1

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

type LogActionsFlag added in v0.2.0

type LogActionsFlag bool

type ManifestState

type ManifestState struct {
	Manifest model.Manifest

	// k8s-specific state
	PodSet PodSet
	LBs    map[k8s.ServiceName]*url.URL

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

	// Store the times of all the pending changes,
	// so we can prioritize the oldest one first.
	PendingFileChanges    map[string]time.Time
	PendingManifestChange time.Time

	// The current build
	CurrentBuild model.BuildStatus

	LastSuccessfulResult     BuildResult
	LastSuccessfulDeployTime time.Time

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

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

func NewManifestState

func NewManifestState(manifest model.Manifest) *ManifestState

func (*ManifestState) AddCompletedBuild added in v0.4.1

func (ms *ManifestState) AddCompletedBuild(bs model.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 mount 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) 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 mount files or config files should kick off a new build.

func (*ManifestState) LastBuild

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

func (*ManifestState) MostRecentPod added in v0.2.0

func (ms *ManifestState) MostRecentPod() Pod

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

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

	// The log for the previously active pod, if any
	PreRestartLog []byte `testdiff:"ignore"`
	// The log for the currently active pod, if any
	CurrentLog []byte `testdiff:"ignore"`

	// Corresponds to the deployed container.
	ContainerName  container.Name
	ContainerID    container.ID
	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) Empty added in v0.2.0

func (p Pod) Empty() bool

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 PodSet added in v0.2.0

type PodSet struct {
	Pods    map[k8s.PodID]*Pod
	ImageID reference.NamedTagged
}

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

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) 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(sub Subscriber) error

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

Jump to

Keyboard shortcuts

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