mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-04 23:35:11 -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
|
@ -87,7 +87,7 @@ func TestPlanUpgrade(t *testing.T) {
|
|||
hasDiff, err := planUpgrade(
|
||||
context.Background(), tc.tf, fs, io.Discard, terraform.LogLevelDebug,
|
||||
&terraform.QEMUVariables{},
|
||||
"existing", "upgrade", "backup",
|
||||
"test", "backup",
|
||||
)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -99,9 +99,9 @@ func TestPlanUpgrade(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMoveUpgradeToCurrent(t *testing.T) {
|
||||
func TestRestoreBackup(t *testing.T) {
|
||||
existingWorkspace := "foo"
|
||||
upgradeWorkingDir := "bar"
|
||||
backupDir := "bar"
|
||||
|
||||
testCases := map[string]struct {
|
||||
prepareFs func(require *require.Assertions) file.Handler
|
||||
|
@ -111,18 +111,18 @@ func TestMoveUpgradeToCurrent(t *testing.T) {
|
|||
prepareFs: func(require *require.Assertions) file.Handler {
|
||||
fs := file.NewHandler(afero.NewMemMapFs())
|
||||
require.NoError(fs.MkdirAll(existingWorkspace))
|
||||
require.NoError(fs.MkdirAll(upgradeWorkingDir))
|
||||
require.NoError(fs.MkdirAll(backupDir))
|
||||
return fs
|
||||
},
|
||||
},
|
||||
"old workspace does not exist": {
|
||||
"existing workspace does not exist": {
|
||||
prepareFs: func(require *require.Assertions) file.Handler {
|
||||
fs := file.NewHandler(afero.NewMemMapFs())
|
||||
require.NoError(fs.MkdirAll(upgradeWorkingDir))
|
||||
require.NoError(fs.MkdirAll(backupDir))
|
||||
return fs
|
||||
},
|
||||
},
|
||||
"upgrade working dir does not exist": {
|
||||
"backup dir does not exist": {
|
||||
prepareFs: func(require *require.Assertions) file.Handler {
|
||||
fs := file.NewHandler(afero.NewMemMapFs())
|
||||
require.NoError(fs.MkdirAll(existingWorkspace))
|
||||
|
@ -135,8 +135,7 @@ func TestMoveUpgradeToCurrent(t *testing.T) {
|
|||
memFS := afero.NewMemMapFs()
|
||||
fs := file.NewHandler(memFS)
|
||||
require.NoError(fs.MkdirAll(existingWorkspace))
|
||||
require.NoError(fs.MkdirAll(upgradeWorkingDir))
|
||||
|
||||
require.NoError(fs.MkdirAll(backupDir))
|
||||
return file.NewHandler(afero.NewReadOnlyFs(memFS))
|
||||
},
|
||||
wantErr: true,
|
||||
|
@ -148,7 +147,7 @@ func TestMoveUpgradeToCurrent(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
fs := tc.prepareFs(require.New(t))
|
||||
|
||||
err := moveUpgradeToCurrent(fs, existingWorkspace, upgradeWorkingDir)
|
||||
err := restoreBackup(fs, existingWorkspace, backupDir)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
|
@ -209,7 +208,7 @@ type stubUpgradePlanner struct {
|
|||
showPlanErr error
|
||||
}
|
||||
|
||||
func (s *stubUpgradePlanner) PrepareUpgradeWorkspace(_, _ string, _ string, _ terraform.Variables) error {
|
||||
func (s *stubUpgradePlanner) PrepareUpgradeWorkspace(_, _ string, _ terraform.Variables) error {
|
||||
return s.prepareWorkspaceErr
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue