Skip to content

Commit 68e2037

Browse files
committed
Add LCOW live migration source and destination pathways
Introduce an end-to-end live-migration workflow for LCOW sandboxes, letting a running sandbox be handed off from a source shim to a destination shim. - Add a migration Controller that sequences a single session through a source or destination lifecycle: the source prepares and exports an opaque sandbox snapshot (VM + per-pod state), while the destination imports it, patches each container onto its new IDs, builds the destination VM, transfers memory over a shared socket, and finalizes with a resume or stop. - Expose the migration gRPC/ttrpc surface on the LCOW shim service (PrepareAndExportSandbox, ImportSandbox, PrepareSandbox, TransferSandbox, FinalizeSandbox, Cancel, Cleanup, CreateDuplicateSocket, Notifications) and register it alongside the task and sandbox services. - Wire migration into the task lifecycle: route destination-side CreateTask for rehydrated containers into a patch path, and reject task mutations (state, delete, kill) while a session is in progress. - Add duplicated transport-socket adoption, a subscriber-based progress notification stream, and proto/HCS conversion helpers for migration options and events. Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
1 parent 41c7620 commit 68e2037

24 files changed

Lines changed: 4496 additions & 32 deletions

‎cmd/containerd-shim-lcow-v2/service/mocks/mock_service.go‎

Lines changed: 165 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cmd/containerd-shim-lcow-v2/service/service.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"fmt"
88
"sync"
99

10+
"github.com/Microsoft/hcsshim/internal/controller/migration"
1011
"github.com/Microsoft/hcsshim/internal/controller/pod"
1112
"github.com/Microsoft/hcsshim/internal/controller/vm"
1213
"github.com/Microsoft/hcsshim/internal/log"
1314
"github.com/Microsoft/hcsshim/internal/shim"
1415
"github.com/Microsoft/hcsshim/internal/shimdiag"
16+
migrationsvc "github.com/Microsoft/hcsshim/pkg/migration"
1517

1618
sandboxsvc "github.com/containerd/containerd/api/runtime/sandbox/v1"
1719
tasksvc "github.com/containerd/containerd/api/runtime/task/v3"
@@ -54,6 +56,10 @@ type Service struct {
5456
// from podControllers.
5557
containerPodMapping map[string]string
5658

59+
// migrationController orchestrates the live-migration session for the
60+
// sandbox. There is at most one active session per shim.
61+
migrationController *migration.Controller
62+
5763
// shutdown manages graceful shutdown operations and allows registration of cleanup callbacks.
5864
shutdown shutdown.Service
5965
}
@@ -68,6 +74,7 @@ func NewService(ctx context.Context, eventsPublisher shim.Publisher, sd shutdown
6874
vmController: vm.New(),
6975
podControllers: make(map[string]*pod.Controller),
7076
containerPodMapping: make(map[string]string),
77+
migrationController: migration.New(),
7178
shutdown: sd,
7279
}
7380

@@ -95,6 +102,7 @@ func (s *Service) RegisterTTRPC(server *ttrpc.Server) error {
95102
tasksvc.RegisterTTRPCTaskService(server, s)
96103
sandboxsvc.RegisterTTRPCSandboxService(server, s)
97104
shimdiag.RegisterShimDiagService(server, s)
105+
migrationsvc.RegisterMigrationService(server, s)
98106
return nil
99107
}
100108

@@ -106,6 +114,14 @@ func (s *Service) ensureVMRunning() error {
106114
return nil
107115
}
108116

117+
// ensureMigrationIdle returns an error if a migration session is in progress.
118+
func (s *Service) ensureMigrationIdle() error {
119+
if state := s.migrationController.State(); state != migration.StateIdle {
120+
return fmt.Errorf("migration session is in progress (state: %s): %w", state, errdefs.ErrFailedPrecondition)
121+
}
122+
return nil
123+
}
124+
109125
// SandboxID returns the unique identifier for the sandbox managed by this Service.
110126
func (s *Service) SandboxID() string {
111127
return s.sandboxID

0 commit comments

Comments
 (0)