8000 cli: perform upgrades in-place in Terraform workspace by msanft · Pull Request #2317 · edgelesssys/constellation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cli: perform upgrades in-place in Terraform workspace #2317

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

Merged
merged 16 commits into from
Sep 14, 2023

Conversation

msanft
Copy link
Contributor
@msanft msanft commented Sep 7, 2023

Context

Previously, on an upgrade including Terraform changes, Constellation would create an external folder ./constellation-upgrade/abc/terraform with a copy of the pre-upgrade Terraform state and the post-upgrade wanted Terraform configuration, and do a terraform plan and terraform apply there. Only if the upgrade would complete successfully, the folder would be copied from ./constellation-upgrade/abc/terraform into ./constellation-terraform. If an upgrade failed, the intermediate state would be lost and users weren't able to use terraform import on the intermediate state.

Proposed change(s)

  • On a Terraform (IAM or cluster) upgrade, first back up the corresponding folder (containing the pre-upgrade state) into ./constellation-upgrade/abc/terraform-backup or ./constellation-upgrade/abc/terraform-iam-backup
  • Then, copy the new embedded Terraform configuration (what the user wants to have post-upgrade) into the constellation-terraform or constellation-iam-terraform folder.
  • Then, show the diff of said folder and apply it if the user confirms.

Additional info

Checklist

  • Add labels (e.g., for changelog category)
  • Is PR title adequate for changelog?
  • Link to Milestone

@msanft msanft added the feature This introduces new functionality label Sep 7, 2023
@msanft msanft added this to the v2.11.0 milestone Sep 7, 2023
@msanft msanft requested a review from malt3 September 7, 2023 11:29
@netlify
Copy link
netlify bot commented Sep 7, 2023

Deploy Preview for constellation-docs canceled.

Name Link
🔨 Latest commit b0266de
🔍 Latest deploy log https://app.netlify.com/sites/constellation-docs/deploys/6502bb196750c200088f006d

@github-actions
Copy link
Contributor
github-actions bot commented Sep 7, 2023

Coverage report

Package Old New Trend
cli/internal/cloudcmd 65.10% 64.20% ↘️
cli/internal/cmd 55.10% 56.30% ↗️
cli/internal/terraform 71.30% 71.40% ↗️

@3u13r 3u13r modified the milestones: v2.11.0, v2.12.0 Sep 8, 2023
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signe
8000
d-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
@msanft msanft force-pushed the feat/cli/tf-upgrade-folder branch from 5035dc7 to 0617c3a Compare September 11, 2023 09:33
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
@msanft msanft marked this pull request as ready for review September 12, 2023 08:35
10000
@@ -83,6 +83,15 @@ func TestUpgradeApply(t *testing.T) {
wantErr: true,
stdin: "no\n",
},
"abort, rollback terraform err": {
kubeUpgrader: &stubKubernetesUpgrader{
currentConfig: config.DefaultForAzureSEVSNP(),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we check that TF is restored when the upgrade is aborted (use the mock for that?) and also not called when we don't abort?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a strong opinion on mocks, but I think we should discuss if we want to actively use mock testing in the team and either do it in every package when someone edits it

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that mocking is a last resort. Of course it would be more resilient to only mock the filesystem and actually check that the files are restored

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do see the point in using mocks for verifying that the expected code path is taken here. However, I don't think that this fits very well with our current testing strategy here, as it would require us to encode logic in our tests, which is often recognized as an anti-pattern. (see here, 12-14 to 12-16) I do see the values coming from these tests, but I think if we decide to adopt this, we should do so as a whole. I think we should avoid mocking only in certain tests, to keep some consistency. I might have a wrong understanding of how to use these mocks too. If you see a way to use it without putting too much logic into the test, feel free to let me know.

},
yesFlag: true,
wantErr: true,
},
ED4F Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding the tests. could we add the restore called check here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

s.a.

Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Copy link
Contributor
@elchead elchead left a comment

Choose a reason for hiding this comment

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

lgtm with the suggested changes

Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
@msanft msanft merged commit 95cf4bd into main Sep 14, 2023
@msanft msanft deleted the feat/cli/tf-upgrade-folder branch September 14, 2023 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This introduces new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0