github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/store/manifest_target.go (about) 1 package store 2 3 import ( 4 "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1" 5 "github.com/tilt-dev/tilt/pkg/model" 6 ) 7 8 type ManifestTarget struct { 9 Manifest model.Manifest 10 State *ManifestState 11 } 12 13 func NewManifestTarget(m model.Manifest) *ManifestTarget { 14 return &ManifestTarget{ 15 Manifest: m, 16 State: NewManifestState(m), 17 } 18 } 19 20 func (t ManifestTarget) Spec() model.TargetSpec { 21 return t.Manifest 22 } 23 24 func (t ManifestTarget) Status() model.TargetStatus { 25 return t.State 26 } 27 28 func (mt *ManifestTarget) UpdateStatus() v1alpha1.UpdateStatus { 29 m := mt.Manifest 30 us := mt.State.UpdateStatus(m.TriggerMode) 31 32 if m.IsLocal() && m.LocalTarget().UpdateCmdSpec == nil { 33 // NOTE(nick): We currently model a local_resource(serve_cmd) as a Manifest 34 // with a no-op Update. BuildController treats it like any other 35 // resource. When the build completes, the server controller starts the 36 // server. 37 // 38 // We want to make sure that the UpdateStatus is still "Pending" until we 39 // have a completed build record. Otherwise the server controller will try 40 // to start the server twice (once while the update is in-progress, and once 41 // when the update completes). 42 if us == v1alpha1.UpdateStatusInProgress { 43 return v1alpha1.UpdateStatusPending 44 } 45 46 if us == v1alpha1.UpdateStatusOK { 47 // The no-op build job completed, but it's confusing/misleading to show 48 // the status of something non-existent as having succeeded, so instead 49 // return the special N/A status so that it can be distinguished from a 50 // true update. 51 // 52 // Note that for local resources with auto_init=False that have not been 53 // triggered, the update status will be UpdateStatusNone until such a time 54 // as they are triggered, and will be UpdateStatusNotApplicable thereafter. 55 // 56 // This is a bit odd, but currently this is how the server controller 57 // determines whether to launch the serve_cmd, so it needs to be able to 58 // distinguish between "resource has never been triggered" (so the server 59 // should not be launched) and "resource has been triggered but has no 60 // update command to wait for" (and thus the server should be launched). 61 return v1alpha1.UpdateStatusNotApplicable 62 } 63 } 64 65 return us 66 } 67 68 // Compute the runtime status for the whole Manifest. 69 func (mt *ManifestTarget) RuntimeStatus() v1alpha1.RuntimeStatus { 70 m := mt.Manifest 71 if m.IsLocal() && m.LocalTarget().ServeCmd.Empty() { 72 return v1alpha1.RuntimeStatusNotApplicable 73 } 74 return mt.State.RuntimeStatus(m.TriggerMode) 75 } 76 77 var _ model.Target = &ManifestTarget{}