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
34 changes: 15 additions & 19 deletions cmd/gcs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func readMemoryEvents(startTime time.Time, efdFile *os.File, cgName string, thre

count++
var msg string
if strings.HasPrefix(cgName, "/virtual-pods") {
msg = "memory usage for virtual pods cgroup exceeded threshold"
if strings.HasPrefix(cgName, "/pods") {
msg = "memory usage for pods cgroup exceeded threshold"
} else {
msg = "memory usage for cgroup exceeded threshold"
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func main() {

// Setup the UVM cgroups to protect against a workload taking all available
// memory and causing the GCS to malfunction we create cgroups: gcs,
// containers, and virtual-pods for multi-pod support.
// containers, and pods for pod support.
//

// Write 1 to memory.use_hierarchy on the root cgroup to enable hierarchy
Expand Down Expand Up @@ -359,17 +359,17 @@ func main() {
}
defer containersControl.Delete() //nolint:errcheck

// Create virtual-pods cgroup hierarchy for multi-pod support
// This will be the parent for all virtual pod cgroups: /containers/virtual-pods/{virtualSandboxID}
virtualPodsControl, err := cgroup.NewManager("/containers/virtual-pods", &oci.LinuxResources{
// Create pods cgroup hierarchy for pod support
// This will be the parent for all pod cgroups: /pods/{sandboxID}
podsControl, err := cgroup.NewManager("/pods", &oci.LinuxResources{
Memory: &oci.LinuxMemory{
Limit: &containersLimit, // Share the same limit as containers
Limit: &containersLimit,
},
})
if err != nil {
logrus.WithError(err).Fatal("failed to create containers/virtual-pods cgroup")
logrus.WithError(err).Fatal("failed to create pods cgroup")
}
defer virtualPodsControl.Delete() //nolint:errcheck
defer podsControl.Delete() //nolint:errcheck

gcsControl, err := cgroup.NewManager("/gcs", &oci.LinuxResources{})
if err != nil {
Expand All @@ -391,10 +391,6 @@ func main() {
EnableV4: *v4,
}
h := hcsv2.NewHost(rtime, tport, initialEnforcer, logWriter)
// Initialize virtual pod support in the host
if err := h.InitializeVirtualPodSupport(virtualPodsControl); err != nil {
logrus.WithError(err).Warn("Virtual pod support initialization failed")
}
b.AssignHandlers(mux, h)

var bridgeIn io.ReadCloser
Expand Down Expand Up @@ -430,13 +426,13 @@ func main() {
oomFile := os.NewFile(oom, "cefd")
defer oomFile.Close()

// Setup OOM monitoring for virtual-pods cgroup
virtualPodsOom, err := virtualPodsControl.OOMEventFD()
// Setup OOM monitoring for pods cgroup
podsOom, err := podsControl.OOMEventFD()
if err != nil {
logrus.WithError(err).Fatal("failed to retrieve the virtual-pods cgroups oom eventfd")
logrus.WithError(err).Fatal("failed to retrieve the pods cgroups oom eventfd")
}
virtualPodsOomFile := os.NewFile(virtualPodsOom, "vp-oomfd")
defer virtualPodsOomFile.Close()
podsOomFile := os.NewFile(podsOom, "pods-oomfd")
defer podsOomFile.Close()

// time synchronization service
if !(*disableTimeSync) {
Expand All @@ -447,7 +443,7 @@ func main() {

go readMemoryEvents(startTime, gefdFile, "/gcs", int64(*gcsMemLimitBytes), gcsControl)
go readMemoryEvents(startTime, oomFile, "/containers", containersLimit, containersControl)
go readMemoryEvents(startTime, virtualPodsOomFile, "/containers/virtual-pods", containersLimit, virtualPodsControl)
go readMemoryEvents(startTime, podsOomFile, "/pods", containersLimit, podsControl)
err = b.ListenAndServe(bridgeIn, bridgeOut)
if err != nil {
logrus.WithFields(logrus.Fields{
Expand Down
3 changes: 2 additions & 1 deletion internal/guest/runtime/hcsv2/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const (
)

type Container struct {
id string
id string
sandboxID string

vsock transport.Transport
logPath string // path to [logFile].
Expand Down
13 changes: 0 additions & 13 deletions internal/guest/runtime/hcsv2/container_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,3 @@ func TestConvertV2StatsToV1_NilInput(t *testing.T) {
t.Error("ConvertV2StatsToV1(nil) should return empty metrics with all nil fields")
}
}

func TestHost_InitializeVirtualPodSupport_ErrorCases(t *testing.T) {
host := &Host{}

// Test with nil input
err := host.InitializeVirtualPodSupport(nil)
if err == nil {
t.Error("Expected error for nil input")
}
if err != nil && err.Error() != "no valid cgroup manager provided for virtual pod support" {
t.Errorf("Unexpected error message: %s", err.Error())
}
}
10 changes: 2 additions & 8 deletions internal/guest/runtime/hcsv2/sandbox_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,8 @@ func setupSandboxContainerSpec(ctx context.Context, id, sandboxRoot string, spec
// also has a concept of a sandbox/shm file when the IPC NamespaceMode !=
// NODE.

// Set cgroup path - check if this is a virtual pod
if virtualSandboxID != "" {
// Virtual pod sandbox gets its own cgroup under /containers/virtual-pods using the virtual pod ID
spec.Linux.CgroupsPath = "/containers/virtual-pods/" + virtualSandboxID
} else {
// Traditional sandbox goes under /containers
spec.Linux.CgroupsPath = "/containers/" + id
}
// Set cgroup path
spec.Linux.CgroupsPath = "/pods/" + id

// Clear the windows section as we dont want to forward to runc
spec.Windows = nil
Expand Down
8 changes: 1 addition & 7 deletions internal/guest/runtime/hcsv2/standalone_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Microsoft/hcsshim/internal/guest/network"
specGuest "github.com/Microsoft/hcsshim/internal/guest/spec"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/pkg/annotations"
)

func getStandaloneHostnamePath(rootDir string) string {
Expand Down Expand Up @@ -119,12 +118,7 @@ func setupStandaloneContainerSpec(ctx context.Context, id, rootDir string, spec
}

// Set cgroup path
virtualSandboxID := spec.Annotations[annotations.VirtualPodID]
if virtualSandboxID != "" {
spec.Linux.CgroupsPath = "/containers/virtual-pods/" + virtualSandboxID + "/" + id
} else {
spec.Linux.CgroupsPath = "/containers/" + id
}
spec.Linux.CgroupsPath = "/pods/" + id

// Clear the windows section as we dont want to forward to runc
spec.Windows = nil
Expand Down
Loading
Loading