Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/argocd/commands/headless/headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ type forwardCacheClient struct {

func (c *forwardCacheClient) doLazy(action func(client cache.CacheClient) error) error {
c.init.Do(func() {
// Check for external Redis server address to bypass in-cluster pod discovery and port-forwarding.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this PR @devbini!

Could you please add:
Unit tests in a new headless_test.go file covering:
External Redis connection (when ARGOCD_REDIS_SERVER is set)
Fallback to port-forwarding (when env var is not set)
Optional..Cache operations (Set/Get/Delete)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback, @pbhatnagar-oss!

I will create the new headless_test.go file as requested.
To ensure I'm on the right track, please review my proposed testing plan.

  1. I'll use miniredis to simulate an external Redis server within the unit tests.

  2. Test Scenarios is Three.

  • External Redis connection

    Verify that doLazy correctly initializes the CacheClient using the address from ARGOCD_REDIS_SERVER.

  • Fallback Path

    Verify that doLazy falls back to the default port-forwarding logic when the environment variable is not set.

  • Cache Operations

    I'll perform Set, Get, and Delete operations to ensure the initialized CacheClient correctly communicates with the Redis instance.

I aim to complete these tests and update the PR by the end of today.
Does this approach sound good to you?

externalRedis := os.Getenv("ARGOCD_REDIS_SERVER")
if externalRedis != "" {
redisClient := redis.NewClient(&redis.Options{Addr: externalRedis, Password: c.redisPassword})
c.client = cache.NewRedisCache(redisClient, time.Hour, c.compression)
return
}

overrides := clientcmd.ConfigOverrides{
CurrentContext: c.context,
}
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ The following environment variables can be used with `argocd` CLI:
| `ARGOCD_REPO_SERVER_NAME` | the Argo CD Repository Server name (default "argocd-repo-server") |
| `ARGOCD_APPLICATION_CONTROLLER_NAME` | the Argo CD Application Controller name (default "argocd-application-controller") |
| `ARGOCD_REDIS_NAME` | the Argo CD Redis name (default "argocd-redis") |
| `ARGOCD_REDIS_SERVER` | the address of an external Redis server to use in --core mode. If set, the CLI bypasses in-cluster pod discovery and port-forwarding. <br> eg. `ARGOCD_REDIS_SERVER=localhost:6379` |
| `ARGOCD_REDIS_HAPROXY_NAME` | the Argo CD Redis HA Proxy name (default "argocd-redis-ha-haproxy") |
| `ARGOCD_GRPC_KEEP_ALIVE_MIN` | defines the GRPCKeepAliveEnforcementMinimum, used in the grpc.KeepaliveEnforcementPolicy. Expects a "Duration" format (default `10s`). |
Loading