Skip to content
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

refactor(controller): avoid patching Stage from Promotions reconciler #1919

Merged
merged 12 commits into from
Jun 3, 2024

Conversation

hiddeco
Copy link
Contributor

@hiddeco hiddeco commented May 1, 2024

This pull request changes the way Stages keep track of their current Freight, by removing the patching of the Stage from the Promotion reconciler and replacing it with logic to allow the Stage itself to self-determine what its current Freight is based on the Promotions existing for it.

From a bird's-eye view, it performs the following steps during the reconciliation of a Stage:

  1. Retrieve all Promotions associated with the Stage.
  2. Arrange them according to specific criteria:
    • Prioritize Running promotions, further sorted by their ULID in ascending order.
    • Next consider other non-terminal promotions, further sorted by their ULID in ascending order.
    • Finally, consider terminal promotions, sorted by their ULID in descending order.
  3. Check if the first Promotion in the ordered list is non-terminal. If so, it signifies that the Stage is in a Promoting phase, and the CurrentPromotion must reflect this. If not, CurrentPromotion remains empty, indicating that the Stage is in a Steady phase.
  4. Identify any newly terminated Promotions since the last reconciliation by comparing their ULID with the LastPromotion information of the Stage. If created after LastPromotion, they are considered new.
  5. Proceed through the list of newly terminated Promotions from oldest to newest. Update the LastPromotion information for the Stage accordingly. If the Promotion was successful, update the Freight history and CurrentFreight for the Stage to reflect this Promotion.

In addition to this:

  • The logic around when the Stage is marked as Verifying has changed. This is now set at the point where the reconciler notices the CurrentFreight does not have any VerificationInfo and the current phase is Steady (and not e.g. Promoting).
  • The health checks for the Stage will run regardless of any phase of the Stage (and there being e.g. a Promotion in a Running phase).

Copy link

netlify bot commented May 1, 2024

Deploy Preview for docs-kargo-akuity-io canceled.

Name Link
🔨 Latest commit 3cdd53c
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-akuity-io/deploys/665e2d9712a8a00008331434

@hiddeco hiddeco force-pushed the sync-promos-for-stage branch 3 times, most recently from b746183 to 8fbc1c2 Compare May 1, 2024 20:48
Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 82.23684% with 27 lines in your changes missing coverage. Please review.

Project coverage is 45.90%. Comparing base (afdc0dd) to head (3cdd53c).
Report is 1 commits behind head on main.

Files Patch % Lines
internal/controller/promotions/promotions.go 0.00% 12 Missing ⚠️
internal/controller/stages/stages.go 92.66% 7 Missing and 1 partial ⚠️
internal/kargo/kargo.go 73.07% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1919      +/-   ##
==========================================
+ Coverage   45.61%   45.90%   +0.29%     
==========================================
  Files         238      238              
  Lines       16477    16545      +68     
==========================================
+ Hits         7516     7595      +79     
+ Misses       8590     8578      -12     
- Partials      371      372       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hiddeco hiddeco force-pushed the sync-promos-for-stage branch 2 times, most recently from 4f61ba6 to ff63007 Compare May 2, 2024 11:21
@hiddeco hiddeco marked this pull request as ready for review May 2, 2024 12:08
@hiddeco hiddeco requested a review from a team as a code owner May 2, 2024 12:08
@hiddeco hiddeco force-pushed the sync-promos-for-stage branch 8 times, most recently from 682a803 to 121cf8e Compare May 3, 2024 12:15
@hiddeco hiddeco force-pushed the sync-promos-for-stage branch 2 times, most recently from 8599114 to 121cf8e Compare June 3, 2024 19:57
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
- Steady phase is now determined by the synchronization of Promotions.
- Cache can no longer be stale, as we now determine and update this bit
  ourselves.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This avoids a pre-mature reset of the phase when it is actually e.g.
verifying.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
Without this, subsequent actions on e.g. the verification history in the
same reconciliation run would end up being set in
`status.lastPromotion`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This addresses an issue when multiple Promotions are (automatically)
generated in a small timeframe. Which causes their `creationTimestamp`
to equal, as it does not include nanoseconds.

As the generated Promotion name does include this, use this to
lexicographically order them.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
Assuming a scenario where Freight would be "repromoted" (i.e. A -> B ->
C -> A), the history would not accurately reflect this as "A" would
already be on the stack.

To address this, push any newly promoted Freight to the top of the
stack (instead of potentially updating it).

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This reverts the relying on a timestamp in the Status, in favor of
simply lexicographically ordering the Promotion names.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This prevents an AnalysisRun from being created if there are still
pending Promotions in the queue.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
@krancour
Copy link
Member

krancour commented Jun 3, 2024

@hiddeco do you think we should remove the now-unused PromoWentTerminal predicate?

@hiddeco
Copy link
Contributor Author

hiddeco commented Jun 3, 2024

It is still being used by the queue for Promotions itself.

@krancour
Copy link
Member

krancour commented Jun 3, 2024

It is still being used by the queue for Promotions itself.

Ah. I see it now. 👍

@hiddeco hiddeco added this pull request to the merge queue Jun 3, 2024
Merged via the queue into akuity:main with commit 1acb9f2 Jun 3, 2024
16 checks passed
@hiddeco hiddeco deleted the sync-promos-for-stage branch June 3, 2024 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants