Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session: clean up data model fields #4407

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions internal/engine/session/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func k8sRuntimeTarget(mt *store.ManifestTarget) *session.Target {
}
}
target.State.Waiting = &session.TargetStateWaiting{
Reason: waitReason,
WaitReason: waitReason,
}
}
}
Expand Down Expand Up @@ -240,17 +240,17 @@ func waitingFromHolds(mn model.ManifestName, holds buildcontrol.HoldSet) *sessio
waitReason = string(hold)
}
return &session.TargetStateWaiting{
Reason: waitReason,
WaitReason: waitReason,
}
}

// tiltfileTarget creates a session.Target object from the store.ManifestState for the current
// Tiltfile.
// tiltfileTarget creates a session.Target object from the engine state for the current Tiltfile.
//
// This is slightly different from generic resource handling because there is no ManifestTarget in the engine
// for the Tiltfile, just ManifestState, but a lot of the logic is shared/duplicated.
// for the Tiltfile (just ManifestState) and config file changes are stored stop level on state, but conceptually
// it does similar things.
func tiltfileTarget(state store.EngineState) session.Target {
tfState := session.Target{
target := session.Target{
Name: "tiltfile:update",
Resources: []string{model.TiltfileManifestName.String()},
Type: session.TargetTypeJob,
Expand All @@ -259,27 +259,27 @@ func tiltfileTarget(state store.EngineState) session.Target {
// Tiltfile is special in engine state and doesn't have a target, just state, so
// this logic is largely duplicated from the generic resource build logic
if !state.TiltfileState.CurrentBuild.Empty() {
tfState.State.Active = &session.TargetStateActive{
target.State.Active = &session.TargetStateActive{
StartTime: metav1.NewMicroTime(state.TiltfileState.CurrentBuild.StartTime),
}
} else if len(state.PendingConfigFileChanges) != 0 {
tfState.State.Waiting = &session.TargetStateWaiting{
Reason: "config-changed",
target.State.Waiting = &session.TargetStateWaiting{
WaitReason: "config-changed",
}
} else if len(state.TiltfileState.BuildHistory) != 0 {
lastBuild := state.TiltfileState.LastBuild()
tfState.State.Terminated = &session.TargetStateTerminated{
target.State.Terminated = &session.TargetStateTerminated{
StartTime: metav1.NewMicroTime(lastBuild.StartTime),
FinishTime: metav1.NewMicroTime(lastBuild.FinishTime),
Error: errToString(lastBuild.Error),
}
} else {
// given the current engine behavior, this doesn't actually occur because
// the first build happens as part of initialization
tfState.State.Waiting = &session.TargetStateWaiting{
Reason: "initial-build",
target.State.Waiting = &session.TargetStateWaiting{
WaitReason: "initial-build",
}
}

return tfState
return target
}
28 changes: 20 additions & 8 deletions pkg/apis/core/v1alpha1/session_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ type SessionStatus struct {
//
// A resource from a Tiltfile might produce one or more targets. A target can also be shared across
// multiple resources (e.g. an image referenced by multiple K8s pods).
Targets []Target `json:"resources"`
Targets []Target `json:"targets"`

// Done indicates whether this Session has completed its work and is ready to exit.
Done bool `json:"done"`
// Error is a non-empty string when the Session is Done but encountered a failure as defined by the ExitCondition
// from the SessionSpec.
//
// +optional
Error string `json:"error,omitempty"`
}

Expand All @@ -172,9 +174,9 @@ type Target struct {
// Server targets run indefinitely (e.g. an HTTP server).
Type TargetType `json:"type"`
// Resources are one or more Tiltfile resources that this target is associated with.
Resources []string `json:"resources,omitempty"`
Resources []string `json:"resources"`
// State provides information about the current status of the target.
State TargetState `json:"runtime,omitempty"`
State TargetState `json:"state"`
}

// TargetType describes a high-level categorization about the expected execution behavior for the target.
Expand All @@ -194,17 +196,25 @@ const (
// be expected to execute.
type TargetState struct {
// Waiting being non-nil indicates that the next execution of the target has been queued but not yet started.
Waiting *TargetStateWaiting `json:"pending,omitempty"`
//
// +optional
Waiting *TargetStateWaiting `json:"waiting,omitempty"`
// Active being non-nil indicates that the target is currently executing.
//
// +optional
Active *TargetStateActive `json:"active,omitempty"`
// Terminated being non-nil indicates that the target finished execution either normally or due to failure.
//
// +optional
Terminated *TargetStateTerminated `json:"terminated,omitempty"`
}

// TargetStateWaiting is a target that has been enqueued for execution but has not yet started.
type TargetStateWaiting struct {
// Reason is a description for why the target is waiting and not yet active.
Reason string `json:"reason"`
// WaitReason is a description for why the target is waiting and not yet active.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

//
// This is NOT the "cause" or "trigger" for the target being invoked.
WaitReason string `json:"waitReason"`
}

// TargetStateActive is a target that is currently running but has not yet finished.
Expand All @@ -213,8 +223,8 @@ type TargetStateActive struct {
StartTime metav1.MicroTime `json:"startTime"`
// Ready indicates that the target has passed readiness checks.
//
// If the target does not use readiness checks, this is always true.
Ready bool
// If the target does not use or support readiness checks, this is always true.
Ready bool `json:"ready"`
}

// TargetStateTerminated is a target that finished running, either because it completed successfully or
Expand All @@ -228,6 +238,8 @@ type TargetStateTerminated struct {
//
// For targets of type TargetTypeServer, this is always populated, as the target is expected to run indefinitely,
// and thus any termination is an error.
//
// +optional
Error string `json:"error,omitempty"`
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.