Skip to content

fix: relogin command ignores --argocd-context flag#26796

Open
AlJohri wants to merge 1 commit intoargoproj:masterfrom
AlJohri:fix/relogin-argocd-context
Open

fix: relogin command ignores --argocd-context flag#26796
AlJohri wants to merge 1 commit intoargoproj:masterfrom
AlJohri:fix/relogin-argocd-context

Conversation

@AlJohri
Copy link

@AlJohri AlJohri commented Mar 11, 2026

Summary

  • argocd relogin --argocd-context <name> uses the current context's server instead of the server from the specified --argocd-context, causing credentials to be sent to the wrong ArgoCD server
  • The root cause is that relogin.go hardcodes localCfg.CurrentContext instead of using clientOpts.Context (the --argocd-context flag value), unlike every other command which correctly passes clientOpts.Context to ResolveContext()
  • Fix: use clientOpts.Context for context resolution (which already falls back to CurrentContext when empty), and use configCtx.Name for the upsert and status message

Test plan

  • Set current context to cluster A (argocd context cluster-a)
  • Run argocd relogin --argocd-context cluster-b --password <cluster-b-password>
  • Verified it succeeds and prints Context 'cluster-b' updated (previously failed with "Invalid username or password" and would have printed Context 'cluster-a' updated)
  • Verify argocd relogin without --argocd-context still works (falls back to current context via ResolveContext(""))

@bunnyshell
Copy link

bunnyshell bot commented Mar 11, 2026

🔴 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

The relogin command hardcoded `localCfg.CurrentContext` instead of using
`clientOpts.Context` (the --argocd-context flag value). This caused it
to connect to the wrong server and update the wrong context entry.

Signed-off-by: Al Johri <al.johri@gmail.com>
@AlJohri AlJohri force-pushed the fix/relogin-argocd-context branch from bd0883c to 98b50b4 Compare March 11, 2026 19:04
@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.89%. Comparing base (4c59c3c) to head (98b50b4).

Files with missing lines Patch % Lines
cmd/argocd/commands/relogin.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #26796   +/-   ##
=======================================
  Coverage   62.89%   62.89%           
=======================================
  Files         414      414           
  Lines       56143    56143           
=======================================
+ Hits        35310    35313    +3     
+ Misses      17480    17476    -4     
- Partials     3353     3354    +1     

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

@AlJohri AlJohri marked this pull request as ready for review March 11, 2026 21:18
@AlJohri AlJohri requested review from a team as code owners March 11, 2026 21:18
Copy link
Member

@choejwoo choejwoo left a comment

Choose a reason for hiding this comment

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

Generally LGTM.

Could we add a regression test covering argocd relogin --argocd-context <other-context> so we verify it updates the selected context rather than current-context?

Copy link
Contributor

@ppapapetrou76 ppapapetrou76 left a comment

Choose a reason for hiding this comment

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

I agree with @choejwoo - let's add a quick test ( I would expect that the test would fail before the change and succeeds after the change )

Copy link
Member

@dudinea dudinea left a comment

Choose a reason for hiding this comment

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

It would be great if you added an example using the --argocd-context flag to the usage string, so people know that this option an be used with this command.

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.

4 participants