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

Fix: legacy backend state reading and GC #338

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

chivalryq
Copy link
Member

@chivalryq chivalryq commented Aug 10, 2022

For now if restart controller with --controller-namespace. The configuration state will become GeneratingTerraformOutputs and stuck. This is because controller can't got the legacy backend.

Fix that Configuration.Spec.Backend will be overwritten if set --controller-namespace. Instead, now controller
only overwrite Configuration.Spec.Backend when no backend specified.

How is this tested

Add both unittest and e2e test

Signed-off-by: Qiaozp qiaozhongpei.qzp@alibaba-inc.com

@codecov
Copy link

codecov bot commented Aug 10, 2022

Codecov Report

Merging #338 (a7ece49) into master (5d81c7b) will increase coverage by 3.03%.
The diff coverage is 83.58%.

❗ Current head a7ece49 differs from pull request most recent head 244602c. Consider uploading reports for the commit 244602c to get more accurate results

@@            Coverage Diff             @@
##           master     #338      +/-   ##
==========================================
+ Coverage   76.58%   79.62%   +3.03%     
==========================================
  Files          24       23       -1     
  Lines        1764     1737      -27     
==========================================
+ Hits         1351     1383      +32     
+ Misses        335      272      -63     
- Partials       78       82       +4     
Flag Coverage Δ
e2e ∅ <ø> (∅)
unit 79.62% <83.58%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
controllers/configuration/configuration.go 95.40% <ø> (+2.33%) ⬆️
controllers/configuration/backend/kubernetes.go 77.47% <75.47%> (-5.14%) ⬇️
controllers/configuration_controller.go 77.75% <87.14%> (+0.03%) ⬆️
controllers/configuration/backend/backend.go 89.58% <100.00%> (+0.22%) ⬆️
controllers/provider/credentials.go 92.63% <100.00%> (ø)
controllers/provider/ucloud.go 100.00% <100.00%> (ø)
controllers/terraform/status.go 77.41% <100.00%> (ø)
e2e/normal/regression.go

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@loheagn loheagn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user applies a Configuration without spec.Backend, then the terraform apply job will use the default kubernetes backend whose secret is {Namespace: ${env.TERRAFORM_BACKEND_NAMESPACE} || ${configuration.Namespace}, Name: tfstate-default-${confguration.Name}}.

Then, the user restarts the controller with --controller-namespace. In this case, the terraform apply job will use the default kubernetes backend whose secret is {Namespace: ${env.TERRAFORM_BACKEND_NAMESPACE} || ${configuration.Namespace}, Name: tfstate-default-${confguration.UID}}.

The two backend secrets are in the same namespace but have different names. Will this cause an error?

@loheagn
Copy link
Contributor

loheagn commented Aug 10, 2022

Shoule we add some e2e tests for the "restart controller with --controller-namespace" cases?

@chivalryq
Copy link
Member Author

If a user applies a Configuration without spec.Backend, then the terraform apply job will use the default kubernetes backend whose secret is {Namespace: ${env.TERRAFORM_BACKEND_NAMESPACE} || ${configuration.Namespace}, Name: tfstate-default-${confguration.Name}}.

Then, the user restarts the controller with --controller-namespace. In this case, the terraform apply job will use the default kubernetes backend whose secret is {Namespace: ${env.TERRAFORM_BACKEND_NAMESPACE} || ${configuration.Namespace}, Name: tfstate-default-${confguration.UID}}.

The two backend secrets are in the same namespace but have different names. Will this cause an error?

There are duplications. But it's OK.

  1. New secret won't be used. It is created for simplicity (No need for extra logic).
  2. They will be both deleted when calling backend.Cleanup.
Fix: legacy backend GC

add e2e test

split package

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants