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 argocd application info to promotion event #2789

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

hanxiaop
Copy link
Contributor

This PR adds the applications updated during promotion to the event, so we can get the related application info. Also, I’ve moved NewPromotionEventAnnotations from the api directory to internal/api since it’s only used in internal packages, to avoid cyclic imports.

The sample results will be something like:

...
 metadata:
    annotations:
      event.kargo.akuity.io/actor: admin
      event.kargo.akuity.io/applications: '[{"name":"kargo-demo-test"}]'
      event.kargo.akuity.io/freight-alias: billowing-shark
...

@hanxiaop hanxiaop requested a review from a team as a code owner October 21, 2024 05:53
Copy link

netlify bot commented Oct 21, 2024

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit a9e29fb
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-io/deploys/6720d95fa1d5cc00083e6b41
😎 Deploy Preview https://deploy-preview-2789.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.

@@ -0,0 +1,101 @@
package api
Copy link
Contributor

Choose a reason for hiding this comment

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

any specific reason to move this code from the v1alpha1/event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two main reasons:

  1. The function is only used in internal packages.
  2. If I keep it in the original directory, importing ArgoCDUpdateConfig from the internal package will cause import cycle not allowed, as the v1alpha1/ package is also imported in the internal package.

Copy link
Member

Choose a reason for hiding this comment

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

I understand the import cycle you're trying to avoid, but I don't think this package is a good home for this. (idk if its old home was any better, tbh.)

"API" is overloaded. I wish this package had been named apiserver instead, as this package is all API server endpoints, interceptors, etc. and this functionality you're moving to here is used much more broadly -- by the controller, by the webhooks, etc.

Is it possible this might be better off living in the existing event package (e.g. Live alongside things like func NewRecorder())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@krancour I tried placing it in the existing event package, but realized it is better for k8s event type. Since I couldn’t find a better location, I’ve refactored some files into internal folders in #2808. PTAL if this makes sense. Thank you!

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 72.85714% with 19 lines in your changes missing coverage. Please review.

Project coverage is 50.16%. Comparing base (cf12780) to head (a9e29fb).
Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
internal/event/promotion.go 74.24% 7 Missing and 10 partials ⚠️
internal/controller/promotions/promotions.go 0.00% 1 Missing ⚠️
internal/controller/stages/stages.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2789      +/-   ##
==========================================
+ Coverage   48.83%   50.16%   +1.33%     
==========================================
  Files         270      275       +5     
  Lines       23932    24410     +478     
==========================================
+ Hits        11687    12246     +559     
+ Misses      11616    11504     -112     
- Partials      629      660      +31     

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

@gdsoumya gdsoumya requested review from krancour and hiddeco October 21, 2024 06:10
Signed-off-by: xiaopeng <hanxiaop8@outlook.com>
if step.Uses != "argocd-update" || step.Config == nil {
continue
}
var cfg directives.ArgoCDUpdateConfig
Copy link
Member

Choose a reason for hiding this comment

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

We're trying really hard to make built-in directives "not special." Ideally, the rest of Kargo would have as little awareness of their internals as it will eventually have of the internals of third-party directives.

That being said, I understand this might seem like the only practical way to get the information you're trying to include in the events. This, unfortunately, wouldn't be the first spot where we compromised on this ideal because it seemed like the only way to get something done.

Ultimately, I think this ties into a much broader question of how coupled do we want to be or not want to be to Argo CD. Implementation details aside, just including this information in the Promotion event to begin with says something about Kargo's relationship to Argo CD being special in some way. I think this may be a question for @jessesuen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're trying really hard to make built-in directives "not special." Ideally, the rest of Kargo would have as little awareness of their internals as it will eventually have of the internals of third-party directives.

The intention of maintaining flexibility and avoiding any special logics for built-in and third-party directives makes sense to me. However I'm still a bit unclear about the design here. From my perspective, this little awareness is from code level instead of user level. Users still see the results the directives processed, but developers are limited to access the output of runners they have written.

Ultimately, I think this ties into a much broader question of how coupled do we want to be or not want to be to Argo CD. Implementation details aside, just including this information in the Promotion event to begin with says something about Kargo's relationship to Argo CD being special in some way.

I would also like to know the idea behind #2545. As a Kargo newbie, when I saw the argocd-update step inPromotion resource, I would expect there are some ArgoCD integrations with Kargo. Otherwise it seems we might not need this directive from the lower-level implementations. Seems like this can also be related to how we can integrate with projects that manage workloads?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel this new location is making things worse, as it now mixes simple Kubernetes implementations with our API-specific code. IMHO, the better option is/was internal/event. But before you make this change @hanxiaop, I would like @krancour to agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hiddeco I tried to move the entire api/v1alpha1/event.go file and kubernetes events related files to internal/event in #2808. However as you can see, this would require moving multiple files since some helpers rely on functions within that file. Moving just one function to internal/event doesn’t seem to make much sense. I’d also like to wait for consensus on the best location for this function.

Signed-off-by: xiaopeng <hanxiaop8@outlook.com>

// NewPromotionEventAnnotations returns annotations for a Promotion related event.
// It may skip some fields when error occurred during serialization, to record event with best-effort.
func NewPromotionEventAnnotations(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this to internal/event/promotion.go.

Copy link
Contributor

Choose a reason for hiding this comment

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

Plus maybe rename it to NewPromotionAnnotations, as event already should be enough to indicate it's about events.

Copy link
Contributor

Choose a reason for hiding this comment

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

Additional candidate to be moved from the public API package is FormatEventUserActor (-> FormatUserActor).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hiddeco Thank you for the suggestion! I've moved this function to internal/event/promotion.go.

Additional candidate to be moved from the public API package is FormatEventUserActor (-> FormatUserActor).

I've tried this but it still caused the import cycle issue like:

0.602   imports github.com/akuity/kargo/api/v1alpha1
0.602   imports github.com/akuity/kargo/internal/event
0.602   imports github.com/akuity/kargo/api/v1alpha1: import cycle not allowed

I think we could only move NewPromotionAnnotations here for minimal changes. We can discuss further improvements if necessary and I'd be very happy to contribute more.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair.

@hanxiaop hanxiaop requested a review from krancour October 29, 2024 10:44
Signed-off-by: xiaopeng <hanxiaop8@outlook.com>
@krancour krancour added this pull request to the merge queue Oct 29, 2024
Merged via the queue into akuity:main with commit f9afcdb Oct 29, 2024
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.

4 participants