Production plans on PRs: branch planner blocked for Forgejo #97

Open
opened 2026-11-15 15:35:50 +00:00 by ginjiruu · 2 comments
Owner

Goal: production plans for an iac PR appear on the PR, so nobody needs state or OpenBao credentials on a workstation.

Branch planner can't do it today

tofu-controller v0.16.4 added a Gitea provider to the branch planner (flux-iac/tofu-controller#1780). It can't be reached for a self-hosted Forgejo, and v0.16.6 (2026-10-26) still has the bug.

  • internal/informer/branch-planner/informer.go calls provider.RepoFromURL(obj.Spec.URL) and then provider.FromURL.
  • Both parse the URL with kubescape/go-git-url v0.0.33. Its NewGitURL only knows GitHub, Azure, Bitbucket and GitLab hosts, and returns repository host '<host>' not supported for anything else.
  • So ssh://git@git.animeteamspeak.moe/lab/iac.git fails before the Gitea provider is ever created.

The only override is WithCustomProviderURLParserFn, an option the branch-planner binary doesn't expose.

Options

  1. Patch upstream so the provider type can be set explicitly, for example a --git-provider=gitea flag or an annotation on the GitRepository. The Gitea provider itself already exists, so the fix is small.
  2. Run the plan from Forgejo Actions instead. A workflow on PRs runs tofu plan with read-only state access and an OpenBao planner token, then posts the plan as a comment. This needs the read access from the local-plan issue.

Option 1 keeps plans on the runner that applies, which is the reason to want the branch planner at all.

Goal: production plans for an iac PR appear on the PR, so nobody needs state or OpenBao credentials on a workstation. ## Branch planner can't do it today tofu-controller v0.16.4 added a Gitea provider to the branch planner (flux-iac/tofu-controller#1780). It can't be reached for a self-hosted Forgejo, and v0.16.6 (2026-10-26) still has the bug. - `internal/informer/branch-planner/informer.go` calls `provider.RepoFromURL(obj.Spec.URL)` and then `provider.FromURL`. - Both parse the URL with `kubescape/go-git-url` v0.0.33. Its `NewGitURL` only knows GitHub, Azure, Bitbucket and GitLab hosts, and returns `repository host '<host>' not supported` for anything else. - So `ssh://git@git.animeteamspeak.moe/lab/iac.git` fails before the Gitea provider is ever created. The only override is `WithCustomProviderURLParserFn`, an option the branch-planner binary doesn't expose. ## Options 1. Patch upstream so the provider type can be set explicitly, for example a `--git-provider=gitea` flag or an annotation on the GitRepository. The Gitea provider itself already exists, so the fix is small. 2. Run the plan from Forgejo Actions instead. A workflow on PRs runs `tofu plan` with read-only state access and an OpenBao `planner` token, then posts the plan as a comment. This needs the read access from the local-plan issue. Option 1 keeps plans on the runner that applies, which is the reason to want the branch planner at all.
Author
Owner

Correction after reading go-git-url v0.0.33: git.animeteamspeak.moe is not rejected. IsHostGitLab matches any host starting with "git.", so the planner treats Forgejo as GitLab and calls GitLab endpoints. No URL reaches the Gitea provider, because no parser returns "gitea".

A second bug shows up once the provider is reachable: Gitea/Forgejo list merged and closed pull requests when no state is given, so the planner would plan all 41 old lab/iac PRs every poll.

Both fixed in a local fork, ~/go/src/github.com/flux-iac/tofu-controller branch forgejo-provider: a --git-provider-host==gitea flag and Open: true on the list call. Live test against lab/iac lists the 3 open PRs.

Correction after reading go-git-url v0.0.33: git.animeteamspeak.moe is not rejected. IsHostGitLab matches any host starting with "git.", so the planner treats Forgejo as GitLab and calls GitLab endpoints. No URL reaches the Gitea provider, because no parser returns "gitea". A second bug shows up once the provider is reachable: Gitea/Forgejo list merged and closed pull requests when no state is given, so the planner would plan all 41 old lab/iac PRs every poll. Both fixed in a local fork, ~/go/src/github.com/flux-iac/tofu-controller branch forgejo-provider: a --git-provider-host=<host>=gitea flag and Open: true on the list call. Live test against lab/iac lists the 3 open PRs.
Author
Owner

Gap found 2026-11-17 (c1 VLAN-20 window, PRs #140/#141): the branch planner ConfigMap on mini lists only openbao-config, kanidm-config and harbor-config. The three routeros-* roots never get PR plans, and they run approvePlan: auto with no dependsOn, so a router PR merge applies unseen.

Workaround used tonight (manual, once): plan-only clones in flux-system (planOnly: true, destroyResourcesOnDeletion: false, backendConfig.secretSuffix = the real object so they read real state, a GitRepository per PR branch), label animeteamspeak.moe/temporary=c1-window-plan, deleted afterwards. Caveats learned:

  • branches must be rebased on master first, or the plan shows master's newer work being removed;
  • clones of the same root share the state lock (plan them one at a time);
  • clones show artifacts the real object does not (monitoring slot data_json_wo updates, rollback hash re-arm), so plan a master clone as the baseline and diff against it.

What a proper fix needs: a read-only router identity for PR plans (REST read user per device, like the #139 monitoring user, plus a read-only Bao policy for the vault_* data the roots touch), routeros-* added to the planner ConfigMap, runners in iac-plans without the apply secrets.

Gap found 2026-11-17 (c1 VLAN-20 window, PRs #140/#141): the branch planner ConfigMap on mini lists only openbao-config, kanidm-config and harbor-config. The three routeros-* roots never get PR plans, and they run `approvePlan: auto` with no dependsOn, so a router PR merge applies unseen. Workaround used tonight (manual, once): plan-only clones in flux-system (`planOnly: true`, `destroyResourcesOnDeletion: false`, `backendConfig.secretSuffix` = the real object so they read real state, a GitRepository per PR branch), label `animeteamspeak.moe/temporary=c1-window-plan`, deleted afterwards. Caveats learned: - branches must be rebased on master first, or the plan shows master's newer work being removed; - clones of the same root share the state lock (plan them one at a time); - clones show artifacts the real object does not (monitoring slot `data_json_wo` updates, rollback hash re-arm), so plan a master clone as the baseline and diff against it. What a proper fix needs: a read-only router identity for PR plans (REST read user per device, like the #139 monitoring user, plus a read-only Bao policy for the vault_* data the roots touch), routeros-* added to the planner ConfigMap, runners in iac-plans without the apply secrets.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/iac#97
No description provided.