Skip to content

Commit a2ff6c6

Browse files
matheuscscpgithub-actions[bot]
authored andcommitted
Fix migrate -f command to work with comments
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com> (cherry picked from commit 83213ce)
1 parent 4accd37 commit a2ff6c6

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

cmd/flux/migrate.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ The command has two modes of operation:
157157
# Simulate the migration without making any changes.
158158
flux migrate -f . --dry-run
159159
160-
# Run the migration by skipping confirmation prompts.
160+
# Run the migration skipping confirmation prompts.
161161
flux migrate -f . --yes
162162
`,
163163
RunE: runMigrateCmd,
@@ -177,7 +177,7 @@ func init() {
177177
migrateCmd.Flags().StringVarP(&migrateFlags.path, "path", "f", "",
178178
"the path to the directory containing the manifests to migrate")
179179
migrateCmd.Flags().StringSliceVarP(&migrateFlags.extensions, "extensions", "e", []string{".yaml", ".yml"},
180-
"the file extensions to consider when migrating manifests, only applicable --path")
180+
"the file extensions to consider when migrating manifests, only applicable with --path")
181181
migrateCmd.Flags().StringVarP(&migrateFlags.version, "version", "v", "",
182182
"the target Flux minor version to migrate manifests to, only applicable with --path (defaults to the version of the CLI)")
183183
migrateCmd.Flags().BoolVarP(&migrateFlags.yes, "yes", "y", false,
@@ -605,7 +605,8 @@ func (f *FileSystemMigrator) detectFileUpgrades(file string) ([]APIUpgrade, erro
605605
if idx == -1 {
606606
continue
607607
}
608-
apiVersion := strings.TrimSpace(apiVersionLine[idx+len(apiVersionPrefix):])
608+
apiVersionValuePrefix := strings.TrimSpace(apiVersionLine[idx+len(apiVersionPrefix):])
609+
apiVersion := strings.Split(apiVersionValuePrefix, " ")[0]
609610
gv, err := schema.ParseGroupVersion(apiVersion)
610611
if err != nil {
611612
logger.Warningf("%s:%d: %v", file, line+1, err)
@@ -669,7 +670,7 @@ func (f *FileSystemMigrator) migrateFile(fileUpgrades *FileAPIUpgrades) error {
669670
// Apply upgrades to lines.
670671
for _, upgrade := range fileUpgrades.Upgrades {
671672
line := lines[upgrade.Line]
672-
line = strings.ReplaceAll(line, upgrade.OldVersion, upgrade.NewVersion)
673+
line = strings.Replace(line, upgrade.OldVersion, upgrade.NewVersion, 1)
673674
lines[upgrade.Line] = line
674675
}
675676

cmd/flux/testdata/migrate/file-system/dir.golden/some-file.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ kind: ImageRepository
77
apiVersion: image.toolkit.fluxcd.io/v1
88
kind: ImagePolicy
99

10+
---
11+
spec:
12+
wait: true
13+
dependsOn:
14+
- apiVersion: image.toolkit.fluxcd.io/v1 # update this from v1beta1
15+
kind: ImageRepository
16+
1017

1118
---
1219

cmd/flux/testdata/migrate/file-system/dir.output.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
⚠️ skipping irregular file testdata/migrate/file-system/dir/some-file-link.yaml
44
✚ testdata/migrate/file-system/dir/some-dir/another-file.yaml:2: ImageUpdateAutomation v1beta2 -> v1
55
✚ testdata/migrate/file-system/dir/some-dir/another-file.yml:3: ImageUpdateAutomation v1beta2 -> v1
6-
⚠️ testdata/migrate/file-system/dir/some-file.yaml:13: unexpected GroupVersion string: image.toolkit.fluxcd.io/v1/v2
6+
⚠️ testdata/migrate/file-system/dir/some-file.yaml:20: unexpected GroupVersion string: image.toolkit.fluxcd.io/v1/v2
77
✚ testdata/migrate/file-system/dir/some-file.yaml:1: ImageRepository v1beta1 -> v1
88
✚ testdata/migrate/file-system/dir/some-file.yaml:7: ImagePolicy v1beta2 -> v1
9+
✚ testdata/migrate/file-system/dir/some-file.yaml:14: ImageRepository v1beta1 -> v1
910
⚠️ testdata/migrate/file-system/dir/some-file.yml:15: unexpected GroupVersion string: image.toolkit.fluxcd.io/v1/v2
1011
✚ testdata/migrate/file-system/dir/some-file.yml:3: ImageRepository v1beta2 -> v1
1112
✚ testdata/migrate/file-system/dir/some-file.yml:9: ImagePolicy v1beta1 -> v1

cmd/flux/testdata/migrate/file-system/dir/some-file.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ kind: ImageRepository
77
apiVersion: image.toolkit.fluxcd.io/v1beta2
88
kind: ImagePolicy
99

10+
---
11+
spec:
12+
wait: true
13+
dependsOn:
14+
- apiVersion: image.toolkit.fluxcd.io/v1beta1 # update this from v1beta1
15+
kind: ImageRepository
16+
1017

1118
---
1219

0 commit comments

Comments
 (0)