Skip to content

Commit

Permalink
engine: add an up-to-date condition to all uiresources (#5236)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed Nov 30, 2021
1 parent 30cd9b1 commit dd065a4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/cloud/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func TestWriteSnapshotTo(t *testing.T) {
"updateStatus": "pending",
"order": 1,
"conditions": [
{
"type": "UpToDate",
"status": "False",
"reason": "UpdatePending"
},
{
"type": "Ready",
"status": "False",
Expand Down
11 changes: 11 additions & 0 deletions internal/engine/uiresource/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestUpdateTiltfile(t *testing.T) {
require.NotNil(t, r)
assert.Equal(t, "3", r.ObjectMeta.ResourceVersion)
assert.Equal(t, "False", string(readyCondition(r).Status))
assert.Equal(t, "False", string(upToDateCondition(r).Status))

// Make sure OnChange is idempotent.
_ = f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
Expand All @@ -63,6 +64,7 @@ func TestUpdateTiltfile(t *testing.T) {
r = f.resource("(Tiltfile)")
require.NotNil(t, r)
assert.Equal(t, "4", r.ObjectMeta.ResourceVersion)
assert.Equal(t, "True", string(upToDateCondition(r).Status))
assert.Equal(t, "True", string(readyCondition(r).Status))
}

Expand Down Expand Up @@ -104,3 +106,12 @@ func readyCondition(r *v1alpha1.UIResource) *v1alpha1.UIResourceCondition {
}
return nil
}

func upToDateCondition(r *v1alpha1.UIResource) *v1alpha1.UIResourceCondition {
for _, c := range r.Status.Conditions {
if c.Type == v1alpha1.UIResourceUpToDate {
return &c
}
}
return nil
}
27 changes: 27 additions & 0 deletions internal/hud/webview/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func toUIResource(mt *store.ManifestTarget, s store.EngineState, disableSources
}

r.Status.Conditions = []v1alpha1.UIResourceCondition{
UIResourceUpToDateCondition(r.Status),
UIResourceReadyCondition(r.Status),
}
return r, nil
Expand Down Expand Up @@ -341,6 +342,31 @@ func UIResourceReadyCondition(r v1alpha1.UIResourceStatus) v1alpha1.UIResourceCo
return c
}

// The "UpToDate" condition is a cross-resource status report that's synthesized
// from the more type-specific fields of UIResource.
func UIResourceUpToDateCondition(r v1alpha1.UIResourceStatus) v1alpha1.UIResourceCondition {
c := v1alpha1.UIResourceCondition{
Type: v1alpha1.UIResourceUpToDate,
Status: metav1.ConditionUnknown,
LastTransitionTime: apis.NowMicro(),
}

if r.UpdateStatus == v1alpha1.UpdateStatusOK || r.UpdateStatus == v1alpha1.UpdateStatusNotApplicable {
c.Status = metav1.ConditionTrue
return c
}

c.Status = metav1.ConditionFalse
if r.UpdateStatus == v1alpha1.UpdateStatusError {
c.Reason = "UpdateError"
} else if r.UpdateStatus == v1alpha1.UpdateStatusPending {
c.Reason = "UpdatePending"
} else {
c.Reason = "Unknown"
}
return c
}

// TODO(nick): We should build this from the Tiltfile in the apiserver,
// not the Tiltfile state in EngineState.
func TiltfileResource(name model.ManifestName, ms *store.ManifestState, logStore *logstore.LogStore) *v1alpha1.UIResource {
Expand Down Expand Up @@ -372,6 +398,7 @@ func TiltfileResource(name model.ManifestName, ms *store.ManifestState, logStore
}

tr.Status.Conditions = []v1alpha1.UIResourceCondition{
UIResourceUpToDateCondition(tr.Status),
UIResourceReadyCondition(tr.Status),
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/core/v1alpha1/uiresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ type UIResourceConditionType string
// Ready means the UI Resource has built, deployed, and passed any readiness checks.
const UIResourceReady UIResourceConditionType = "Ready"

// UpToDate means that the UI Resource has successfully built and deployed all
// its components. Runtime checks may not be passing yet.
const UIResourceUpToDate UIResourceConditionType = "UpToDate"

type UIResourceCondition struct {
// Type of UI Resource condition.
Type UIResourceConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=UIResourceConditionType"`
Expand Down

0 comments on commit dd065a4

Please sign in to comment.