mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 14:26:23 -04:00
cli: generate state file during constellation config generate
(#2455)
* create state file during config generate * use written file in `constellation create` * document creation of state file * remove accidentally added test * check error when writing state file
This commit is contained in:
parent
e5513f14e6
commit
25b23689ad
6 changed files with 70 additions and 22 deletions
|
@ -191,8 +191,12 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
|
|||
}
|
||||
c.log.Debugf("Successfully created the cloud resources for the cluster")
|
||||
|
||||
state := state.New().SetInfrastructure(infraState)
|
||||
if err := state.WriteToFile(fileHandler, constants.StateFilename); err != nil {
|
||||
stateFile, err := state.ReadFromFile(fileHandler, constants.StateFilename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading state file: %w", err)
|
||||
}
|
||||
stateFile = stateFile.SetInfrastructure(infraState)
|
||||
if err := stateFile.WriteToFile(fileHandler, constants.StateFilename); err != nil {
|
||||
return fmt.Errorf("writing state file: %w", err)
|
||||
}
|
||||
|
||||
|
@ -216,13 +220,6 @@ func (c *createCmd) checkDirClean(fileHandler file.Handler) error {
|
|||
c.flags.pathPrefixer.PrefixPrintablePath(constants.MasterSecretFilename),
|
||||
)
|
||||
}
|
||||
c.log.Debugf("Checking state file")
|
||||
if _, err := fileHandler.Stat(constants.StateFilename); !errors.Is(err, fs.ErrNotExist) {
|
||||
return fmt.Errorf(
|
||||
"file '%s' already exists in working directory. Constellation won't overwrite previous cluster state. Move it somewhere or delete it before creating a new cluster",
|
||||
c.flags.pathPrefixer.PrefixPrintablePath(constants.StateFilename),
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue