Skip to content

Commit 18fb5d8

Browse files
author
Shreyansh Sancheti
committed
guest: unify pod model for V1, virtual pod, and V2 shim support
Replace VirtualPod with a generic uvmPod struct that serves all three sandbox modes (V1 shim, virtual pod annotation, V2 native Sandbox API). Key changes: - VirtualPod (exported, complex) -> uvmPod (unexported, simpler) - Host.virtualPods/containerToVirtualPod/virtualPodsCgroupParent -> Host.pods - createPodInUVM: unified pod creation under /pods/<sandboxID> cgroup - Container.sandboxID: every container tracks its sandbox for cleanup - RemoveContainer: uses sandboxID + pod lookup instead of annotation checks - Cgroup layout: /pods/<sandboxID>/<containerID> for all CRI containers - cmd/gcs/main.go: /containers/virtual-pods cgroup -> /pods cgroup - Remove InitializeVirtualPodSupport and all VirtualPod management methods Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
1 parent 5e2b46c commit 18fb5d8

File tree

7 files changed

+122
-325
lines changed

7 files changed

+122
-325
lines changed

cmd/gcs/main.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,16 @@ func main() {
362362
}
363363
defer containersControl.Delete() //nolint:errcheck
364364

365-
// Create virtual-pods cgroup hierarchy for multi-pod support
366-
// This will be the parent for all virtual pod cgroups: /containers/virtual-pods/{virtualSandboxID}
367-
virtualPodsControl, err := cgroup.NewManager("/containers/virtual-pods", &oci.LinuxResources{
365+
// Create /pods cgroup hierarchy for all pods (sandbox, virtual pod, and v2).
366+
podsControl, err := cgroup.NewManager("/pods", &oci.LinuxResources{
368367
Memory: &oci.LinuxMemory{
369-
Limit: &containersLimit, // Share the same limit as containers
368+
Limit: &containersLimit,
370369
},
371370
})
372371
if err != nil {
373-
logrus.WithError(err).Fatal("failed to create containers/virtual-pods cgroup")
372+
logrus.WithError(err).Fatal("failed to create pods cgroup")
374373
}
375-
defer virtualPodsControl.Delete() //nolint:errcheck
374+
defer podsControl.Delete() //nolint:errcheck
376375

377376
gcsControl, err := cgroup.NewManager("/gcs", &oci.LinuxResources{})
378377
if err != nil {
@@ -394,10 +393,6 @@ func main() {
394393
EnableV4: *v4,
395394
}
396395
h := hcsv2.NewHost(rtime, tport, initialEnforcer, logWriter)
397-
// Initialize virtual pod support in the host
398-
if err := h.InitializeVirtualPodSupport(virtualPodsControl); err != nil {
399-
logrus.WithError(err).Warn("Virtual pod support initialization failed")
400-
}
401396
b.AssignHandlers(mux, h)
402397

403398
var bridgeIn io.ReadCloser
@@ -433,13 +428,13 @@ func main() {
433428
oomFile := os.NewFile(oom, "cefd")
434429
defer oomFile.Close()
435430

436-
// Setup OOM monitoring for virtual-pods cgroup
437-
virtualPodsOom, err := virtualPodsControl.OOMEventFD()
431+
// Setup OOM monitoring for pods cgroup
432+
podsOom, err := podsControl.OOMEventFD()
438433
if err != nil {
439-
logrus.WithError(err).Fatal("failed to retrieve the virtual-pods cgroups oom eventfd")
434+
logrus.WithError(err).Fatal("failed to retrieve the pods cgroups oom eventfd")
440435
}
441-
virtualPodsOomFile := os.NewFile(virtualPodsOom, "vp-oomfd")
442-
defer virtualPodsOomFile.Close()
436+
podsOomFile := os.NewFile(podsOom, "pods-oomfd")
437+
defer podsOomFile.Close()
443438

444439
// time synchronization service
445440
if !(*disableTimeSync) {
@@ -450,7 +445,7 @@ func main() {
450445

451446
go readMemoryEvents(startTime, gefdFile, "/gcs", int64(*gcsMemLimitBytes), gcsControl)
452447
go readMemoryEvents(startTime, oomFile, "/containers", containersLimit, containersControl)
453-
go readMemoryEvents(startTime, virtualPodsOomFile, "/containers/virtual-pods", containersLimit, virtualPodsControl)
448+
go readMemoryEvents(startTime, podsOomFile, "/pods", containersLimit, podsControl)
454449
err = b.ListenAndServe(bridgeIn, bridgeOut)
455450
if err != nil {
456451
logrus.WithFields(logrus.Fields{

internal/guest/runtime/hcsv2/container.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Container struct {
5252

5353
spec *oci.Spec
5454
ociBundlePath string
55+
sandboxID string // ID of the sandbox/pod this container belongs to
5556
isSandbox bool
5657

5758
container runtime.Container

internal/guest/runtime/hcsv2/container_stats_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,3 @@ func TestConvertV2StatsToV1_NilInput(t *testing.T) {
494494
t.Error("ConvertV2StatsToV1(nil) should return empty metrics with all nil fields")
495495
}
496496
}
497-
498-
func TestHost_InitializeVirtualPodSupport_ErrorCases(t *testing.T) {
499-
host := &Host{}
500-
501-
// Test with nil input
502-
err := host.InitializeVirtualPodSupport(nil)
503-
if err == nil {
504-
t.Error("Expected error for nil input")
505-
}
506-
if err != nil && err.Error() != "no valid cgroup manager provided for virtual pod support" {
507-
t.Errorf("Unexpected error message: %s", err.Error())
508-
}
509-
}

internal/guest/runtime/hcsv2/sandbox_container.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,8 @@ func setupSandboxContainerSpec(ctx context.Context, id, sandboxRoot string, spec
119119
// also has a concept of a sandbox/shm file when the IPC NamespaceMode !=
120120
// NODE.
121121

122-
// Set cgroup path - check if this is a virtual pod
123-
if virtualSandboxID != "" {
124-
spec.Linux.CgroupsPath = "/containers/virtual-pods/" + virtualSandboxID
125-
} else {
126-
spec.Linux.CgroupsPath = "/containers/" + id
127-
}
122+
// Set cgroup path under the pod's cgroup.
123+
spec.Linux.CgroupsPath = "/pods/" + id
128124

129125
// Clear the windows section as we dont want to forward to runc
130126
spec.Windows = nil

internal/guest/runtime/hcsv2/standalone_container.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/Microsoft/hcsshim/internal/guest/network"
1616
specGuest "github.com/Microsoft/hcsshim/internal/guest/spec"
1717
"github.com/Microsoft/hcsshim/internal/oc"
18-
"github.com/Microsoft/hcsshim/pkg/annotations"
1918
)
2019

2120
func getStandaloneHostnamePath(rootDir string) string {
@@ -118,13 +117,8 @@ func setupStandaloneContainerSpec(ctx context.Context, id, rootDir string, spec
118117
spec.Mounts = append(spec.Mounts, mt)
119118
}
120119

121-
// Set cgroup path
122-
virtualSandboxID := spec.Annotations[annotations.VirtualPodID]
123-
if virtualSandboxID != "" {
124-
spec.Linux.CgroupsPath = "/containers/virtual-pods/" + virtualSandboxID + "/" + id
125-
} else {
126-
spec.Linux.CgroupsPath = "/containers/" + id
127-
}
120+
// Set cgroup path. Standalone containers go under /containers.
121+
spec.Linux.CgroupsPath = "/containers/" + id
128122

129123
// Clear the windows section as we dont want to forward to runc
130124
spec.Windows = nil

0 commit comments

Comments
 (0)