mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 06:16:08 -04:00
cli: perform upgrades in-place in Terraform workspace (#2317)
* perform upgrades in-place in terraform workspace Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * update buildfiles Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add iam upgrade apply test Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * update buildfiles Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * fix linter Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * make config fetcher stubbable Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * change workspace restoring behaviour Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * allow overwriting existing Terraform files Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * allow overwrites of TF variables Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * fix iam upgrade apply Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * fix embed directive Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * make loader test less brittle Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * pass upgrade ID to user Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * naming nit Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * use upgradeDir Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * tidy Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
This commit is contained in:
parent
9c54ff06e0
commit
95cf4bdf21
19 changed files with 410 additions and 286 deletions
|
@ -108,12 +108,13 @@ func runUpgradeCheck(cmd *cobra.Command, _ []string) error {
|
|||
log: log,
|
||||
versionsapi: versionfetcher,
|
||||
},
|
||||
upgradeDir: upgradeDir,
|
||||
terraformChecker: tfClient,
|
||||
fileHandler: fileHandler,
|
||||
log: log,
|
||||
}
|
||||
|
||||
return up.upgradeCheck(cmd, attestationconfigapi.NewFetcher(), upgradeDir, flags)
|
||||
return up.upgradeCheck(cmd, attestationconfigapi.NewFetcher(), flags)
|
||||
}
|
||||
|
||||
func parseUpgradeCheckFlags(cmd *cobra.Command) (upgradeCheckFlags, error) {
|
||||
|
@ -154,6 +155,7 @@ func parseUpgradeCheckFlags(cmd *cobra.Command) (upgradeCheckFlags, error) {
|
|||
|
||||
type upgradeCheckCmd struct {
|
||||
canUpgradeCheck bool
|
||||
upgradeDir string
|
||||
collect collector
|
||||
terraformChecker terraformChecker
|
||||
fileHandler file.Handler
|
||||
|
@ -161,7 +163,7 @@ type upgradeCheckCmd struct {
|
|||
}
|
||||
|
||||
// upgradePlan plans an upgrade of a Constellation cluster.
|
||||
func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fetcher attestationconfigapi.Fetcher, upgradeDir string, flags upgradeCheckFlags) error {
|
||||
func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fetcher attestationconfigapi.Fetcher, flags upgradeCheckFlags) error {
|
||||
conf, err := config.New(u.fileHandler, constants.ConfigFilename, fetcher, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
|
@ -235,9 +237,14 @@ func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fetcher attestationco
|
|||
return fmt.Errorf("planning terraform migrations: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
// Remove the upgrade directory
|
||||
if err := u.fileHandler.RemoveAll(upgradeDir); err != nil {
|
||||
u.log.Debugf("Failed to clean up Terraform migrations: %s", err)
|
||||
// User doesn't expect to see any changes in his workspace after an "upgrade plan",
|
||||
// therefore, roll back to the backed up state.
|
||||
if err := u.terraformChecker.RestoreClusterWorkspace(); err != nil {
|
||||
cmd.PrintErrf(
|
||||
"restoring Terraform workspace: %s, restore the Terraform workspace manually from %s ",
|
||||
err,
|
||||
filepath.Join(u.upgradeDir, constants.TerraformUpgradeBackupDir),
|
||||
)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -728,6 +735,7 @@ type kubernetesChecker interface {
|
|||
|
||||
type terraformChecker interface {
|
||||
PlanClusterUpgrade(ctx context.Context, outWriter io.Writer, vars terraform.Variables, csp cloudprovider.Provider) (bool, error)
|
||||
RestoreClusterWorkspace() error
|
||||
}
|
||||
|
||||
type versionListFetcher interface {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue