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

chore(refactor): remove app destination inferrence logic #21189

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

crenshaw-dev
Copy link
Member

@crenshaw-dev crenshaw-dev commented Dec 16, 2024

The utils.ValidateDestination function has the side-effect of setting the app destination's server URL if it is not present.

This side effect makes the code hard to read and has introduced subtle bugs and race conditions.

This PR is an attempt to remove the side effect and instead have the code load in the cluster details whenever they're needed. It may result in more network calls, so we need to be aware of performance. We also need to look out for places that still assume the old side-effect behavior and fix them to explicitly pull the cluster details instead.

The code is called in five places in the app controller:

  • in finalizeApplicationDeletion; since not all code paths in processAppOperationQueueItem require a destCluster, we delegate that to finalizeApplicationDeletion when an app deletion is in progress
  • in processRequestedAppOperation, which is another code path accessible from processAppOperationQueueItem; we call it as late as possible, and we need it in order to call SyncAppState; there are some error paths in SyncAppState which don't require destCluster, but I think they'll be relatively rare
  • in processAppRefreshQueueItem; here again there are a few code paths which could potentially short-circuit the need to get the cluster, but the most common paths require it
  • in canProcessApp, which is called in 5 places; I'd much rather avoid this work for most of those cases, but that requires a bigger refactor
  • in the app informer's namespace index key generation function; this is another place that call doesn't belong, but it's a bigger refactor

Copy link

bunnyshell bot commented Dec 16, 2024

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@crenshaw-dev crenshaw-dev changed the title refactor: remove app destination inferrence logic chore(refactor): remove app destination inferrence logic Dec 16, 2024
Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 66.33663% with 68 lines in your changes missing coverage. Please review.

Project coverage is 55.24%. Comparing base (947a7b8) to head (efd74ee).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
controller/state.go 50.00% 6 Missing and 3 partials ⚠️
server/application/application.go 50.00% 5 Missing and 4 partials ⚠️
cmd/argocd/commands/admin/cluster.go 27.27% 7 Missing and 1 partial ⚠️
controller/appcontroller.go 85.36% 3 Missing and 3 partials ⚠️
controller/cache/cache.go 71.42% 5 Missing and 1 partial ⚠️
server/project/project.go 33.33% 5 Missing and 1 partial ⚠️
util/argo/argo.go 83.33% 4 Missing and 2 partials ⚠️
controller/sync.go 58.33% 4 Missing and 1 partial ⚠️
cmd/argocd/commands/admin/app.go 50.00% 3 Missing and 1 partial ⚠️
pkg/apis/application/v1alpha1/app_project_types.go 66.66% 2 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21189      +/-   ##
==========================================
+ Coverage   55.21%   55.24%   +0.03%     
==========================================
  Files         337      337              
  Lines       56945    56843     -102     
==========================================
- Hits        31441    31405      -36     
+ Misses      22828    22756      -72     
- Partials     2676     2682       +6     

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

Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Copy link
Member Author

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Note to self: there are probably a lot of code paths where we just need the destServerURL, not the whole Cluster object. Consider simplifying those code paths.

Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

LGTM. Minor comments. Other people should review this I think because the potential side-effects are extremely hard to spot! Hopefully, we have enough unit test :)

@@ -437,7 +442,7 @@ func reconcileApplications(
sources = append(sources, app.Spec.GetSource())
revisions = append(revisions, app.Spec.GetSource().TargetRevision)

res, err := appStateManager.CompareAppState(&app, proj, revisions, sources, false, false, nil, false, false)
res, err := appStateManager.CompareAppState(destCluster, &app, proj, revisions, sources, false, false, nil, false, false)
Copy link
Member

@agaudreault agaudreault Dec 20, 2024

Choose a reason for hiding this comment

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

I feel like it would be better to do the inference again in CompareAppState instead of adding a parameter here. Or maybe have a private property with an accessor in the app destination object?

Copy link
Member

Choose a reason for hiding this comment

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

As discussed, this is a refactor and can be improved further in another PR. No blocker.

@crenshaw-dev crenshaw-dev marked this pull request as ready for review January 6, 2025 19:45
@crenshaw-dev crenshaw-dev requested a review from a team as a code owner January 6, 2025 19:45
Copy link
Collaborator

@leoluz leoluz left a comment

Choose a reason for hiding this comment

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

From the description this seems to be a breaking change. Can you please confirm?

@crenshaw-dev
Copy link
Member Author

@leoluz not breaking, behavior should be 100% identical from a user's perspective.

Comment on lines +957 to 959
if destination.Name != "" && destination.Server != "" {
return nil, fmt.Errorf("application destination can't have both name and server defined: %s %s", destination.Name, destination.Server)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this constraint existing at the CRD level today? I suspect that nothing fails today if both fields are present. Can you please confirm?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not exactly at the CRD level, but it is currently enforced at runtime: https://github.com/argoproj/argo-cd/pull/21189/files#diff-87b3b573e8c40af95af4dbda83f7dbc467219b02182415ff8e1f0ad73a82dc59L518

I tested locally in 2.14.0-rc5. If I set both fields, the app goes into an Unknown state with an error application destination can't have both name and server defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for final review
Development

Successfully merging this pull request may close these issues.

4 participants