Skip to content

feat: add --repo-server-address flag to skip port-forward in repo-server-api mode#407

Open
roulettedares wants to merge 4 commits into
dag-andersen:mainfrom
roulettedares:feat/repo-server-address
Open

feat: add --repo-server-address flag to skip port-forward in repo-server-api mode#407
roulettedares wants to merge 4 commits into
dag-andersen:mainfrom
roulettedares:feat/repo-server-address

Conversation

@roulettedares

Copy link
Copy Markdown

When running argocd-diff-preview inside the same cluster as Argo CD (e.g. a self-hosted CI runner), the repo server is reachable directly via ClusterIP DNS. Port-forwarding through the Kubernetes API server is unnecessary in this case and requires pods/portforward RBAC that would otherwise not be needed.

This commit wires up the existing but unused NewClientWithAddress() (defined in pkg/reposerver/client.go:77) constructor by adding a --repo-server-address flag. When set:

  • repo-server-api mode connects directly to the provided host:port
  • EnsurePortForward() is a no-op (returns nil when k8sClient is nil)
  • No pods/portforward RBAC is required on the target cluster
    Useful when running inside the same cluster as Argo CD.

The flag is validated to only be used with --render-method=repo-server-api. TLS is enabled with InsecureSkipVerify=true (matching the port-forward path, since the repo server uses a self-signed certificate by default).

Example:

 argocd-diff-preview     --render-method repo-server-api     --repo-server-address argocd-repo-server.argocd.svc.cluster.local:8081

Fixes: NewClientWithAddress() was defined but never called (pkg/reposerver/client.go)

…ver-api mode

When running argocd-diff-preview inside the same cluster as Argo CD (e.g. a
self-hosted CI runner), the repo server is reachable directly via ClusterIP DNS.
Port-forwarding through the Kubernetes API server is unnecessary in this case and
requires pods/portforward RBAC that would otherwise not be needed.

This commit wires up the existing but unused NewClientWithAddress() constructor
by adding a --repo-server-address flag. When set:
- repo-server-api mode connects directly to the provided host:port
- EnsurePortForward() is a no-op (returns nil when k8sClient is nil)
- No pods/portforward RBAC is required on the target cluster

The flag is validated to only be used with --render-method=repo-server-api.
TLS is enabled with InsecureSkipVerify=true (matching the port-forward path,
since the repo server uses a self-signed certificate by default).

Example:
  argocd-diff-preview     --render-method repo-server-api     --repo-server-address argocd-repo-server.argocd.svc.cluster.local:8081     ...

Fixes: NewClientWithAddress() was defined but never called (pkg/reposerver/client.go)
@roulettedares roulettedares marked this pull request as draft April 25, 2026 21:22
- pkg/reposerver: verify NewClientWithAddress sets fields correctly,
  EnsurePortForward is a no-op when k8sClient is nil, and Cleanup
  does not panic on a direct-address client
- cmd: verify ToConfig accepts --repo-server-address with repo-server-api
  and rejects it with server-api / cli render methods
- options.md: add flag and REPO_SERVER_ADDRESS env var to options table
- rendering-methods.md: add in-cluster direct-connect section under repo-server-api
- reusing-clusters/self-hosted-gh-runner.md: split RBAC into minimal
  (--repo-server-address) and broad options
…ss path

- Remove multi-line doc comments from tests where function names are self-explanatory
- Move pods/portforward explanation from YAML comment to prose in rendering-methods.md
- Fix appofapps.go to honour --repo-server-address (was silently ignored for app-of-apps traversal)
- Trim redundant EnsurePortForward docstring to a single line
@roulettedares roulettedares marked this pull request as ready for review April 25, 2026 22:43
@dag-andersen

Copy link
Copy Markdown
Owner

@roulettedares
Sorry for the slow reply. This past week has been very busy on my side.

Thank you for the contribution and you showing interest in the project - I really appreciate it!

In general, I try to keep the tool as seamless as possible and avoid adding too many arguments if possible, since that can be confusing for new users.

Would you be open to making this automatic instead? We already do service discovery in other places. For example, in pkg/argocd/call_api.go (portForwardToArgoCD()), we look up the Argo CD server Service by label using GetServiceNameByLabel().

Could we use the same pattern for repo server access, so users do not need to provide an extra argument in the common case? 🚀

Let me know what you think!

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.

2 participants