Skip to content

Conversation

mtbennett-godaddy
Copy link
Contributor

@mtbennett-godaddy mtbennett-godaddy commented Aug 2, 2025

Fixes #17277, #23965.

Every reconciliation performed by our application set controller prints 2 Loading TLS configuration from secret messages per app (and we have hundreds of apps). Tracked it down to the fact that multiple cluster DB methods (GetCluster, specifically in our case) call GetSettings() unconditionally but only end up referencing the settings if the cluster in question is the current k8s cluster (appv1.KubernetesInternalAPIServerAddr).

This updates GetCluster, GetClusterServersByName, and CreateCluster to only call GetSettings if considering the current cluster.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • [ ] I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • [ ] Does this PR require documentation updates?
  • [ ] I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • [ ] My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Copy link

bunnyshell bot commented Aug 2, 2025

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@mtbennett-godaddy mtbennett-godaddy changed the title avoid unnecessary GetSettings calls (fix) avoid unnecessary GetSettings calls Aug 2, 2025
@mtbennett-godaddy mtbennett-godaddy changed the title (fix) avoid unnecessary GetSettings calls fix: avoid unnecessary GetSettings calls Aug 2, 2025
Copy link

codecov bot commented Aug 2, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.26%. Comparing base (03ac864) to head (7c73bd8).
⚠️ Report is 37 commits behind head on master.

Files with missing lines Patch % Lines
util/db/cluster.go 91.42% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #24021      +/-   ##
==========================================
+ Coverage   60.25%   60.26%   +0.01%     
==========================================
  Files         347      347              
  Lines       59354    59366      +12     
==========================================
+ Hits        35761    35775      +14     
+ Misses      20724    20719       -5     
- Partials     2869     2872       +3     

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

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…essary-get-settings

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@mtbennett-godaddy mtbennett-godaddy changed the title fix: avoid unnecessary GetSettings calls fix: avoid unnecessary GetSettings calls (#17277) (#23965) Aug 4, 2025
@mtbennett-godaddy mtbennett-godaddy marked this pull request as ready for review August 4, 2025 07:14
@mtbennett-godaddy mtbennett-godaddy requested a review from a team as a code owner August 4, 2025 07:14
@blakepettersson
Copy link
Member

This generally LGTM, but can we add a test for this?

@mtbennett-godaddy
Copy link
Contributor Author

@blakepettersson I’m not well-versed in Go, especially testing patterns. From what I’ve read, if I wanted to know whether GetSettings was being called during certain flows, I’d need to mock SettingsManager for the tests. But to do that, SettingsManager would need to be an interface. Making that change seems … non-trivial.

Is there a simpler way to count method calls? Or am I off-base on your request?

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…essary-get-settings

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@mtbennett-godaddy
Copy link
Contributor Author

@blakepettersson 892de07 adds an ArgoDBSettingsSource interface that gets mocked by new tests that check whether or not GetSettings is called under the various conditions.

I’m totally open to alternatives if there’s a more project-standard way of doing this.

…essary-get-settings

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…essary-get-settings

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…essary-get-settings

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…essary-get-settings

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@blakepettersson
Copy link
Member

@mtbennett-godaddy I wonder if an approach similar to #22282 wouldn't be preferable, since while your approach works, it means that any other future invocation that doesn't follow your pattern would surface this issue again. If we fix this at its core rather than trying to prevent excessive GetSettings calls we would ensure that this would not be an issue in the future.

@mtbennett-godaddy
Copy link
Contributor Author

@blakepettersson Honestly, my top priority here was to reduce the Loading TLS configuration from secret logging. (We get literally hundreds of those messages every time the app set controller reconciles. It’s just overwhelming noise in the logs.) #22282 doesn’t lessen the frequency of that message. It actually increases it. It would need to be updated to remove the log call in updateSettingsFromSecret in lieu of the one in the cache miss branch.

#22282 seems abandoned? Want me to close this PR and open a new one using #22282’s approach with tests?

@blakepettersson
Copy link
Member

Superseded by #24080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

argocd-server-tls continuously reloaded
2 participants