Skip to content

Bug | repo-server-api fails to render multi-source apps with external $ref sources when primary source matches --repo #426

@Amoolaa

Description

@Amoolaa

Describe the bug

(Apologies for wordy title)

For context, we have some Applications targetRevisions pointing to main for our internal helm charts in dev for testing. When we raise changes to the helm charts I'd like to preview those changes across dev to get an idea on what the blast radius of those changes are.

When using --render-method repo-server-api with --redirect-target-revisions, multi-source Applications where the primary source (path:) matches --repo but a $ref source points to a different repo fail to render.

Expected behavior

When any ref source's repoURL does not match --repo, fall back to the remote RPC path (returning streamDir="") and populate request.RefSources with credentials for all ref sources. The repo server then git-fetches the primary source at source.TargetRevision and resolves all $ref sources.

Standard output (with --debug flag)

DBG Rendering application source via repo server (App: "my-app [t|...]") (multiSource: true) (remoteChart: false) (sourceIndex: 0) (streamDir: /var/folders/.../argocd-diff-preview-XXXXXXXXXX)
DBG Compressing application directory for repo server (app: my-app) (dir: /var/folders/.../argocd-diff-preview-XXXXXXXXXX)
DBG Opening GenerateManifestWithFiles stream (app: my-app)
ERR ❌ Failed to render application via repo server: error="failed to render app my-app [...]:
repo server returned error for content source 0: failed to receive manifest response:
rpc error: code = Unknown desc = failed to execute helm template command:
helm template . --values /tmp/.../.refs/helm-values-repo/values.yaml ...
Error: open /tmp/.../.refs/helm-values-repo/values.yaml: no such file or directory"

Application causing problems (if applicable)

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
spec:
  sources:
    - repoURL: https://github.com/org/helm-charts.git  # matches --repo
      path: charts/my-chart
      targetRevision: main
      helm:
        valueFiles:
          - $helm-values-repo/values.yaml
    - repoURL: https://github.com/org/app-values.git  # external ref
      targetRevision: main
      ref: helm-values-repo

Parameters

✨ Running v0.2.6 with:
✨ - using cluster with Argo CD pre-installed
✨ - render-method: repo-server-api
✨ - base-branch: main
✨ - target-branch: refs/pull/1/merge
✨ - argocd-namespace: argocd
✨ - repo: org/helm-charts
✨ - redirect-target-revisions: [main]
✨ - output-app-manifests: true

Your pipeline (if applicable)

Root cause

(Disclaimer: I have used an LLM to guide me to this conclusion)

In pkg/reposerverextract/extract.go, buildManifestRequestForSource reaches the streaming slow path when the primary source matches --repo and ref sources are present. It copies each ref source from branchFolder:

srcRefDir := filepath.Join(branchFolder, ref.Path)
if ref.Path == "" {
    // Ref-only source with no path points at the repo root.
    srcRefDir = branchFolder   // ← wrong when ref.RepoURL is a foreign repo
}
copyDir(srcRefDir, refDir)

There is no check for whether ref.RepoURL matches prRepo. When the ref source is external (ref.Path == ""), it silently copies branchFolder root instead of the actual ref repo content.

Proposed fix

Before creating the tempDir, check whether any ref source is external. If so, fall back to the remote RPC path with RefSources populated.

This is identical in structure to the fix in PR #359 (lines 594-615).

I have tested this locally and it works, so happy to raise a PR.

There is an easy workaround, which is to set --repo to the Applications repo and patch the targetRevisions in the target with the PR ref of the helm chart change. Perhaps this project isn't intended for previewing changes/cases like this, which I'm ok with.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions