mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-07 16:27:27 +00:00
Merge pull request #5560 from fluxcd/fix-migrate-files
Fix `flux migrate -f` command to work with comments
This commit is contained in:
commit
333c8fe704
4 changed files with 21 additions and 5 deletions
|
|
@ -157,7 +157,7 @@ The command has two modes of operation:
|
||||||
# Simulate the migration without making any changes.
|
# Simulate the migration without making any changes.
|
||||||
flux migrate -f . --dry-run
|
flux migrate -f . --dry-run
|
||||||
|
|
||||||
# Run the migration by skipping confirmation prompts.
|
# Run the migration skipping confirmation prompts.
|
||||||
flux migrate -f . --yes
|
flux migrate -f . --yes
|
||||||
`,
|
`,
|
||||||
RunE: runMigrateCmd,
|
RunE: runMigrateCmd,
|
||||||
|
|
@ -177,7 +177,7 @@ func init() {
|
||||||
migrateCmd.Flags().StringVarP(&migrateFlags.path, "path", "f", "",
|
migrateCmd.Flags().StringVarP(&migrateFlags.path, "path", "f", "",
|
||||||
"the path to the directory containing the manifests to migrate")
|
"the path to the directory containing the manifests to migrate")
|
||||||
migrateCmd.Flags().StringSliceVarP(&migrateFlags.extensions, "extensions", "e", []string{".yaml", ".yml"},
|
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", "",
|
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)")
|
"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,
|
migrateCmd.Flags().BoolVarP(&migrateFlags.yes, "yes", "y", false,
|
||||||
|
|
@ -605,7 +605,8 @@ func (f *FileSystemMigrator) detectFileUpgrades(file string) ([]APIUpgrade, erro
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
continue
|
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)
|
gv, err := schema.ParseGroupVersion(apiVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warningf("%s:%d: %v", file, line+1, err)
|
logger.Warningf("%s:%d: %v", file, line+1, err)
|
||||||
|
|
@ -669,7 +670,7 @@ func (f *FileSystemMigrator) migrateFile(fileUpgrades *FileAPIUpgrades) error {
|
||||||
// Apply upgrades to lines.
|
// Apply upgrades to lines.
|
||||||
for _, upgrade := range fileUpgrades.Upgrades {
|
for _, upgrade := range fileUpgrades.Upgrades {
|
||||||
line := lines[upgrade.Line]
|
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
|
lines[upgrade.Line] = line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,13 @@ kind: ImageRepository
|
||||||
apiVersion: image.toolkit.fluxcd.io/v1
|
apiVersion: image.toolkit.fluxcd.io/v1
|
||||||
kind: ImagePolicy
|
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
|
⚠️ 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.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-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:1: ImageRepository v1beta1 -> v1
|
||||||
✚ testdata/migrate/file-system/dir/some-file.yaml:7: ImagePolicy v1beta2 -> 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: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:3: ImageRepository v1beta2 -> v1
|
||||||
✚ testdata/migrate/file-system/dir/some-file.yml:9: ImagePolicy v1beta1 -> 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
|
apiVersion: image.toolkit.fluxcd.io/v1beta2
|
||||||
kind: ImagePolicy
|
kind: ImagePolicy
|
||||||
|
|
||||||
|
---
|
||||||
|
spec:
|
||||||
|
wait: true
|
||||||
|
dependsOn:
|
||||||
|
- apiVersion: image.toolkit.fluxcd.io/v1beta1 # update this from v1beta1
|
||||||
|
kind: ImageRepository
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue