Skip to content

Commit

Permalink
fixed issue with eks migration
Browse files Browse the repository at this point in the history
  • Loading branch information
facchettos committed Jul 25, 2024
1 parent ff981ca commit 2f9c628
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/vclusterctl/cmd/convert/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (cmd *configCmd) Run() error {
)

if cmd.distro == "" {
return fmt.Errorf("no distro given: please set \"--distro\" (IMPORTANT: distro must match the given config values)")
return fmt.Errorf("no distro given: please set \"--distro\" (IMPORTANT: distro must match the given config values, or be \"k8s\" if you are migrating from eks distro)")
}

if cmd.filePath != "" {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func ValidateChanges(oldCfg, newCfg *Config) error {

// ValidateStoreAndDistroChanges checks whether migrating from one store to the other is allowed.
func ValidateStoreAndDistroChanges(currentStoreType, previousStoreType StoreType, currentDistro, previousDistro string) error {
if currentDistro != previousDistro {
if currentDistro != previousDistro && !(previousDistro == "eks" && currentDistro == K8SDistro) {
return fmt.Errorf("seems like you were using %s as a distro before and now have switched to %s, please make sure to not switch between vCluster distros", previousDistro, currentDistro)
}

Expand Down
21 changes: 7 additions & 14 deletions config/legacyconfig/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,30 @@ func MigrateLegacyConfig(distro, oldValues string) (string, error) {
if err != nil {
return "", fmt.Errorf("migrate legacy %s values: %w", distro, err)
}
case config.K8SDistro:
err = migrateK8sAndEKS(distro, oldValues, toConfig)
case config.K8SDistro, "eks":
err = migrateK8sAndEKS(oldValues, toConfig)
if err != nil {
return "", fmt.Errorf("migrate legacy %s values: %w", distro, err)
}
default:
if distro == "eks" {
return "", fmt.Errorf("eks distro is not supported anymore. Instead use the k8s distro with the eks images")
}

return "", fmt.Errorf("migrating distro %s is not supported", distro)
}

return config.Diff(fromConfig, toConfig)
}

func migrateK8sAndEKS(distro, oldValues string, newConfig *config.Config) error {
func migrateK8sAndEKS(oldValues string, newConfig *config.Config) error {
// unmarshal legacy config
oldConfig := &LegacyK8s{}
err := oldConfig.UnmarshalYAMLStrict([]byte(oldValues))
if err != nil {
return fmt.Errorf("unmarshal legacy config: %w", err)
}

// k8s specific
if distro == config.K8SDistro {
newConfig.ControlPlane.Distro.K8S.Enabled = true
convertAPIValues(oldConfig.API, &newConfig.ControlPlane.Distro.K8S.APIServer)
convertControllerValues(oldConfig.Controller, &newConfig.ControlPlane.Distro.K8S.ControllerManager)
convertSchedulerValues(oldConfig.Scheduler, &newConfig.ControlPlane.Distro.K8S.Scheduler)
}
newConfig.ControlPlane.Distro.K8S.Enabled = true
convertAPIValues(oldConfig.API, &newConfig.ControlPlane.Distro.K8S.APIServer)
convertControllerValues(oldConfig.Controller, &newConfig.ControlPlane.Distro.K8S.ControllerManager)
convertSchedulerValues(oldConfig.Scheduler, &newConfig.ControlPlane.Distro.K8S.Scheduler)

// convert etcd
err = convertEtcd(oldConfig.Etcd, newConfig)
Expand Down

0 comments on commit 2f9c628

Please sign in to comment.