Skip to content

Commit

Permalink
Revert "Consolidate and only use findAndSetLatestReadyRevision"
Browse files Browse the repository at this point in the history
This reverts commit 7ca7fb3.
  • Loading branch information
Tara Gu committed Oct 31, 2019
1 parent c358a16 commit 28f613e
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pkg/reconciler/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,37 @@ func (c *Reconciler) reconcile(ctx context.Context, config *v1alpha1.Configurati
default:
return fmt.Errorf("unrecognized condition status: %v on revision %q", rc.Status, revName)
}

lcrReady := rc != nil && rc.Status == corev1.ConditionTrue
if err = c.findAndSetLatestReadyRevision(config, lcrReady); err != nil {
return fmt.Errorf("failed to find and set latest ready revision: %w", err)
if rc != nil && rc.Status == corev1.ConditionTrue {
old, new := config.Status.LatestReadyRevisionName, lcr.Name
config.Status.SetLatestReadyRevisionName(lcr.Name)
if old != new {
c.Recorder.Eventf(config, corev1.EventTypeNormal, "LatestReadyUpdate",
"LatestReadyRevisionName updated to %q", new)
}
} else {
if err = c.findAndSetLatestReadyRevision(config); err != nil {
return fmt.Errorf("failed to find and set latest ready revision: %w", err)
}
}

return nil
}

// findAndSetLatestReadyRevision finds the last ready revision and sets LatestReadyRevisionName to it.
// lcrReady indicates whether the latest created revision is ready or not.
func (c *Reconciler) findAndSetLatestReadyRevision(config *v1alpha1.Configuration, lcrReady bool) error {
// findAndSetLatestReadyRevision finds the last ready revision and sets LatestReadyRevisionName to it
func (c *Reconciler) findAndSetLatestReadyRevision(config *v1alpha1.Configuration) error {
sortedRevisions, err := c.getSortedCreatedRevisions(config)
if err != nil {
return err
}
for _, rev := range sortedRevisions {
if rev.Status.IsReady() {
// No need to update latest ready revision in this case
if rev.Name == config.Status.LatestReadyRevisionName && !lcrReady {
if rev.Name == config.Status.LatestReadyRevisionName {
return nil
}
old, new := config.Status.LatestReadyRevisionName, rev.Name
config.Status.SetLatestReadyRevisionName(rev.Name)
if old != new {
c.Recorder.Eventf(config, corev1.EventTypeNormal, "LatestReadyUpdate",
"LatestReadyRevisionName updated to %q", rev.Name)
}
c.Recorder.Eventf(config, corev1.EventTypeNormal, "LatestReadyUpdate",
"LatestReadyRevisionName updated to %q", rev.Name)
return nil
}
}
Expand Down

0 comments on commit 28f613e

Please sign in to comment.