Skip to content

Commit

Permalink
Merge pull request #2111 from hidalgopl/fix-vcluster-convert-config-a…
Browse files Browse the repository at this point in the history
…lready-migrated

fallback to checking if config is in correct format
  • Loading branch information
FabianKramm authored Sep 5, 2024
2 parents ac9f321 + 8caf63e commit 39c1444
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
14 changes: 14 additions & 0 deletions config/legacyconfig/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func migrateK8sAndEKS(oldValues string, newConfig *config.Config) error {
oldConfig := &LegacyK8s{}
err := oldConfig.UnmarshalYAMLStrict([]byte(oldValues))
if err != nil {
if err := errIfConfigIsAlreadyConverted(oldValues); err != nil {
return err
}
return fmt.Errorf("unmarshal legacy config: %w", err)
}

Expand Down Expand Up @@ -91,6 +94,9 @@ func migrateK3sAndK0s(distro, oldValues string, newConfig *config.Config) error
oldConfig := &LegacyK0sAndK3s{}
err := oldConfig.UnmarshalYAMLStrict([]byte(oldValues))
if err != nil {
if err := errIfConfigIsAlreadyConverted(oldValues); err != nil {
return err
}
return fmt.Errorf("unmarshal legacy config: %w", err)
}

Expand Down Expand Up @@ -136,6 +142,14 @@ func migrateK3sAndK0s(distro, oldValues string, newConfig *config.Config) error
return convertBaseValues(oldConfig.BaseHelm, newConfig)
}

func errIfConfigIsAlreadyConverted(oldValues string) error {
currentConfig := &config.Config{}
if err := currentConfig.UnmarshalYAMLStrict([]byte(oldValues)); err == nil {
return fmt.Errorf("config is already in correct format")
}
return nil
}

func convertEtcd(oldConfig EtcdValues, newConfig *config.Config) error {
if oldConfig.Disabled {
newConfig.ControlPlane.BackingStore.Etcd.Deploy.StatefulSet.Enabled = false
Expand Down
44 changes: 44 additions & 0 deletions config/legacyconfig/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,50 @@ policies:
podManagementPolicy: OrderedReady`,
ExpectedErr: "",
},
{
Name: "k3s already migrated to correct format",
Distro: "k3s",
In: `sync:
fromHost:
nodes:
enabled: false
toHost:
serviceAccounts:
enabled: false
controlPlane:
distro:
k3s:
enabled: true
image:
tag: v1.30.2-k3s2
statefulSet:
scheduling:
podManagementPolicy: OrderedReady
`,
ExpectedErr: "migrate legacy k3s values: config is already in correct format",
},
{
Name: "k8s already migrated to correct format",
Distro: "k8s",
In: `sync:
fromHost:
nodes:
enabled: false
toHost:
serviceAccounts:
enabled: false
controlPlane:
distro:
k8s:
enabled: true
statefulSet:
scheduling:
podManagementPolicy: OrderedReady
`,
ExpectedErr: "migrate legacy k8s values: config is already in correct format",
},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit 39c1444

Please sign in to comment.