Skip to content

Commit

Permalink
componentstatus: fix possible panic when setting LastTransitionTime (P…
Browse files Browse the repository at this point in the history
…ROJQUAY-2636)

We need to check if curCond is not nil before we move on and start using
its properties.
  • Loading branch information
ricardomaraschini committed Oct 28, 2021
1 parent 9d338ae commit 186ba04
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions controllers/quay/quayregistry_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ func (q *QuayRegistryStatusReconciler) overwriteConditions(
for _, cond := range conds {
curCond := qv1.GetCondition(reg.Status.Conditions, cond.Type)

// make sure we only update LastTransitionTime if the status has changed.
cond.LastTransitionTime = curCond.LastTransitionTime
if curCond != nil && curCond.Status != cond.Status {
cond.LastTransitionTime = cond.LastUpdateTime
// initially updates last transition time to be last update time but if the
// condition remains the same since we last checked overwrites it with the
// previous last transition time. LastTransitionTime shows the last time the
// status has changed (transition from ok to not ok or vice versa).
cond.LastTransitionTime = cond.LastUpdateTime
if curCond != nil && curCond.Status == cond.Status {
cond.LastTransitionTime = curCond.LastTransitionTime
}

reg.Status.Conditions = qv1.SetCondition(reg.Status.Conditions, cond)
Expand Down

0 comments on commit 186ba04

Please sign in to comment.