mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 22:34:56 -04:00
cli: use state file on init and upgrade (#2395)
* [wip] use state file in CLI Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> tidy Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * use state file in CLI Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> take clusterConfig from IDFile for compat Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> various fixes Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> wip Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add GCP-specific values in Helm loader test Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove unnecessary pointer Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * write ClusterValues in one step Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * move stub to test file Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove mention of id-file Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * move output to `migrateTerraform` Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * unconditional assignments converting from idFile Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * move require block in go modules file Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * fall back to id file on upgrade Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * tidy Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * fix linter check Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add notice to remove Terraform state check on manual migration Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add `name` field Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> fix name tests Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * return early if no Terraform diff Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * tidy Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * return infrastructure state even if no diff exists Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add TODO to remove comment Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * use state-file in miniconstellation Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * cli: remove id-file (#2402) * remove id-file from `constellation create` Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add file renaming to handler * rename id-file after upgrade * use idFile on `constellation init` Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove id-file from `constellation verify` Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * linter fixes Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove id-file from `constellation mini` * remove id-file from `constellation recover` * linter fixes * remove id-file from `constellation terminate` * fix initSecret type * fix recover argument precedence * fix terminate test * generate * add TODO to remove id-file removal * Update cli/internal/cmd/init.go Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com> * fix verify arg parse logic Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * add version test Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove id-file from docs * add file not found log * use state-file in miniconstellation Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove id-file from `constellation iam destroy` Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * remove id-file from `cdbg deploy` Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com> * use state-file in CI Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * update orchestration docs --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com>
This commit is contained in:
parent
dbf40d185c
commit
005e865a13
51 changed files with 1189 additions and 497 deletions
|
@ -11,8 +11,7 @@ import (
|
|||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/clusterid"
|
||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/state"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/spf13/afero"
|
||||
|
@ -47,65 +46,64 @@ func TestTerminateCmdArgumentValidation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTerminate(t *testing.T) {
|
||||
setupFs := func(require *require.Assertions, idFile clusterid.File) afero.Fs {
|
||||
setupFs := func(require *require.Assertions, stateFile *state.State) afero.Fs {
|
||||
fs := afero.NewMemMapFs()
|
||||
fileHandler := file.NewHandler(fs)
|
||||
require.NoError(fileHandler.Write(constants.AdminConfFilename, []byte{1, 2}, file.OptNone))
|
||||
require.NoError(fileHandler.WriteJSON(constants.ClusterIDsFilename, idFile, file.OptNone))
|
||||
require.NoError(fileHandler.Write(constants.StateFilename, []byte{3, 4}, file.OptNone))
|
||||
require.NoError(stateFile.WriteToFile(fileHandler, constants.StateFilename))
|
||||
return fs
|
||||
}
|
||||
someErr := errors.New("failed")
|
||||
|
||||
testCases := map[string]struct {
|
||||
idFile clusterid.File
|
||||
stateFile *state.State
|
||||
yesFlag bool
|
||||
stdin string
|
||||
setupFs func(*require.Assertions, clusterid.File) afero.Fs
|
||||
setupFs func(*require.Assertions, *state.State) afero.Fs
|
||||
terminator spyCloudTerminator
|
||||
wantErr bool
|
||||
wantAbort bool
|
||||
}{
|
||||
"success": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
stateFile: state.New(),
|
||||
setupFs: setupFs,
|
||||
terminator: &stubCloudTerminator{},
|
||||
yesFlag: true,
|
||||
},
|
||||
"interactive": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
stateFile: state.New(),
|
||||
setupFs: setupFs,
|
||||
terminator: &stubCloudTerminator{},
|
||||
stdin: "yes\n",
|
||||
},
|
||||
"interactive abort": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
stateFile: state.New(),
|
||||
setupFs: setupFs,
|
||||
terminator: &stubCloudTerminator{},
|
||||
stdin: "no\n",
|
||||
wantAbort: true,
|
||||
},
|
||||
"files to remove do not exist": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
setupFs: func(require *require.Assertions, idFile clusterid.File) afero.Fs {
|
||||
stateFile: state.New(),
|
||||
setupFs: func(require *require.Assertions, stateFile *state.State) afero.Fs {
|
||||
fs := afero.NewMemMapFs()
|
||||
fileHandler := file.NewHandler(fs)
|
||||
require.NoError(fileHandler.WriteJSON(constants.ClusterIDsFilename, idFile, file.OptNone))
|
||||
require.NoError(stateFile.WriteToFile(fileHandler, constants.StateFilename))
|
||||
return fs
|
||||
},
|
||||
terminator: &stubCloudTerminator{},
|
||||
yesFlag: true,
|
||||
},
|
||||
"terminate error": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
stateFile: state.New(),
|
||||
setupFs: setupFs,
|
||||
terminator: &stubCloudTerminator{terminateErr: someErr},
|
||||
yesFlag: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing id file does not error": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
setupFs: func(require *require.Assertions, idFile clusterid.File) afero.Fs {
|
||||
stateFile: state.New(),
|
||||
setupFs: func(require *require.Assertions, stateFile *state.State) afero.Fs {
|
||||
fs := afero.NewMemMapFs()
|
||||
fileHandler := file.NewHandler(fs)
|
||||
require.NoError(fileHandler.Write(constants.AdminConfFilename, []byte{1, 2}, file.OptNone))
|
||||
|
@ -115,9 +113,9 @@ func TestTerminate(t *testing.T) {
|
|||
yesFlag: true,
|
||||
},
|
||||
"remove file fails": {
|
||||
idFile: clusterid.File{CloudProvider: cloudprovider.GCP},
|
||||
setupFs: func(require *require.Assertions, idFile clusterid.File) afero.Fs {
|
||||
fs := setupFs(require, idFile)
|
||||
stateFile: state.New(),
|
||||
setupFs: func(require *require.Assertions, stateFile *state.State) afero.Fs {
|
||||
fs := setupFs(require, stateFile)
|
||||
return afero.NewReadOnlyFs(fs)
|
||||
},
|
||||
terminator: &stubCloudTerminator{},
|
||||
|
@ -141,7 +139,7 @@ func TestTerminate(t *testing.T) {
|
|||
cmd.Flags().String("workspace", "", "")
|
||||
|
||||
require.NotNil(tc.setupFs)
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.idFile))
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.stateFile))
|
||||
|
||||
if tc.yesFlag {
|
||||
require.NoError(cmd.Flags().Set("yes", "true"))
|
||||
|
@ -159,8 +157,6 @@ func TestTerminate(t *testing.T) {
|
|||
assert.True(tc.terminator.Called())
|
||||
_, err = fileHandler.Stat(constants.AdminConfFilename)
|
||||
assert.Error(err)
|
||||
_, err = fileHandler.Stat(constants.ClusterIDsFilename)
|
||||
assert.Error(err)
|
||||
_, err = fileHandler.Stat(constants.StateFilename)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue