Skip to content

Commit

Permalink
chore: simplify timestamp comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco authored and krancour committed Jun 18, 2024
1 parent 9a37d30 commit 145e303
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions internal/controller/stages/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,15 +884,10 @@ func (r *reconciler) syncNormalStage(
return status, nil
}

// Find the latest Freight
// Find the latest Freight by sorting the available Freight by creation time
// in descending order.
slices.SortFunc(availableFreight, func(lhs, rhs kargoapi.Freight) int {
if lhs.CreationTimestamp.Time.Before(rhs.CreationTimestamp.Time) {
return 1
}
if lhs.CreationTimestamp.Time.After(rhs.CreationTimestamp.Time) {
return -1
}
return 0
return rhs.CreationTimestamp.Time.Compare(lhs.CreationTimestamp.Time)
})

Check warning on line 891 in internal/controller/stages/stages.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/stages/stages.go#L890-L891

Added lines #L890 - L891 were not covered by tests
latestFreight := availableFreight[0]

Expand Down

0 comments on commit 145e303

Please sign in to comment.