guest: unify pod model for V1, virtual pod, and V2 shim support#2699
Conversation
62fc02c to
a724fae
Compare
a724fae to
ad3ee5f
Compare
ad3ee5f to
f51f773
Compare
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>
f51f773 to
32802d9
Compare
…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>
- 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>
ccdc388 to
832f7bd
Compare
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
helsaawy
left a comment
There was a problem hiding this comment.
small nit, but lgtm overall
| ) | ||
|
|
||
| // uvmPod tracks pod-level state within the UVM. | ||
| type uvmPod struct { |
There was a problem hiding this comment.
| type uvmPod struct { | |
| type pod struct { |
There was a problem hiding this comment.
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
SandboxLogsDirandSandboxLogPath. - Update
ExtendPolicyWithNetworkingMountsinpkg/securitypolicyto takesandboxRoot stringand use the FromRoot variant.
Stats
4 files changed, 21 insertions(+), 167 deletions(-).
Depends on #2699.
There was a problem hiding this comment.
Done in 4b245d0 — renamed uvmPod → pod (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>
The GCS guest runtime (
internal/guest/runtime/hcsv2/uvm.go) tracks virtual pods separately from V1 sandbox containers — a dedicatedVirtualPodtype, 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
uvmPodtype and a singlepodsmap onHost. Every sandbox — V1, virtual pod, or V2 shim — goes throughcreatePodInUVM, which allocates a cgroup under/pods/{sandboxID}. Workload containers nest at/pods/{sandboxID}/{containerID}. Container-to-pod membership is tracked viaaddContainerToPod. Cleanup inRemoveContaineris 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:
to:
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:
RemoveContainerskipsRemoveNetworkNamespacefor virtual pod sandbox containers since the host-driven path (TearDownNetworking→RemoveNetNS→removeNIC) handles adapter removal first.cmd/gcs/main.goreplaces the/containers/virtual-podsparent cgroup with/podsand drops theInitializeVirtualPodSupportcall.Tested E2E with both shims:
io.containerd.runhcs.v1)io.containerd.lcow.v2)/run/gcs/c/<podId>/run/gcs/pods/<podId>/<podId>/sys/fs/cgroup/memory/pods/<podId>/sys/fs/cgroup/memory/pods/<podId>/containers/virtual-pods/