diff --git a/internal/pkg/agent/application/upgrade/details/details.go b/internal/pkg/agent/application/upgrade/details/details.go index a4cb9954d4b..5bc1e409cad 100644 --- a/internal/pkg/agent/application/upgrade/details/details.go +++ b/internal/pkg/agent/application/upgrade/details/details.go @@ -73,6 +73,15 @@ func (d *Details) SetState(s State) { defer d.mu.Unlock() d.State = s + + // If State is something other than StateFailed, make sure to clear + // Metadata.FailedState and Metadata.ErrorMsg as those two fields + // should be set when State is set to StateFailed. See the Fail method. + if s != StateFailed { + d.Metadata.ErrorMsg = "" + d.Metadata.FailedState = "" + } + d.notifyObservers() } diff --git a/internal/pkg/agent/application/upgrade/details/details_test.go b/internal/pkg/agent/application/upgrade/details/details_test.go index 303d071e6b1..670b40705de 100644 --- a/internal/pkg/agent/application/upgrade/details/details_test.go +++ b/internal/pkg/agent/application/upgrade/details/details_test.go @@ -38,6 +38,12 @@ func TestDetailsFail(t *testing.T) { require.Equal(t, StateFailed, det.State) require.Equal(t, StateRequested, det.Metadata.FailedState) require.Equal(t, err.Error(), det.Metadata.ErrorMsg) + + // Check that resetting state to something other than StateFailed + // clears Metadata.FailedState and Metadata.ErrorMsg + det.SetState(StateDownloading) + require.Equal(t, State(""), det.Metadata.FailedState) + require.Equal(t, "", det.Metadata.ErrorMsg) } func TestDetailsObserver(t *testing.T) {