mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 09:01:31 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
@@ -1,4 +1,4 @@
|
||||
package migrate
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -1,4 +1,4 @@
|
||||
package migrate
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
Reference in New Issue
Block a user