From c1b9b3ad288cc0e1629615d1962dfc7a93063fda Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Wed, 7 Apr 2021 15:12:48 -0400 Subject: [PATCH] session: clean up data model fields (#4407) Missed an desired rename here (`Reason` -> `WaitReason`) and a few of these had mismatched/missing JSON field names from continuous changes. Also renamed a misnamed var in the conversion. --- internal/engine/session/conv.go | 26 +++++++++++------------ pkg/apis/core/v1alpha1/session_types.go | 28 ++++++++++++++++++------- pkg/openapi/zz_generated.openapi.go | 22 +++++++++---------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/internal/engine/session/conv.go b/internal/engine/session/conv.go index d5a49a353e..f7376cf626 100644 --- a/internal/engine/session/conv.go +++ b/internal/engine/session/conv.go @@ -103,7 +103,7 @@ func k8sRuntimeTarget(mt *store.ManifestTarget) *session.Target { } } target.State.Waiting = &session.TargetStateWaiting{ - Reason: waitReason, + WaitReason: waitReason, } } } @@ -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, @@ -259,16 +259,16 @@ 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), @@ -276,10 +276,10 @@ func tiltfileTarget(state store.EngineState) session.Target { } 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 } diff --git a/pkg/apis/core/v1alpha1/session_types.go b/pkg/apis/core/v1alpha1/session_types.go index 937a39fa77..4361c725c3 100644 --- a/pkg/apis/core/v1alpha1/session_types.go +++ b/pkg/apis/core/v1alpha1/session_types.go @@ -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"` } @@ -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. @@ -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. + // + // 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. @@ -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 @@ -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"` } diff --git a/pkg/openapi/zz_generated.openapi.go b/pkg/openapi/zz_generated.openapi.go index 30baeec11c..2d29b4bebc 100644 --- a/pkg/openapi/zz_generated.openapi.go +++ b/pkg/openapi/zz_generated.openapi.go @@ -1313,7 +1313,7 @@ func schema_pkg_apis_core_v1alpha1_SessionStatus(ref common.ReferenceCallback) c Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime"), }, }, - "resources": { + "targets": { SchemaProps: spec.SchemaProps{ Description: "Targets are normalized representations of the servers/jobs managed by this Session.\n\nA 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).", Type: []string{"array"}, @@ -1343,7 +1343,7 @@ func schema_pkg_apis_core_v1alpha1_SessionStatus(ref common.ReferenceCallback) c }, }, }, - Required: []string{"pid", "startTime", "resources", "done"}, + Required: []string{"pid", "startTime", "targets", "done"}, }, }, Dependencies: []string{ @@ -1418,7 +1418,7 @@ func schema_pkg_apis_core_v1alpha1_Target(ref common.ReferenceCallback) common.O }, }, }, - "runtime": { + "state": { SchemaProps: spec.SchemaProps{ Description: "State provides information about the current status of the target.", Default: map[string]interface{}{}, @@ -1426,7 +1426,7 @@ func schema_pkg_apis_core_v1alpha1_Target(ref common.ReferenceCallback) common.O }, }, }, - Required: []string{"name", "type"}, + Required: []string{"name", "type", "resources", "state"}, }, }, Dependencies: []string{ @@ -1441,7 +1441,7 @@ func schema_pkg_apis_core_v1alpha1_TargetState(ref common.ReferenceCallback) com Description: "TargetState describes the current execution status for a target.\n\nEither EXACTLY one of Waiting, Active, or Terminated will be populated or NONE of them will be. In the event that all states are null, the target is currently inactive or disabled and should not be expected to execute.", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "pending": { + "waiting": { SchemaProps: spec.SchemaProps{ Description: "Waiting being non-nil indicates that the next execution of the target has been queued but not yet started.", Ref: ref("github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1.TargetStateWaiting"), @@ -1481,16 +1481,16 @@ func schema_pkg_apis_core_v1alpha1_TargetStateActive(ref common.ReferenceCallbac Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime"), }, }, - "Ready": { + "ready": { SchemaProps: spec.SchemaProps{ - Description: "Ready indicates that the target has passed readiness checks.\n\nIf the target does not use readiness checks, this is always true.", + Description: "Ready indicates that the target has passed readiness checks.\n\nIf the target does not use or support readiness checks, this is always true.", Default: false, Type: []string{"boolean"}, Format: "", }, }, }, - Required: []string{"startTime", "Ready"}, + Required: []string{"startTime", "ready"}, }, }, Dependencies: []string{ @@ -1542,16 +1542,16 @@ func schema_pkg_apis_core_v1alpha1_TargetStateWaiting(ref common.ReferenceCallba Description: "TargetStateWaiting is a target that has been enqueued for execution but has not yet started.", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "reason": { + "waitReason": { SchemaProps: spec.SchemaProps{ - Description: "Reason is a description for why the target is waiting and not yet active.", + Description: "WaitReason is a description for why the target is waiting and not yet active.\n\nThis is NOT the \"cause\" or \"trigger\" for the target being invoked.", Default: "", Type: []string{"string"}, Format: "", }, }, }, - Required: []string{"reason"}, + Required: []string{"waitReason"}, }, }, }