Skip to content

Conversation

mtbennett-godaddy
Copy link
Contributor

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

Updates SettingsManager.externalServerTLSCertificate to cache the key parsed from the secret’s cert and to invalidate that cache when the secret is updated. It also moves the Loading TLS configuration from secret log message so that it is only emitted when the cert is parsed (as opposed to every time SettingsManager.GetSettings is called).

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>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Copy link

bunnyshell bot commented Aug 8, 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>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

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

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 93.61702% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.16%. Comparing base (a4919ed) to head (9220f82).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
util/settings/settings.go 93.61% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #24080      +/-   ##
==========================================
+ Coverage   60.15%   60.16%   +0.01%     
==========================================
  Files         348      348              
  Lines       59889    59905      +16     
==========================================
+ Hits        36024    36040      +16     
+ Misses      20980    20975       -5     
- Partials     2885     2890       +5     

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

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

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

@mtbennett-godaddy is there any reason why we couldn't do something like

// externalServerTLSCertificate will try and load a TLS certificate from an
// external secret, instead of tls.crt and tls.key in argocd-secret. If both
// return values are nil, no external secret has been configured.
func (mgr *SettingsManager) externalServerTLSCertificate(existingCert *tls.Certificate) (*tls.Certificate, error) {
	var cert tls.Certificate
	secret, err := mgr.GetSecretByName(externalServerTLSSecretName)
	if err != nil {
		if apierrors.IsNotFound(err) {
			return nil, nil
		}
	}

	if secret.ResourceVersion != mgr.tlsCertCacheSecretVersion || existingCert == nil {
		log.Infof("Loading TLS configuration from secret %s/%s", mgr.namespace, externalServerTLSSecretName)

		tlsCert, certOK := secret.Data[settingServerCertificate]
		tlsKey, keyOK := secret.Data[settingServerPrivateKey]
		if certOK && keyOK {
			cert, err = tls.X509KeyPair(tlsCert, tlsKey)
			if err != nil {
				return nil, err
			}
		}

		mgr.tlsCertCacheSecretVersion = secret.ResourceVersion
		return &cert, nil
	}

	return existingCert, nil
}

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

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

@blakepettersson Commited some refactors before I saw your comment. The refactor adds a loadTLSCertificateFromSecret function that gets called with the external cert and if there’s nothing there, it calls it again with the argocd-secret. The caching logic is in that function so it applies to both cert sources, not just the external one.

However, there are sporadic unit test failures in the GH action runs that I haven’t been able to reproduce locally. Still trying to figure that out.

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@mtbennett-godaddy mtbennett-godaddy marked this pull request as ready for review August 14, 2025 16:26
@mtbennett-godaddy mtbennett-godaddy requested a review from a team as a code owner August 14, 2025 16:26
@mtbennett-godaddy
Copy link
Contributor Author

@blakepettersson Ready for review. I figured out the unit test issue… I was calling invalidateTLSCertCache unnecessarily in the informer event handler, which was being triggered more frequently in the action-run tests than it was locally for some reason.

…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

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

Seems like this should be cherry-picked back to 3.0 and 3.1 (once this PR gets approved and merged)

…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
…nal-tls-cert

Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@blakepettersson blakepettersson merged commit 1c5d7f1 into argoproj:master Aug 25, 2025
28 checks passed
@blakepettersson
Copy link
Member

@mtbennett-godaddy thanks a lot! Do you mind creating cherry-pick PRs for 3.0 and 3.1?

@mtbennett-godaddy mtbennett-godaddy deleted the cache-external-tls-cert branch August 25, 2025 14:40
mtbennett-godaddy added a commit to mtbennett-godaddy/argo-cd that referenced this pull request Aug 26, 2025
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
mtbennett-godaddy added a commit to mtbennett-godaddy/argo-cd that referenced this pull request Aug 26, 2025
Signed-off-by: Matthew Bennett <mtbennett@godaddy.com>
@ivanpedersen
Copy link

ivanpedersen commented Sep 2, 2025

I'm new to the ArgoCD project and don't really understand the release process. Has this been released? @blakepettersson

@crenshaw-dev
Copy link
Member

crenshaw-dev commented Sep 2, 2025

@ivanpedersen we haven't cherry-picked this back, so it'll go out in 3.2.0-rc1 which is released in ~2 weeks.

We have cherry-picked and released #24235, which I'm hoping will sufficiently mitigate the logs and performance issues.

Mangaal pushed a commit to Mangaal/argo-cd that referenced this pull request Sep 10, 2025
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.

Excessive logging of loading external server TLS certificate argocd-server-tls continuously reloaded
4 participants