Documentation
¶
Index ¶
- Variables
- func StateToView(s EngineState) view.View
- type Action
- type BuildResult
- type BuildState
- type EngineState
- type ManifestState
- type Pod
- type Store
- func (s *Store) Actions() <-chan Action
- func (s *Store) AddSubscriber(sub Subscriber)
- func (s *Store) Close()
- func (s *Store) Dispatch(action Action)
- func (s *Store) LockMutableState() *EngineState
- func (s *Store) NotifySubscribers(ctx context.Context)
- func (s *Store) RLockState() EngineState
- func (s *Store) RUnlockState()
- func (s *Store) UnlockMutableState()
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
var BuildStateClean = BuildState{}
Functions ¶
func StateToView ¶
func StateToView(s EngineState) view.View
Types ¶
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 }
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 (*Store) AddSubscriber ¶
func (s *Store) AddSubscriber(sub Subscriber)
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 ¶
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 ¶
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()