Skip to content

guest: unify pod model for V1, virtual pod, and V2 shim support#2699

Merged
shreyanshjain7174 merged 5 commits into
microsoft:mainfrom
shreyanshjain7174:guest-pod-unification-v2
May 13, 2026
Merged

guest: unify pod model for V1, virtual pod, and V2 shim support#2699
shreyanshjain7174 merged 5 commits into
microsoft:mainfrom
shreyanshjain7174:guest-pod-unification-v2

Conversation

@shreyanshjain7174
Copy link
Copy Markdown
Contributor

@shreyanshjain7174 shreyanshjain7174 commented Apr 22, 2026

The GCS guest runtime (internal/guest/runtime/hcsv2/uvm.go) tracks virtual pods separately from V1 sandbox containers — a dedicated VirtualPod type, seven exported methods, a parent cgroup manager, and a reverse-lookup map. V1 sandboxes have no pod-level tracking at all. Adding V2 shim support would need a third path.

This collapses all three into one: a private uvmPod type and a single pods map on Host. Every sandbox — V1, virtual pod, or V2 shim — goes through createPodInUVM, which allocates a cgroup under /pods/{sandboxID}. Workload containers nest at /pods/{sandboxID}/{containerID}. Container-to-pod membership is tracked via addContainerToPod. Cleanup in RemoveContainer is a single code path: remove the container from the pod, and when the sandbox container itself is removed, delete the pod's cgroup.

Cgroup hierarchy changes from:

/containers/{id}                         (V1 sandbox)
/containers/virtual-pods/{virtualPodID}  (virtual pod)

to:

/pods/{sandboxID}                        (all pod types)
/pods/{sandboxID}/{containerID}          (workload containers)

Standalone (non-CRI) containers keep their own cgroup at /pods/{id} with no pod entry — same isolation as before, just under the new prefix.

Network namespace teardown for virtual pod sandboxes is preserved: RemoveContainer skips RemoveNetworkNamespace for virtual pod sandbox containers since the host-driven path (TearDownNetworkingRemoveNetNSremoveNIC) handles adapter removal first.

cmd/gcs/main.go replaces the /containers/virtual-pods parent cgroup with /pods and drops the InitializeVirtualPodSupport call.

Tested E2E with both shims:

V1 shim (io.containerd.runhcs.v1) V2 shim (io.containerd.lcow.v2)
OCIBundlePath /run/gcs/c/<podId> /run/gcs/pods/<podId>/<podId>
Pod cgroup /sys/fs/cgroup/memory/pods/<podId> /sys/fs/cgroup/memory/pods/<podId>
/containers/virtual-pods/ absent absent

Comment thread cmd/gcs/main.go Outdated
Comment thread cmd/gcs/main.go Outdated
Comment thread cmd/gcs/main.go Outdated
Comment thread cmd/gcs/main.go Outdated
Comment thread internal/guest/runtime/hcsv2/container.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/workload_container.go
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go
@rawahars rawahars requested a review from helsaawy May 4, 2026 06:35
@shreyanshjain7174 shreyanshjain7174 force-pushed the guest-pod-unification-v2 branch from ad3ee5f to f51f773 Compare May 4, 2026 06:46
@shreyanshjain7174 shreyanshjain7174 requested a review from rawahars May 4, 2026 07:54
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Replace the separate VirtualPod tracking (dedicated type, exported
methods, parent cgroup manager, reverse-lookup map) with a unified
uvmPod type and a single pods map on Host. All pod types (V1 sandbox,
virtual pod, V2 shim) now go through the same code path:

- createPodInUVM allocates a cgroup under /pods/{sandboxID}
- RemoveContainer handles cleanup uniformly

Cgroup hierarchy changes from:
  /containers/{id}                         (V1 sandbox)
  /containers/virtual-pods/{virtualPodID}  (virtual pod)
to:
  /pods/{sandboxID}                        (all pod types)
  /pods/{sandboxID}/{containerID}          (workload containers)

Signed-off-by: Shreyansh Jain <shreyanshjain7174@gmail.com>
Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
@shreyanshjain7174 shreyanshjain7174 force-pushed the guest-pod-unification-v2 branch from f51f773 to 32802d9 Compare May 4, 2026 11:22
@shreyanshjain7174 shreyanshjain7174 requested a review from rawahars May 4, 2026 11:29
…ID assign

- Lock containersMutex over the entire createPodInUVM method instead of
  the double-check pattern.
- Assign sandboxID directly from annotation without intermediate sid
  variable in the early resolution block.

Signed-off-by: Shreyansh Jain <shreyanshjain7174@gmail.com>
Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
Comment thread internal/guest/runtime/hcsv2/sandbox_container.go Outdated
Comment thread internal/guest/runtime/hcsv2/sandbox_container.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go
Comment thread internal/guest/runtime/hcsv2/uvm.go
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
Comment thread internal/guest/runtime/hcsv2/workload_container.go Outdated
- Introduce podCgroupPathFmt and containerCgroupPathFmt constants for
  the /pods/{sandboxID} and /pods/{sandboxID}/{containerID} cgroup paths
  used by sandbox, standalone, and workload containers.
- Drop unused networkNamespace and cgroupPath fields from uvmPod; only
  sandboxID, cgroupControl, and the container set are actually consulted.
- Move workload-container pod registration to run before the per-type
  switch. Return an error when the sandbox pod is missing or when the
  container ID is already registered, instead of silently no-oping.
- Consolidate the duplicate VirtualPodID lookup in the sandbox container
  spec setup so the cgroup path uses the value resolved at the top.

Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
@shreyanshjain7174 shreyanshjain7174 force-pushed the guest-pod-unification-v2 branch from ccdc388 to 832f7bd Compare May 10, 2026 18:42
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Copy link
Copy Markdown
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit, but lgtm overall

Comment thread internal/guest/runtime/hcsv2/uvm.go Outdated
)

// uvmPod tracks pod-level state within the UVM.
type uvmPod struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type uvmPod struct {
type pod struct {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to #2699: removes the VirtualPod-specific path helpers from internal/guest/spec/spec.go that became dead code after the pod-unification refactor.

Context

After #2699, all callers of pod paths use the *FromRoot(sandboxRoot) variants from #2653. The 13 Get*VirtualPod* / VirtualPodAware* helpers in spec.go are no longer reachable from any production path, and SandboxLogsDir / SandboxLogPath were only used by VirtualPodAwareSandboxRootDir.

Changes

  • Drop 13 VirtualPod path functions from internal/guest/spec/spec.go.
  • Drop SandboxLogsDir and SandboxLogPath.
  • Update ExtendPolicyWithNetworkingMounts in pkg/securitypolicy to take sandboxRoot string and use the FromRoot variant.

Stats

4 files changed, 21 insertions(+), 167 deletions(-).

Depends on #2699.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4b245d0 — renamed uvmPodpod (5 sites, all in uvm.go).

The uvm prefix is redundant inside the hcsv2 package — the struct is
already package-private and only referenced from within the UVM-side
code path. Renames the type and the four call sites.

Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
@shreyanshjain7174 shreyanshjain7174 merged commit c1a159c into microsoft:main May 13, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants