diff --git a/cmd/flux/migrate.go b/cmd/flux/migrate.go index 3a0129ce..7beba3c7 100644 --- a/cmd/flux/migrate.go +++ b/cmd/flux/migrate.go @@ -157,7 +157,7 @@ The command has two modes of operation: # Simulate the migration without making any changes. flux migrate -f . --dry-run - # Run the migration by skipping confirmation prompts. + # Run the migration skipping confirmation prompts. flux migrate -f . --yes `, RunE: runMigrateCmd, @@ -177,7 +177,7 @@ func init() { migrateCmd.Flags().StringVarP(&migrateFlags.path, "path", "f", "", "the path to the directory containing the manifests to migrate") migrateCmd.Flags().StringSliceVarP(&migrateFlags.extensions, "extensions", "e", []string{".yaml", ".yml"}, - "the file extensions to consider when migrating manifests, only applicable --path") + "the file extensions to consider when migrating manifests, only applicable with --path") migrateCmd.Flags().StringVarP(&migrateFlags.version, "version", "v", "", "the target Flux minor version to migrate manifests to, only applicable with --path (defaults to the version of the CLI)") migrateCmd.Flags().BoolVarP(&migrateFlags.yes, "yes", "y", false, @@ -605,7 +605,8 @@ func (f *FileSystemMigrator) detectFileUpgrades(file string) ([]APIUpgrade, erro if idx == -1 { continue } - apiVersion := strings.TrimSpace(apiVersionLine[idx+len(apiVersionPrefix):]) + apiVersionValuePrefix := strings.TrimSpace(apiVersionLine[idx+len(apiVersionPrefix):]) + apiVersion := strings.Split(apiVersionValuePrefix, " ")[0] gv, err := schema.ParseGroupVersion(apiVersion) if err != nil { logger.Warningf("%s:%d: %v", file, line+1, err) @@ -669,7 +670,7 @@ func (f *FileSystemMigrator) migrateFile(fileUpgrades *FileAPIUpgrades) error { // Apply upgrades to lines. for _, upgrade := range fileUpgrades.Upgrades { line := lines[upgrade.Line] - line = strings.ReplaceAll(line, upgrade.OldVersion, upgrade.NewVersion) + line = strings.Replace(line, upgrade.OldVersion, upgrade.NewVersion, 1) lines[upgrade.Line] = line } diff --git a/cmd/flux/testdata/migrate/file-system/dir.golden/some-file.yaml b/cmd/flux/testdata/migrate/file-system/dir.golden/some-file.yaml index 011a7ffe..8b8ed51b 100644 --- a/cmd/flux/testdata/migrate/file-system/dir.golden/some-file.yaml +++ b/cmd/flux/testdata/migrate/file-system/dir.golden/some-file.yaml @@ -7,6 +7,13 @@ kind: ImageRepository apiVersion: image.toolkit.fluxcd.io/v1 kind: ImagePolicy +--- +spec: + wait: true + dependsOn: + - apiVersion: image.toolkit.fluxcd.io/v1 # update this from v1beta1 + kind: ImageRepository + --- diff --git a/cmd/flux/testdata/migrate/file-system/dir.output.golden b/cmd/flux/testdata/migrate/file-system/dir.output.golden index ecd7885b..ab536652 100644 --- a/cmd/flux/testdata/migrate/file-system/dir.output.golden +++ b/cmd/flux/testdata/migrate/file-system/dir.output.golden @@ -3,9 +3,10 @@ ⚠️ skipping irregular file testdata/migrate/file-system/dir/some-file-link.yaml ✚ testdata/migrate/file-system/dir/some-dir/another-file.yaml:2: ImageUpdateAutomation v1beta2 -> v1 ✚ testdata/migrate/file-system/dir/some-dir/another-file.yml:3: ImageUpdateAutomation v1beta2 -> v1 -⚠️ testdata/migrate/file-system/dir/some-file.yaml:13: unexpected GroupVersion string: image.toolkit.fluxcd.io/v1/v2 +⚠️ testdata/migrate/file-system/dir/some-file.yaml:20: unexpected GroupVersion string: image.toolkit.fluxcd.io/v1/v2 ✚ testdata/migrate/file-system/dir/some-file.yaml:1: ImageRepository v1beta1 -> v1 ✚ testdata/migrate/file-system/dir/some-file.yaml:7: ImagePolicy v1beta2 -> v1 +✚ testdata/migrate/file-system/dir/some-file.yaml:14: ImageRepository v1beta1 -> v1 ⚠️ testdata/migrate/file-system/dir/some-file.yml:15: unexpected GroupVersion string: image.toolkit.fluxcd.io/v1/v2 ✚ testdata/migrate/file-system/dir/some-file.yml:3: ImageRepository v1beta2 -> v1 ✚ testdata/migrate/file-system/dir/some-file.yml:9: ImagePolicy v1beta1 -> v1 diff --git a/cmd/flux/testdata/migrate/file-system/dir/some-file.yaml b/cmd/flux/testdata/migrate/file-system/dir/some-file.yaml index 3dc8c492..a8b2be01 100644 --- a/cmd/flux/testdata/migrate/file-system/dir/some-file.yaml +++ b/cmd/flux/testdata/migrate/file-system/dir/some-file.yaml @@ -7,6 +7,13 @@ kind: ImageRepository apiVersion: image.toolkit.fluxcd.io/v1beta2 kind: ImagePolicy +--- +spec: + wait: true + dependsOn: + - apiVersion: image.toolkit.fluxcd.io/v1beta1 # update this from v1beta1 + kind: ImageRepository + ---