Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to checking if config is in correct format #2111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading