Skip to content

Commit d62db24

Browse files
committed
feat: resource state versioning
Adds a system to version resource states and to migrate them to newer versions. These migrations run when the server starts as well as when they're retrieved from storage in order to handle cases where different server versions are started simultaneously.
1 parent 377415a commit d62db24

22 files changed

Lines changed: 3456 additions & 4 deletions

server/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/pgEdge/control-plane/server/internal/orchestrator/swarm"
2626
"github.com/pgEdge/control-plane/server/internal/ports"
2727
"github.com/pgEdge/control-plane/server/internal/resource"
28+
"github.com/pgEdge/control-plane/server/internal/resource/migrations"
2829
"github.com/pgEdge/control-plane/server/internal/scheduler"
2930
"github.com/pgEdge/control-plane/server/internal/task"
3031
"github.com/pgEdge/control-plane/server/internal/workflows"
@@ -79,6 +80,7 @@ func newRootCmd(i *do.Injector) *cobra.Command {
7980
monitor.Provide(i)
8081
ports.Provide(i)
8182
resource.Provide(i)
83+
migrations.Provide(i)
8284
scheduler.Provide(i)
8385
workflows.Provide(i)
8486
activities.Provide(i)

server/internal/app/app.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/pgEdge/control-plane/server/internal/host"
1919
"github.com/pgEdge/control-plane/server/internal/migrate"
2020
"github.com/pgEdge/control-plane/server/internal/monitor"
21+
"github.com/pgEdge/control-plane/server/internal/resource"
2122
"github.com/pgEdge/control-plane/server/internal/scheduler"
2223
"github.com/pgEdge/control-plane/server/internal/workflows"
2324
)
@@ -173,6 +174,14 @@ func (a *App) runInitialized(parentCtx context.Context) error {
173174
return handleError(fmt.Errorf("failed to update host: %w", err))
174175
}
175176

177+
resourceSvc, err := do.Invoke[*resource.Service](a.i)
178+
if err != nil {
179+
return handleError(fmt.Errorf("failed to initialize resource service: %w", err))
180+
}
181+
if err := resourceSvc.Start(a.serviceCtx); err != nil {
182+
return handleError(fmt.Errorf("failed to start resource service: %w", err))
183+
}
184+
176185
hostTicker, err := do.Invoke[*host.UpdateTicker](a.i)
177186
if err != nil {
178187
return handleError(fmt.Errorf("failed to initialize host ticker: %w", err))

0 commit comments

Comments
 (0)