Skip to content

Commit

Permalink
fix: Fix typo. Consolidate update condition clause
Browse files Browse the repository at this point in the history
  • Loading branch information
aDisplayName authored Aug 28, 2024
1 parent 57686b2 commit cb35fab
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions internal/controller/kuik/cachedimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,11 @@ func (r *CachedImageReconciler) cacheImage(cachedImage *kuikv1alpha1.CachedImage
lastWriteComplete := int64(0)
onUpdated := func(update v1.Update) {
needUpdate := false

Check failure on line 350 in internal/controller/kuik/cachedimage_controller.go

View workflow job for this annotation

GitHub Actions / Unit Testing (1.26)

needUpdate declared and not used

Check failure on line 350 in internal/controller/kuik/cachedimage_controller.go

View workflow job for this annotation

GitHub Actions / Unit Testing (1.27)

needUpdate declared and not used

Check failure on line 350 in internal/controller/kuik/cachedimage_controller.go

View workflow job for this annotation

GitHub Actions / Unit Testing (1.25)

needUpdate declared and not used

Check failure on line 350 in internal/controller/kuik/cachedimage_controller.go

View workflow job for this annotation

GitHub Actions / Unit Testing (1.24)

needUpdate declared and not used

Check failure on line 350 in internal/controller/kuik/cachedimage_controller.go

View workflow job for this annotation

GitHub Actions / Unit Testing (1.28)

needUpdate declared and not used
if lastWriteComplete != update.Complete && update.Complete == update.Total {
// Update is needed whenever the writing complmetes.
needUpdate = true
}

isCompleted := lastWriteComplete != update.Complete && update.Complete == update.Total

if time.Since(lastUpdateTime).Seconds() >= 5 {
// Update is needed if last update is more than 5 seconds ago
needUpdate = true
}
if needUpdate {
if time.Since(lastUpdateTime).Seconds() >= 5 || isCompleted {
// Update is needed if last update is more than 5 seconds ago, or the current progress indicates the remote writing has just completed.
updateStatus(r.Client, cachedImage, desc, func(status *kuikv1alpha1.CachedImageStatus) {
cachedImage.Status.Progress.Total = update.Total
cachedImage.Status.Progress.Available = update.Complete
Expand Down

0 comments on commit cb35fab

Please sign in to comment.