-
Notifications
You must be signed in to change notification settings - Fork 362
Fix: Freight should manage its own discoveryTimestamp, not rely on cr… #6133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,10 @@ func (s PromotionStepStatus) Compare(other PromotionStepStatus) int { | |
| type Promotion struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` | ||
| // DiscoveryTimestamp is the time at which the Promotion was created. | ||
| // This is distinct from metadata.creationTimestamp, which is | ||
| // set by Kubernetes and cannot be controlled by users. | ||
| DiscoveryTimestamp *metav1.Time `json:"discoveryTimestamp,omitempty" protobuf:"bytes,4,opt,name=discoveryTimestamp"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as here: https://github.com/akuity/kargo/pull/6133/changes#r3118215938
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call this apiVersion: kargo.akuity.io/v1alpha1
kind: Promotion
metadata:
creationTimestamp: 2026-04-08T15:50:21Z
name: dev.01knpwk5z8ngczawgqctc79w39.efe1b47
status:
startedAt: 2026-04-08T15:40:22Z # <<<<< my preference
finishedAt: 2026-04-08T15:51:10Z
phase: Succeeded
stepExecutionMetadata:
- alias: task-1::step-1
finishedAt: 2026-04-08T15:50:24Z
startedAt: 2026-04-08T15:50:22Z
status: Succeeded
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, unlike Freight, for the promotion object, this needs to be under |
||
| // Spec describes the desired transition of a specific Stage into a specific | ||
| // Freight. | ||
| // | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1721,10 +1721,15 @@ func (r *RegularStageReconciler) autoPromoteFreight( | |||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Find the latest Freight by sorting the available Freight by creation time | ||||||||||||||||||||||||||||||||
| // Find the latest Freight by sorting the available Freight by discovery time | ||||||||||||||||||||||||||||||||
| // in descending order. | ||||||||||||||||||||||||||||||||
| slices.SortFunc(freight, func(lhs, rhs kargoapi.Freight) int { | ||||||||||||||||||||||||||||||||
| return rhs.CreationTimestamp.Compare(lhs.CreationTimestamp.Time) | ||||||||||||||||||||||||||||||||
| lhsTime := lhs.DiscoveryTimestamp | ||||||||||||||||||||||||||||||||
| rhsTime := rhs.DiscoveryTimestamp | ||||||||||||||||||||||||||||||||
| if lhsTime == nil || rhsTime == nil { | ||||||||||||||||||||||||||||||||
| return rhs.CreationTimestamp.Compare(lhs.CreationTimestamp.Time) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return rhsTime.Time.Compare(lhsTime.Time) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+1727
to
+1732
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was really smart to fall back on I might suggest a small improvement though. Instead of falling back on CreationTimestamp for both when either doesn't have a
Suggested change
|
||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| latestFreight := freight[0] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -1811,11 +1816,16 @@ func (r *RegularStageReconciler) autoPromoteFreight( | |||||||||||||||||||||||||||||||
| latestFreight.Name, stage.Namespace, err, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if len(promotions.Items) > 0 { | ||||||||||||||||||||||||||||||||
| // Sort the terminal Promotions by creation time in descending order | ||||||||||||||||||||||||||||||||
| slices.SortFunc(promotions.Items, func(lhs, rhs kargoapi.Promotion) int { | ||||||||||||||||||||||||||||||||
| if len(promotions.Items) > 0 { | ||||||||||||||||||||||||||||||||
| // Sort the terminal Promotions by discovery time in descending order | ||||||||||||||||||||||||||||||||
| slices.SortFunc(promotions.Items, func(lhs, rhs kargoapi.Promotion) int { | ||||||||||||||||||||||||||||||||
| lhsTime := lhs.DiscoveryTimestamp | ||||||||||||||||||||||||||||||||
| rhsTime := rhs.DiscoveryTimestamp | ||||||||||||||||||||||||||||||||
| if lhsTime == nil || rhsTime == nil { | ||||||||||||||||||||||||||||||||
| return rhs.CreationTimestamp.Compare(lhs.CreationTimestamp.Time) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return rhsTime.Time.Compare(lhsTime.Time) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+1820
to
+1827
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as here: https://github.com/akuity/kargo/pull/6133/changes#r3118278060 I start to wonder whether we should include a generic |
||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| newestPromotion := promotions.Items[0] | ||||||||||||||||||||||||||||||||
| if newestPromotion.Status.Phase != kargoapi.PromotionPhaseSucceeded { | ||||||||||||||||||||||||||||||||
| freightLogger.Debug( | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/oklog/ulid/v2" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
@@ -82,6 +83,7 @@ func (b *PromotionBuilder) Build( | |
| Namespace: stage.Namespace, | ||
| Annotations: annotations, | ||
| }, | ||
| DiscoveryTimestamp: &metav1.Time{Time: time.Now()}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since I'm asking for StartedAt timestamp to be a |
||
| Spec: kargoapi.PromotionSpec{ | ||
| Stage: stage.Name, | ||
| Freight: freight, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,7 +292,12 @@ func sortFreightSlice(orderBy string, reverse bool, freight []*kargoapi.Freight) | |
| return strings.Compare(lhsTag, rhsTag) | ||
| } | ||
| } | ||
| return lhs.CreationTimestamp.Compare(rhs.CreationTimestamp.Time) | ||
| lhsTime := lhs.DiscoveryTimestamp | ||
| rhsTime := rhs.DiscoveryTimestamp | ||
| if lhsTime == nil || rhsTime == nil { | ||
| return lhs.CreationTimestamp.Time.Compare(rhs.CreationTimestamp.Time) | ||
| } | ||
| return rhsTime.Time.Compare(lhsTime.Time) | ||
|
Comment on lines
+295
to
+300
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as here: https://github.com/akuity/kargo/pull/6133/changes#r3118302803 Another point in favor of a generic helper. |
||
| }) | ||
| if reverse { | ||
| slices.Reverse(freight) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears codegen wasn't run after this change. Among many other things, codegen will also set the
protobufstruct tag for you (making it harder to get wrong).I would suggest this change:
When you run codegen (
make hack-codegen), which you will need to do for reasons other than just this, it will probably put it back to exactly as you had it here, but it may do something slightly different. Better safe than sorry.