diff --git a/cli/internal/cmd/apply.go b/cli/internal/cmd/apply.go index d3da58cfe3b..6898b7ceb2b 100644 --- a/cli/internal/cmd/apply.go +++ b/cli/internal/cmd/apply.go @@ -337,6 +337,15 @@ 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 err + } + if err := stateFile.Migrate(); err != nil { + return err + } + // Validate inputs conf, stateFile, err := a.validateInputs(cmd, configFetcher) if err != nil { diff --git a/cli/internal/state/BUILD.bazel b/cli/internal/state/BUILD.bazel index 0d24793d65e..ca45e7ffd20 100644 --- a/cli/internal/state/BUILD.bazel +++ b/cli/internal/state/BUILD.bazel @@ -11,10 +11,12 @@ go_library( visibility = ["//cli:__subpackages__"], deps = [ "//internal/cloud/cloudprovider", + "//internal/constants", "//internal/file", "//internal/validation", "@cat_dario_mergo//:mergo", "@com_github_siderolabs_talos_pkg_machinery//config/encoder", + "@org_golang_x_mod//semver", ], ) diff --git a/cli/internal/state/state.go b/cli/internal/state/state.go index 49e4cef0b96..cb080649376 100644 --- a/cli/internal/state/state.go +++ b/cli/internal/state/state.go @@ -20,8 +20,10 @@ 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/validation" + "golang.org/x/mod/semver" ) const ( @@ -555,6 +557,23 @@ 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. + if semver.Compare(constants.BinaryVersion().String(), "v2.13.0") != -1 { + if s.Infrastructure.InClusterEndpoint == "" { + s.Infrastructure.InClusterEndpoint = s.Infrastructure.ClusterEndpoint + } + if s.Infrastructure.IPCidrNode == "" { + s.Infrastructure.IPCidrNode = "192.168.2.1" + } + } + return nil +} + // HexBytes is a byte slice that is marshalled to and from a hex string. type HexBytes []byte