Skip to content

Commit

Permalink
Bug 1768255: replace Fraction with Done and Total
Browse files Browse the repository at this point in the history
Make Done and Total available to syncStatus and calculate percent
complete locally.
  • Loading branch information
jottofar committed Jan 15, 2021
1 parent a8d4d53 commit b9ad6de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
12 changes: 8 additions & 4 deletions pkg/cvo/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"time"

"k8s.io/klog/v2"
Expand Down Expand Up @@ -296,14 +297,17 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
})
} else {
var message string
percentComplete := float32(status.Done) / float32(status.Total)
switch {
case len(validationErrs) > 0:
message = fmt.Sprintf("Reconciling %s: the cluster version is invalid", version)
case status.Fraction > 0 && skipFailure:
case percentComplete > 0 && skipFailure:
reason = progressReason
message = fmt.Sprintf("Working towards %s: %.0f%% complete, %s", version, status.Fraction*100, progressShortMessage)
case status.Fraction > 0:
message = fmt.Sprintf("Working towards %s: %.0f%% complete", version, status.Fraction*100)
message = fmt.Sprintf("Working towards %s: %d of %d done (%.0f%% complete), %s", version,
status.Done, status.Total, math.Trunc(float64(percentComplete*100)), progressShortMessage)
case percentComplete > 0:
message = fmt.Sprintf("Working towards %s: %d of %d done (%.0f%% complete)", version,
status.Done, status.Total, math.Trunc(float64(percentComplete*100)))
case status.Step == "RetrievePayload":
if len(reason) == 0 {
reason = "DownloadingUpdate"
Expand Down
21 changes: 14 additions & 7 deletions pkg/cvo/sync_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ type SyncWorkerStatus struct {
Step string
Failure error

Fraction float32
Done int
Total int

Completed int
Reconciling bool
Expand Down Expand Up @@ -374,15 +375,17 @@ type statusWrapper struct {

func (w *statusWrapper) Report(status SyncWorkerStatus) {
p := w.previousStatus
percentComplete := float32(status.Done) / float32(status.Total)
previousPercentComplete := float32(p.Done) / float32(p.Total)
if p.Failure != nil && status.Failure == nil {
if p.Actual.Image == status.Actual.Image {
if status.Fraction < p.Fraction {
if percentComplete < previousPercentComplete {
klog.V(5).Infof("Dropping status report from earlier in sync loop")
return
}
}
}
if status.Fraction > p.Fraction || status.Completed > p.Completed || (status.Failure == nil && status.Actual.Image != p.Actual.Image) {
if percentComplete > previousPercentComplete || status.Completed > p.Completed || (status.Failure == nil && status.Actual.Image != p.Actual.Image) {
status.LastProgress = time.Now()
}
if status.Generation == 0 {
Expand Down Expand Up @@ -802,7 +805,8 @@ func (r *consistentReporter) Update() {
metricPayload.WithLabelValues(r.version, "applied").Set(float64(r.done))
copied := r.status
copied.Step = "ApplyResources"
copied.Fraction = float32(r.done) / float32(r.total)
copied.Done = r.done
copied.Total = r.total
r.reporter.Report(copied)
}

Expand All @@ -811,7 +815,8 @@ func (r *consistentReporter) Error(err error) {
defer r.lock.Unlock()
copied := r.status
copied.Step = "ApplyResources"
copied.Fraction = float32(r.done) / float32(r.total)
copied.Done = r.done
copied.Total = r.total
if !isContextError(err) {
copied.Failure = err
}
Expand All @@ -825,7 +830,8 @@ func (r *consistentReporter) Errors(errs []error) error {
defer r.lock.Unlock()
copied := r.status
copied.Step = "ApplyResources"
copied.Fraction = float32(r.done) / float32(r.total)
copied.Done = r.done
copied.Total = r.total
if err != nil {
copied.Failure = err
}
Expand All @@ -848,7 +854,8 @@ func (r *consistentReporter) Complete() {
copied.Completed = r.completed + 1
copied.Initial = false
copied.Reconciling = true
copied.Fraction = 1
copied.Done = r.done
copied.Total = r.total
r.reporter.Report(copied)
}

Expand Down

0 comments on commit b9ad6de

Please sign in to comment.