Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 165 additions & 5 deletions cmd/containerd-shim-lcow-v2/service/mocks/mock_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions cmd/containerd-shim-lcow-v2/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"fmt"
"sync"

"github.com/Microsoft/hcsshim/internal/controller/migration"
"github.com/Microsoft/hcsshim/internal/controller/pod"
"github.com/Microsoft/hcsshim/internal/controller/vm"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/shim"
"github.com/Microsoft/hcsshim/internal/shimdiag"
migrationsvc "github.com/Microsoft/hcsshim/pkg/migration"

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

// migrationController orchestrates the live-migration session for the
// sandbox. There is at most one active session per shim.
migrationController *migration.Controller

// shutdown manages graceful shutdown operations and allows registration of cleanup callbacks.
shutdown shutdown.Service
}
Expand All @@ -68,6 +74,7 @@ func NewService(ctx context.Context, eventsPublisher shim.Publisher, sd shutdown
vmController: vm.New(),
podControllers: make(map[string]*pod.Controller),
containerPodMapping: make(map[string]string),
migrationController: migration.New(),
shutdown: sd,
}

Expand Down Expand Up @@ -95,6 +102,7 @@ func (s *Service) RegisterTTRPC(server *ttrpc.Server) error {
tasksvc.RegisterTTRPCTaskService(server, s)
sandboxsvc.RegisterTTRPCSandboxService(server, s)
shimdiag.RegisterShimDiagService(server, s)
migrationsvc.RegisterMigrationService(server, s)
return nil
}

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

// ensureMigrationIdle returns an error if a migration session is in progress.
func (s *Service) ensureMigrationIdle() error {
if state := s.migrationController.State(); state != migration.StateIdle {
return fmt.Errorf("migration session is in progress (state: %s): %w", state, errdefs.ErrFailedPrecondition)
}
return nil
}

// SandboxID returns the unique identifier for the sandbox managed by this Service.
func (s *Service) SandboxID() string {
return s.sandboxID
Expand Down
Loading
Loading