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

Merged
merged 6 commits into from
Mar 24, 2025
Merged

Conversation

keithfz
Copy link
Contributor

@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 6f3d98d
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-io/deploys/67e1c6422d93e40008aba26f
😎 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 21.92%. Comparing base (ec8d3f7) to head (6f3d98d).
Report is 1 commits behind head on main.

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   21.90%   21.92%   +0.01%     
==========================================
  Files         312      312              
  Lines       65210    65226      +16     
==========================================
+ Hits        14287    14302      +15     
- Misses      50154    50155       +1     
  Partials      769      769              

☔ 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.

@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
Contributor 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
Contributor 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.

@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
Signed-off-by: Hidde Beydals <[email protected]>
Copy link
Contributor

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

Thank you very much @keithfz 🌷

@hiddeco hiddeco added this pull request to the merge queue Mar 24, 2025
Merged via the queue into akuity:main with commit ee846bb Mar 24, 2025
17 checks passed
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