Skip to content

Commit

Permalink
api: set uiresource conditions / update,runtime status when disabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
landism authored Feb 24, 2022
1 parent 248a226 commit 091667e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/hud/webview/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ func UIResourceReadyCondition(r v1alpha1.UIResourceStatus) v1alpha1.UIResourceCo
}

c.Status = metav1.ConditionFalse
if r.RuntimeStatus == v1alpha1.RuntimeStatusError {
if r.DisableStatus.State == v1alpha1.DisableStateDisabled {
c.Reason = "Disabled"
} else if r.RuntimeStatus == v1alpha1.RuntimeStatusError {
c.Reason = "RuntimeError"
} else if r.UpdateStatus == v1alpha1.UpdateStatusError {
c.Reason = "UpdateError"
Expand Down Expand Up @@ -339,7 +341,9 @@ func UIResourceUpToDateCondition(r v1alpha1.UIResourceStatus) v1alpha1.UIResourc
}

c.Status = metav1.ConditionFalse
if r.UpdateStatus == v1alpha1.UpdateStatusError {
if r.DisableStatus.State == v1alpha1.DisableStateDisabled {
c.Reason = "Disabled"
} else if r.UpdateStatus == v1alpha1.UpdateStatusError {
c.Reason = "UpdateError"
} else if r.UpdateStatus == v1alpha1.UpdateStatusPending {
c.Reason = "UpdatePending"
Expand Down Expand Up @@ -391,6 +395,11 @@ func populateResourceInfoView(mt *store.ManifestTarget, r *v1alpha1.UIResource)
r.Status.UpdateStatus = mt.UpdateStatus()
r.Status.RuntimeStatus = mt.RuntimeStatus()

if r.Status.DisableStatus.State == v1alpha1.DisableStateDisabled {
r.Status.UpdateStatus = v1alpha1.UpdateStatusNone
r.Status.RuntimeStatus = v1alpha1.RuntimeStatusNone
}

if mt.Manifest.IsLocal() {
lState := mt.State.LocalRuntimeState()
r.Status.LocalResourceInfo = &v1alpha1.UIResourceLocal{PID: int64(lState.PID)}
Expand Down
47 changes: 47 additions & 0 deletions internal/hud/webview/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,44 @@ func TestReadinessCheckFailing(t *testing.T) {
require.Equal(t, "False", string(readyCondition(rv).Status))
}

func TestRuntimeErrorAndDisabled(t *testing.T) {
m := model.Manifest{
Name: "foo",
}.WithDeployTarget(model.K8sTarget{})
state := newState([]model.Manifest{m})
mt := state.ManifestTargets[m.Name]
mt.State.RuntimeState = store.NewK8sRuntimeStateWithPods(m, v1alpha1.Pod{
Name: "pod-id",
Status: "Error",
Phase: string(v1.PodFailed),
Containers: []v1alpha1.Container{
{
Ready: false,
},
},
})

state.ConfigMaps["foo-disable"] = &v1alpha1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "disabled"}, Data: map[string]string{"isDisabled": "true"}}
disableSources := map[string][]v1alpha1.DisableSource{
"foo": {
{ConfigMap: &v1alpha1.ConfigMapDisableSource{Name: "foo-disable", Key: "isDisabled"}},
},
}
uiResources, err := ToUIResourceList(*state, disableSources)
require.NoError(t, err)
require.Equal(t, m.Name.String(), uiResources[1].Name)

rv := uiResources[1].Status
rc := readyCondition(rv)
require.Equal(t, "False", string(rc.Status))
require.Equal(t, "Disabled", rc.Reason)
uc := upToDateCondition(rv)
require.Equal(t, "False", string(uc.Status))
require.Equal(t, "Disabled", uc.Reason)
require.Equal(t, v1alpha1.RuntimeStatusNone, rv.RuntimeStatus)
require.Equal(t, v1alpha1.UpdateStatusNone, rv.UpdateStatus)
}

func TestLocalResource(t *testing.T) {
cmd := model.Cmd{
Argv: []string{"make", "test"},
Expand Down Expand Up @@ -513,3 +551,12 @@ func readyCondition(rs v1alpha1.UIResourceStatus) *v1alpha1.UIResourceCondition
}
return nil
}

func upToDateCondition(rs v1alpha1.UIResourceStatus) *v1alpha1.UIResourceCondition {
for _, c := range rs.Conditions {
if c.Type == v1alpha1.UIResourceUpToDate {
return &c
}
}
return nil
}

0 comments on commit 091667e

Please sign in to comment.