-
Notifications
You must be signed in to change notification settings - Fork 281
[shimV2] implements task, shimdiag service and wires up pod/container controllers #2685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rawahars
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
rawahars:task_service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| //go:build windows | ||
| //go:build windows && lcow | ||
|
|
||
| package main | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,25 @@ | ||
| //go:build windows | ||
| //go:build windows && lcow | ||
|
|
||
| package service | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sync" | ||
|
|
||
| "github.com/Microsoft/hcsshim/internal/builder/vm/lcow" | ||
| "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" | ||
|
|
||
| sandboxsvc "github.com/containerd/containerd/api/runtime/sandbox/v1" | ||
| tasksvc "github.com/containerd/containerd/api/runtime/task/v3" | ||
| tasksvc "github.com/containerd/containerd/api/runtime/task/v2" | ||
| "github.com/containerd/containerd/v2/core/runtime" | ||
| "github.com/containerd/containerd/v2/pkg/namespaces" | ||
| "github.com/containerd/containerd/v2/pkg/shutdown" | ||
| "github.com/containerd/errdefs" | ||
| "github.com/containerd/ttrpc" | ||
| ) | ||
|
|
||
|
|
@@ -29,7 +32,7 @@ const ( | |
| // All Service methods (sandbox, task, and shimdiag) operate on this shared struct. | ||
| type Service struct { | ||
| // mu is used to synchronize access to shared state within the Service. | ||
| mu sync.Mutex | ||
| mu sync.RWMutex | ||
|
|
||
| // publisher is used to publish events from the shim to containerd. | ||
| publisher shim.Publisher | ||
|
|
@@ -45,7 +48,15 @@ type Service struct { | |
| sandboxOptions *lcow.SandboxOptions | ||
|
|
||
| // vmController is responsible for managing the lifecycle of the underlying utility VM and its associated resources. | ||
| vmController vm.Controller | ||
| vmController *vm.Controller | ||
|
|
||
| // podControllers maps podID -> PodController for each active pod. | ||
| podControllers map[string]*pod.Controller | ||
|
|
||
| // containerPodMapping maps containerID -> podID, allowing callers to look up | ||
| // which pod a container belongs to and then retrieve the corresponding controller | ||
| // from podControllers. | ||
| containerPodMapping map[string]string | ||
|
|
||
| // shutdown manages graceful shutdown operations and allows registration of cleanup callbacks. | ||
| shutdown shutdown.Service | ||
|
|
@@ -56,10 +67,12 @@ var _ shim.TTRPCService = (*Service)(nil) | |
| // NewService creates a new instance of the Service with the shared state. | ||
| func NewService(ctx context.Context, eventsPublisher shim.Publisher, sd shutdown.Service) *Service { | ||
| svc := &Service{ | ||
| publisher: eventsPublisher, | ||
| events: make(chan interface{}, 128), // Buffered channel for events | ||
| vmController: vm.NewController(), | ||
| shutdown: sd, | ||
| publisher: eventsPublisher, | ||
| events: make(chan interface{}, 128), // Buffered channel for events | ||
| vmController: vm.New(), | ||
| podControllers: make(map[string]*pod.Controller), | ||
| containerPodMapping: make(map[string]string), | ||
| shutdown: sd, | ||
| } | ||
|
|
||
| go svc.forward(ctx, eventsPublisher) | ||
|
|
@@ -83,23 +96,27 @@ func NewService(ctx context.Context, eventsPublisher shim.Publisher, sd shutdown | |
| // RegisterTTRPC registers the Task, Sandbox, and ShimDiag TTRPC services on | ||
| // the provided server so that containerd can call into the shim over TTRPC. | ||
| func (s *Service) RegisterTTRPC(server *ttrpc.Server) error { | ||
| tasksvc.RegisterTTRPCTaskService(server, s) | ||
| tasksvc.RegisterTaskService(server, s) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh? Doesnt this have to be ttrpc for contained? |
||
| sandboxsvc.RegisterTTRPCSandboxService(server, s) | ||
| shimdiag.RegisterShimDiagService(server, s) | ||
| return nil | ||
| } | ||
|
|
||
| // ensureVMRunning returns an error if the VM is not in the running state. | ||
| func (s *Service) ensureVMRunning() error { | ||
| if state := s.vmController.State(); state != vm.StateRunning { | ||
| return fmt.Errorf("vm is not running (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 | ||
| } | ||
|
|
||
| // send enqueues an event onto the internal events channel so that it can be | ||
| // forwarded to containerd asynchronously by the forward goroutine. | ||
| // | ||
| // TODO: wire up send() for task events once task lifecycle methods are implemented. | ||
| // | ||
| //nolint:unused | ||
| func (s *Service) send(evt interface{}) { | ||
| s.events <- evt | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| //go:build windows | ||
| //go:build windows && lcow | ||
|
|
||
| package service | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter what version?