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

feat: add actor metadata to Promotion context #3592

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

keithfz
Copy link

@keithfz keithfz commented Mar 2, 2025

As a prerequisite to adopting Kargo, we want to be able to include information about the user triggering the promotion in our promotion templates. Specifically so the authenticated user triggering a promotion is tracked in the Git history of our GitOps repo.

To implement this, I followed the same pattern & logic used by the Created By column in the frontend where we parse the kargo.akuity.io/create-actor annotation. If it doesn't exist, we return N/A. This gets added to the promotion context, and can then be exposed in an expression.

title: 'Created By',
render: (_, promotion) => {
const annotation = promotion.metadata?.annotations['kargo.akuity.io/create-actor'];
const email = annotation ? annotation.split(':')[1] : 'N/A';
return email || annotation;

For our use case around auditability in the commit history, this suffices.

Relates to issue: #3081

@keithfz keithfz requested review from a team as code owners March 2, 2025 05:35
Copy link

netlify bot commented Mar 2, 2025

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit 5fac7f4
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-io/deploys/67cef8c16987270008131ef1
😎 Deploy Preview https://deploy-preview-3592.docs.kargo.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hiddeco hiddeco self-requested a review March 3, 2025 11:56
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Project coverage is 52.85%. Comparing base (abea4d1) to head (5fac7f4).

Files with missing lines Patch % Lines
internal/controller/promotions/promotions.go 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3592      +/-   ##
==========================================
+ Coverage   52.82%   52.85%   +0.02%     
==========================================
  Files         299      299              
  Lines       26892    26908      +16     
==========================================
+ Hits        14206    14221      +15     
- Misses      11924    11925       +1     
  Partials      762      762              

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@krancour krancour added this to the v1.4.0 milestone Mar 6, 2025
@hiddeco
Copy link
Contributor

hiddeco commented Mar 10, 2025

Made some changes to facilitate further growth better, and to simplify potential comparison checks people may want to do at some point:

  • Renamed and moved the field from ctx.creator to ctx.meta.promotion.actor.
  • Dropped the N/A in case none is found, this makes it much simpler to do e.g. != "" type of checks.
  • Slightly modified the extraction logic to incorporate a potential admin value that might be set.

@keithfz
Copy link
Author

keithfz commented Mar 10, 2025

Awesome! Changes make sense to me.

Should we also update the docs accordingly for the new path you’ve added?

| `ctx` | `object` | `string` fields `project`, `stage`, `promotion`, and `creator` provide convenient access to details of a `Promotion`. |

@@ -143,7 +143,7 @@ Expect other useful variables to be added in the future.

| Name | Type | Description |
|------|------|-------------|
| `ctx` | `object` | `string` fields `project`, `stage`, and `promotion` provide convenient access to details of a `Promotion`. |
| `ctx` | `object` | `string` fields `project`, `stage`, `promotion`, and `creator` provide convenient access to details of a `Promotion`. |
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update this to new field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this still needs to be updated, but I am struggling to find the best way to address this as we seem to be running into the limitations of using tables.

Signed-off-by: Hidde Beydals <[email protected]>
@hiddeco hiddeco changed the title feat: Add a creator field in the promotion ctx, so it's usable in expressions feat: add actor metadata to Promotion context Mar 10, 2025
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.

3 participants