Skip to content

Commit

Permalink
Merge pull request #511 from fluxcd/result-finalize-ready-check
Browse files Browse the repository at this point in the history
runtime/reconcile: Fix Ready check in Finalizer
  • Loading branch information
darkowlzz authored Mar 14, 2023
2 parents e1f2cfc + 1e919d4 commit 6805701
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/reconcile/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (rs ResultFinalizer) Finalize(obj conditions.Setter, res ctrl.Result, recEr
// Ready=False with the reconcile error. If Ready is already False with a
// reason, preserve the value.
if recErr != nil {
if conditions.IsUnknown(obj, meta.ReadyCondition) || conditions.IsReady(obj) {
if conditions.IsUnknown(obj, meta.ReadyCondition) || conditions.IsTrue(obj, meta.ReadyCondition) {
conditions.MarkFalse(obj, meta.ReadyCondition, meta.FailedReason, recErr.Error())
}
}
Expand Down
14 changes: 14 additions & 0 deletions runtime/reconcile/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ func TestResultFinalizer(t *testing.T) {
*conditions.TrueCondition(meta.ReconcilingCondition, "SomeReasonX", "some msg X"),
},
},
{
name: "result with error, ready and reconciling, change to not ready",
beforeFunc: func(obj conditions.Setter) {
conditions.MarkReconciling(obj, "SomeReasonX", "some msg X")
conditions.MarkTrue(obj, meta.ReadyCondition, "SomeReasonY", "some msg Y")
},
result: resultFailed,
recErr: errors.New("foo failed"),
wantErr: true,
assertConditions: []metav1.Condition{
*conditions.FalseCondition(meta.ReadyCondition, meta.FailedReason, "foo failed"),
*conditions.TrueCondition(meta.ReconcilingCondition, "SomeReasonX", "some msg X"),
},
},
{
name: "stalled and reconciling, Ready=False, remove reconciling, retain ready",
beforeFunc: func(obj conditions.Setter) {
Expand Down

0 comments on commit 6805701

Please sign in to comment.