state: add migration (#2580)

This commit is contained in:
3u13r 2023-11-13 20:49:54 +01:00 committed by GitHub
parent 56ab3e9e04
commit 6f195c6f2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View file

@ -337,6 +337,18 @@ The control flow is as follows:
*/
func (a *applyCmd) apply(cmd *cobra.Command, configFetcher attestationconfigapi.Fetcher, upgradeDir string) error {
// Migrate state file
stateFile, err := state.ReadFromFile(a.fileHandler, constants.StateFilename)
if err != nil {
return fmt.Errorf("reading state file: %w", err)
}
if err := stateFile.Migrate(); err != nil {
return fmt.Errorf("migrating state file: %w", err)
}
if err := stateFile.WriteToFile(a.fileHandler, constants.StateFilename); err != nil {
return fmt.Errorf("writing state file: %w", err)
}
// Validate inputs
conf, stateFile, err := a.validateInputs(cmd, configFetcher)
if err != nil {