Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch planner PR's assume empty state #1163

Open
YentlFrickx opened this issue Dec 12, 2023 · 5 comments
Open

Branch planner PR's assume empty state #1163

YentlFrickx opened this issue Dec 12, 2023 · 5 comments
Labels
area/branch-planner kind/bug Something isn't working

Comments

@YentlFrickx
Copy link

I set up the tf-controller in my cluster and it works without issue for applying changes in the 'main' branch. But using the branch planner functionality I noticed that on every PR I create, it starts from an empty state instead of from the state from the main branch. This results in all resources seemingly being created for the first time, not changed or added.

@jsimpso
Copy link

jsimpso commented Dec 15, 2023

I just ran into this too, it looks like it's due to how secretSuffix is being dynamically assigned in the backend config when not specified in the spec.

For a Terraform object named testing, the default secretSuffix is testing. However, for a branch-planner PR object, the default secretSuffix ends up being testing-pr-{pr_id}.

This can be worked around with the default backend by manually specifying secretSuffix in your backendConfig , e.g.

apiVersion: infra.contrib.fluxcd.io/v1alpha2
kind: Terraform
metadata:
  name: helloworld
  namespace: flux-system
spec:
  interval: 1m
  approvePlan: auto
  path: ./
  backendConfig:
    secretSuffix: helloworld
  sourceRef:
    kind: GitRepository
    name: helloworld
    namespace: flux-system

@yitsushi
Copy link
Collaborator

yitsushi commented Jan 5, 2024

I remember an issue about it, or similar to this issue, but I can't find it. I have no idea if we fixed it (thought we fix) or just wanted to fix it.

@yitsushi yitsushi added area/branch-planner kind/bug Something isn't working labels Jan 5, 2024
@mnencia
Copy link

mnencia commented Jan 31, 2024

It looks like this is the commit that should fixe the issue e93dc5e

@yitsushi
Copy link
Collaborator

yitsushi commented Feb 2, 2024

Thank you. Yes it's related. I don't know yet why it doesn't help the way we expect.

if spec.BackendConfig == nil {
	spec.BackendConfig = &infrav1.BackendConfigSpec{
		SecretSuffix:    originalTF.Name,
		InClusterConfig: true,
	}
}

One issue with this that I can see instantly, it only changes things if BackendConfig it does not apply this, which is okay in most cases, but I can see some edge cases where it fails as hard as it can (like only Labels is defined).

In other cases it literally does the same as the suggested workaround:

default backend by manually specifying secretSuffix

It sets the SecretSuffix to the same as the original TF resource name, so if that workaround works, than this patch should solve that case.

@yitsushi
Copy link
Collaborator

yitsushi commented Feb 2, 2024

Ah, never mind. The mentioned commit landed on Sep 28, 2023, but out latest RC release was on Sep 19, 2023, so it's fixed only in main. We should really create a new release :/

So I guess it's fixed, but the fix is not released yet only merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/branch-planner kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants