Fix migrate -f command to work with comments

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
(cherry picked from commit 83213ce83f)
pull/5561/head
Matheus Pimenta 1 week ago committed by github-actions[bot]
parent 4accd37c1a
commit a2ff6c601e

@ -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
}

@ -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
---

@ -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

@ -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
---

Loading…
Cancel
Save