From 919d5bfa67be98e1644302f02fa1d5905f77e1f6 Mon Sep 17 00:00:00 2001 From: joshsiv-mulga Date: Fri, 9 Oct 2026 11:22:40 +1000 Subject: [PATCH] refactor: move config and object-store upgrade workflow to operator/upgrade Relocate spinifex/migrate, the operator-driven config-file and object-store upgrade workflow behind spx admin upgrade, to operator/upgrade. Package renamed to upgrade (imported as opupgrade where a local upgrade identifier exists). It stays distinct from foundation/state/migrate, the generic KV migration engine; no registry types, migration names, versions, file formats or command names change. --- scripts/diff-coverage.sh | 2 +- spinifex/operator/cli/admin_upgrade.go | 12 ++++++------ spinifex/operator/cli/admin_upgrade_test.go | 8 ++++---- spinifex/{migrate => operator/upgrade}/VERSIONS.md | 4 ++-- spinifex/{migrate => operator/upgrade}/migrate.go | 4 ++-- .../{migrate => operator/upgrade}/migrate_test.go | 2 +- .../{migrate => operator/upgrade}/version_readers.go | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) rename spinifex/{migrate => operator/upgrade}/VERSIONS.md (94%) rename spinifex/{migrate => operator/upgrade}/migrate.go (99%) rename spinifex/{migrate => operator/upgrade}/migrate_test.go (99%) rename spinifex/{migrate => operator/upgrade}/version_readers.go (99%) diff --git a/scripts/diff-coverage.sh b/scripts/diff-coverage.sh index ace344472..791c82dbd 100755 --- a/scripts/diff-coverage.sh +++ b/scripts/diff-coverage.sh @@ -73,7 +73,7 @@ trap 'rm -rf "$TMPDIR"' EXIT # internal/testkit is excluded because it is fakes and harnesses used only from # _test.go files. Coverage is recorded per package under test, so a fake another # package's tests drive reads as zero-covered however hard it is exercised. -git diff "${BASE_REF}" HEAD --unified=0 -M -C --diff-filter=AM -- '*.go' ':!*_test.go' ':!spinifex/migrate/*' ':!spinifex/operator/installer/ui/*' ':!internal/testkit/*' | awk ' +git diff "${BASE_REF}" HEAD --unified=0 -M -C --diff-filter=AM -- '*.go' ':!*_test.go' ':!spinifex/operator/upgrade/*' ':!spinifex/operator/installer/ui/*' ':!internal/testkit/*' | awk ' /^\+\+\+ / { file = substr($2, 3) next diff --git a/spinifex/operator/cli/admin_upgrade.go b/spinifex/operator/cli/admin_upgrade.go index ba1d67bab..f68efd30c 100644 --- a/spinifex/operator/cli/admin_upgrade.go +++ b/spinifex/operator/cli/admin_upgrade.go @@ -7,8 +7,8 @@ import ( "os" "strings" - "github.com/mulgadc/spinifex/spinifex/migrate" "github.com/mulgadc/spinifex/spinifex/operator/host/systemd" + "github.com/mulgadc/spinifex/spinifex/operator/upgrade" "github.com/spf13/cobra" ) @@ -92,7 +92,7 @@ func runAdminUpgrade(cmd *cobra.Command, _ []string) { upgradeExit(1) } - var pending []migrate.PendingMigration + var pending []upgrade.PendingMigration if !unitsOnly { pending = reportConfigStatus(configDir) } @@ -131,7 +131,7 @@ func runAdminUpgrade(cmd *cobra.Command, _ []string) { } if hasConfigWork { - if err := migrate.DefaultRegistry.RunAllConfig(configDir, dataDir); err != nil { + if err := upgrade.DefaultRegistry.RunAllConfig(configDir, dataDir); err != nil { fmt.Fprintf(os.Stderr, "Config migration failed: %v\n", err) upgradeExit(1) } @@ -155,8 +155,8 @@ func runAdminUpgrade(cmd *cobra.Command, _ []string) { // reportConfigStatus prints current config versions and pending migrations, // mirroring the pre-existing `spx admin upgrade` output. -func reportConfigStatus(configDir string) []migrate.PendingMigration { - versions, err := migrate.DefaultRegistry.ConfigVersions(configDir) +func reportConfigStatus(configDir string) []upgrade.PendingMigration { + versions, err := upgrade.DefaultRegistry.ConfigVersions(configDir) if err != nil { fmt.Fprintf(os.Stderr, "Error reading config versions: %v\n", err) upgradeExit(1) @@ -171,7 +171,7 @@ func reportConfigStatus(configDir string) []migrate.PendingMigration { } } - pending, err := migrate.DefaultRegistry.PendingConfig(configDir) + pending, err := upgrade.DefaultRegistry.PendingConfig(configDir) if err != nil { fmt.Fprintf(os.Stderr, "Error checking pending migrations: %v\n", err) upgradeExit(1) diff --git a/spinifex/operator/cli/admin_upgrade_test.go b/spinifex/operator/cli/admin_upgrade_test.go index d462aca73..bbce04d22 100644 --- a/spinifex/operator/cli/admin_upgrade_test.go +++ b/spinifex/operator/cli/admin_upgrade_test.go @@ -7,8 +7,8 @@ import ( "path/filepath" "testing" - "github.com/mulgadc/spinifex/spinifex/migrate" "github.com/mulgadc/spinifex/spinifex/operator/host/systemd" + opupgrade "github.com/mulgadc/spinifex/spinifex/operator/upgrade" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -29,11 +29,11 @@ func TestUpgradeSeesEveryConfigTarget(t *testing.T) { require.NoError(t, os.WriteFile(filepath.Join(configDir, "spinifex.toml"), []byte("version = \"4\"\n"), 0640)) require.NoError(t, os.WriteFile(filepath.Join(configDir, "predastore", "predastore.toml"), []byte("version = 1\n"), 0640)) - versions, err := migrate.DefaultRegistry.ConfigVersions(configDir) + versions, err := opupgrade.DefaultRegistry.ConfigVersions(configDir) require.NoError(t, err) assert.Equal(t, map[string]int{"spinifex.toml": 4}, versions) - pending, err := migrate.DefaultRegistry.PendingConfig(configDir) + pending, err := opupgrade.DefaultRegistry.PendingConfig(configDir) require.NoError(t, err) assert.Empty(t, pending) } @@ -127,7 +127,7 @@ func TestReportConfigStatus_NoPendingMigrations(t *testing.T) { configDir := t.TempDir() require.NoError(t, os.WriteFile(filepath.Join(configDir, "spinifex.toml"), []byte("version = \"4\"\n"), 0640)) - var pending []migrate.PendingMigration + var pending []opupgrade.PendingMigration out := captureStdout(t, func() { pending = reportConfigStatus(configDir) }) assert.Empty(t, pending) diff --git a/spinifex/migrate/VERSIONS.md b/spinifex/operator/upgrade/VERSIONS.md similarity index 94% rename from spinifex/migrate/VERSIONS.md rename to spinifex/operator/upgrade/VERSIONS.md index 0146ae3ba..598341424 100644 --- a/spinifex/migrate/VERSIONS.md +++ b/spinifex/operator/upgrade/VERSIONS.md @@ -48,9 +48,9 @@ Every other bucket has no registered migration, so `RunKV` stamps its target ver ## Where migrations live -Register a `ConfigMigration` against `DefaultRegistry` in a new numbered file under `spinifex/migrate/`, and bump the version in both the template and the table above. +Register a `ConfigMigration` against `DefaultRegistry` in a new numbered file under `spinifex/operator/upgrade/`, and bump the version in both the template and the table above. -A KV migration goes in the package that owns the bucket instead, next to the constant it bumps — `migrate` cannot import the record types it would have to decode. `daemon/instance_records_migrate.go` is the worked example. +A KV migration goes in the package that owns the bucket instead, next to the constant it bumps — `operator/upgrade` cannot import the record types it would have to decode. `daemon/instance_records_migrate.go` is the worked example. For worked examples of the config and object-store kinds, read the deleted files out of git history: diff --git a/spinifex/migrate/migrate.go b/spinifex/operator/upgrade/migrate.go similarity index 99% rename from spinifex/migrate/migrate.go rename to spinifex/operator/upgrade/migrate.go index f38976bd1..9fdf90ca4 100644 --- a/spinifex/migrate/migrate.go +++ b/spinifex/operator/upgrade/migrate.go @@ -1,6 +1,6 @@ -// Package migrate runs versioned migrations over NATS KV buckets, on-disk +// Package upgrade runs versioned migrations over NATS KV buckets, on-disk // config files and object-store data, recording each target's schema version. -package migrate +package upgrade import ( "context" diff --git a/spinifex/migrate/migrate_test.go b/spinifex/operator/upgrade/migrate_test.go similarity index 99% rename from spinifex/migrate/migrate_test.go rename to spinifex/operator/upgrade/migrate_test.go index 7663b3905..378398e64 100644 --- a/spinifex/migrate/migrate_test.go +++ b/spinifex/operator/upgrade/migrate_test.go @@ -1,4 +1,4 @@ -package migrate +package upgrade import ( "errors" diff --git a/spinifex/migrate/version_readers.go b/spinifex/operator/upgrade/version_readers.go similarity index 99% rename from spinifex/migrate/version_readers.go rename to spinifex/operator/upgrade/version_readers.go index 748b6ad4e..79b49c17c 100644 --- a/spinifex/migrate/version_readers.go +++ b/spinifex/operator/upgrade/version_readers.go @@ -1,4 +1,4 @@ -package migrate +package upgrade import ( "fmt"