mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
state: add migration (#2580)
This commit is contained in:
parent
56ab3e9e04
commit
6f195c6f2c
@ -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 {
|
||||
|
@ -11,7 +11,9 @@ go_library(
|
||||
visibility = ["//cli:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/cloud/cloudprovider",
|
||||
"//internal/constants",
|
||||
"//internal/file",
|
||||
"//internal/semver",
|
||||
"//internal/validation",
|
||||
"@cat_dario_mergo//:mergo",
|
||||
"@com_github_siderolabs_talos_pkg_machinery//config/encoder",
|
||||
|
@ -20,7 +20,9 @@ import (
|
||||
|
||||
"dario.cat/mergo"
|
||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/edgelesssys/constellation/v2/internal/semver"
|
||||
"github.com/edgelesssys/constellation/v2/internal/validation"
|
||||
)
|
||||
|
||||
@ -555,6 +557,24 @@ func (s *State) Constraints() []*validation.Constraint {
|
||||
return []*validation.Constraint{}
|
||||
}
|
||||
|
||||
// Migrate migrates the state to the current version.
|
||||
// This is mostly done to pass the validation of the current version.
|
||||
// The infrastructure will be overwritten by the terraform outputs after the validation.
|
||||
func (s *State) Migrate() error {
|
||||
// In v2.13.0 the ClusterEndpoint and InClusterEndpoint fields were added.
|
||||
// So they are expected to be empty when upgrading to this version.
|
||||
// TODO(3u13r): Remove on main after v2.13.0 is released.
|
||||
if constants.BinaryVersion().MajorMinorEqual(semver.NewFromInt(2, 13, 0, "")) {
|
||||
if s.Infrastructure.InClusterEndpoint == "" {
|
||||
s.Infrastructure.InClusterEndpoint = s.Infrastructure.ClusterEndpoint
|
||||
}
|
||||
if s.Infrastructure.IPCidrNode == "" {
|
||||
s.Infrastructure.IPCidrNode = "192.168.2.1/32"
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// HexBytes is a byte slice that is marshalled to and from a hex string.
|
||||
type HexBytes []byte
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user