10000 cli: dry-run Terraform migrations on `upgrade check` by msanft · Pull Request #1942 · edgelesssys/constellation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cli: dry-run Terraform migrations on upgrade check #1942

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 7 commits into from
Jun 20, 2023

Conversation

msanft
Copy link
Contributor
@msanft msanft commented Jun 19, 2023

Context

  • The upgrade check command used not to take the Terraform migrations into account that would happen within the checked upgrade. This should be changed in this PR.

Proposed change(s)

  • The upgrade check command should perform a dry-run of the Terraform migrations that will be applied within the update, to show the user which actions on cloud resources will be taken upon the update.

Additional info

  • Right now, the parseTerraformUpgradeVars function is shared between both the upgrade check and the upgrade apply command. This is certainly not a great dependency model and it should likely be factored out. I was unsure about what an appropriate place might be.

Checklist

  • Add labels (e.g., for changelog category)
  • Link to Milestone

@msanft msanft added the no changelog Change won't be listed in release changelog label Jun 19, 2023
@msanft msanft added this to the v2.9.0 milestone Jun 19, 2023
@msanft msanft requested a review from derpsteb June 19, 2023 10:05
@msanft msanft requested a review from katexochen as a code owner June 19, 2023 10:05
@msanft msanft removed the request for review from katexochen June 19, 2023 10:05
@elchead
Copy link
Contributor
elchead commented Jun 19, 2023

Could you please add the Context section of the new PR template to the description?

@elchead
Copy link
Contributor
elchead commented Jun 19, 2023

I would suggest adding a flag --dry-run to apply rather than adding a new subcommand as done in helm:
https://helm.sh/docs/chart_template_guide/debugging/

This would also solve this problem?

Right now, the parseTerraformUpgradeVars function is shared between both the upgrade check and the upgrade apply command. This is certainly not a great dependency model and it should likely be factored out. I was unsure about what an appropriate place might be.

@elchead elchead self-requested a review June 19, 2023 11:52
@@ -120,8 +120,7 @@ func (u *TerraformUpgrader) PlanTerraformMigrations(ctx context.Context, opts Te
// aborted by the user.
func (u *TerraformUpgrader) CleanUpTerraformMigrations(fileHandler file.Handler, upgradeID string) error {
cleanupFiles := []string{
filepath.Join(constants.UpgradeDir, upgradeID, constants.TerraformUpgradeBackupDir),
filepath.Join(constants.UpgradeDir, upgradeID, constants.TerraformUpgradeWorkingDir),
filepath.Join(constants.UpgradeDir, upgradeID),
Copy link
Contributor

Choose a reason for hiding this comment

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

is it safe to not specify the subdirs anymore? not saying it is not, but just want to raise potential implications if there could be more directories. We still seem to follow explicit listing in l.97f

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I should've changed this when we implemented the upgrade versioning. Before we had the 2 subfolders that needed to be cleaned individually. Now we have 1 folder {constants.UpgradeDir}/{upgradeID}

writeConfig bool
ref string
stream string
terraformLogLevel terraform.LogLevel
}

type upgradeChecker interface {
Copy link
Contributor
@elchead elchead Jun 19, 2023

Choose a reason for hiding this comment

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

the interface seems to go away from what the name suggests: "checking" and instead has side-effects.
PlanTerraformMigrations and CleanUpTerraformMigrations don't seem to belong there.
By seperating this we could maybe also avoid passing the same checker object twice in runUpgradeCheck for cmd creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we won't come around passing the checker twice as it's creating all resources needed for upgrades (i.e. also the Terraform client).

However I do agree that the naming and separation can be changed.

@elchead
Copy link
Contributor
elchead commented Jun 19, 2023

Happy to jump on a call to discuss together

@msanft
Copy link
Contributor Author
msanft commented Jun 19, 2023

I would suggest adding a flag --dry-run to apply rather than adding a new subcommand as done in helm: https://helm.sh/docs/chart_template_guide/debugging/

This would also solve this problem?

Right now, the parseTerraformUpgradeVars function is shared between both the upgrade check and the upgrade apply command. This is certainly not a great dependency model and it should likely be factored out. I was unsure about what an appropriate place might be.

We should see what @derpsteb thinks as he initially designed the upgrade flow

@msanft msanft force-pushed the feat/cli/upgrade-check-tf-dryrun branch from a10009f to 92b192c Compare June 20, 2023 06:22
@msanft msanft force-pushed the feat/cli/upgrade-check-tf-dryrun branch from 92b192c to 92907b6 Compare June 20, 2023 06:43
@msanft msanft force-pushed the feat/cli/upgrade-check-tf-dryrun branch from 92907b6 to 44357a7 Compare June 20, 2023 06:45
@msanft msanft removed the request for review from thomasten June 20, 2023 06:45
@derpsteb
Copy link
Contributor

We had a short discussion on the --dry-run flag and came to the conclusion that this is not relevant for this PR.

@msanft msanft merged commit 2f10c3f into feat/cli/upgrade-versioning Jun 20, 2023
@msanft msanft deleted the feat/cli/upgrade-check-tf-dryrun branch June 20, 2023 09:27
msanft added a commit that referenced this pull request Jun 21, 2023
* upgrade versioning

* dont pass upgrade kind as boolean

* whitespace

* fix godot lint check

* clarify upgrade check directory suffix

* cli: dry-run Terraform migrations on `upgrade check` (#1942)

* dry-run Terraform migrations on upgrade check

* clean whole upgrade dir

* clean up check workspace after planning

* fix parsing

* extend upgrade check test

* rename unused parameters

* exclude false positives in test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Change won't be listed in release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0