Skip to content

fix: branch planner plans against main instead of PR branch when using Flux Operator#1730

Open
maruina wants to merge 1 commit into
flux-iac:mainfrom
maruina:fix/branch-planner-ref-precedence
Open

fix: branch planner plans against main instead of PR branch when using Flux Operator#1730
maruina wants to merge 1 commit into
flux-iac:mainfrom
maruina:fix/branch-planner-ref-precedence

Conversation

@maruina

@maruina maruina commented Mar 14, 2026

Copy link
Copy Markdown

The Branch planner's reconcileSource creates PR-specific GitRepository objects by deep-copying the original source spec and setting spec.Reference.Branch to the PR branch.

However, this doesn't work as expected when using a FluxInstance object: with a spec similar to

  sync:
    interval: 1m
    kind: GitRepository
    path: clusters/my-cluster
    pullSecret: flux-system
    ref: refs/heads/main
    url: https://github.com/my-org/my-repo.git

this gets translated into a GitRepository object with

spec:
  interval: 1m0s
  ref:
    name: refs/heads/main
  secretRef:
    name: flux-system
  timeout: 60s
  url: https://github.com/my-org/my-repo.git

FluxInstance.sync.ref: refs/heads/main is mapped to GitRepository.spec.ref.name: refs/heads/main and not spec.ref.branch.
According to the Gitrepository type, the order of precedence is: Name > Commit > SemVer > Tag > Branch

The problem is the branch planner's deep copy preserves that name field, which always wins over branch.
This causes PR plans to run against main instead of the PR branch.

This PR fix the issue by clearing those higher precedence field and setting just the branch

Clear all higher-precedence GitRepository reference fields after
DeepCopy() so only Branch takes effect on PR-specific sources.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant