Merge pull request #126602 from haircommander/node-cm-test

Revert "Skip node container manager test on systemd" and fix test
This commit is contained in:
Kubernetes Prow Robot
2024-08-15 15:39:58 -07:00
committed by GitHub

View File

@@ -37,7 +37,6 @@ import (
admissionapi "k8s.io/pod-security-admission/api"
"k8s.io/kubernetes/test/e2e/framework"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
"k8s.io/kubernetes/test/e2e/nodefeature"
e2enodekubelet "k8s.io/kubernetes/test/e2e_node/kubeletconfig"
@@ -45,7 +44,7 @@ import (
"github.com/onsi/gomega"
)
func setDesiredConfiguration(initialConfig *kubeletconfig.KubeletConfiguration) {
func setDesiredConfiguration(initialConfig *kubeletconfig.KubeletConfiguration, cgroupManager cm.CgroupManager) {
initialConfig.EnforceNodeAllocatable = []string{"pods", kubeReservedCgroup, systemReservedCgroup}
initialConfig.SystemReserved = map[string]string{
string(v1.ResourceCPU): "100m",
@@ -62,6 +61,11 @@ func setDesiredConfiguration(initialConfig *kubeletconfig.KubeletConfiguration)
initialConfig.CgroupsPerQOS = true
initialConfig.KubeReservedCgroup = kubeReservedCgroup
initialConfig.SystemReservedCgroup = systemReservedCgroup
if initialConfig.CgroupDriver == "systemd" {
initialConfig.KubeReservedCgroup = cm.NewCgroupName(cm.RootCgroupName, kubeReservedCgroup).ToSystemd()
initialConfig.SystemReservedCgroup = cm.NewCgroupName(cm.RootCgroupName, systemReservedCgroup).ToSystemd()
}
}
var _ = SIGDescribe("Node Container Manager", framework.WithSerial(), func() {
@@ -118,6 +122,7 @@ func getAllocatableLimits(cpu, memory, pids string, capacity v1.ResourceList) (*
const (
kubeReservedCgroup = "kube-reserved"
systemReservedCgroup = "system-reserved"
nodeAllocatableCgroup = "kubepods"
)
func createIfNotExists(cm cm.CgroupManager, cgroupConfig *cm.CgroupConfig) error {
@@ -172,15 +177,6 @@ func runTest(ctx context.Context, f *framework.Framework) error {
return err
}
// Test needs to be updated to make it run properly on systemd.
// In its current state it will result in kubelet error since
// kubeReservedCgroup and systemReservedCgroup are not configured
// correctly for systemd.
// See: https://github.com/kubernetes/kubernetes/issues/102394
if oldCfg.CgroupDriver == "systemd" {
e2eskipper.Skipf("unable to run test when using systemd as cgroup driver")
}
// Create a cgroup manager object for manipulating cgroups.
cgroupManager := cm.NewCgroupManager(subsystems, oldCfg.CgroupDriver)
@@ -210,9 +206,10 @@ func runTest(ctx context.Context, f *framework.Framework) error {
if err := createTemporaryCgroupsForReservation(cgroupManager); err != nil {
return err
}
newCfg := oldCfg.DeepCopy()
// Change existing kubelet configuration
setDesiredConfiguration(newCfg)
setDesiredConfiguration(newCfg, cgroupManager)
// Set the new kubelet configuration.
// Update the Kubelet configuration.
ginkgo.By("Stopping the kubelet")
@@ -223,6 +220,18 @@ func runTest(ctx context.Context, f *framework.Framework) error {
return kubeletHealthCheck(kubeletHealthCheckURL)
}, time.Minute, time.Second).Should(gomega.BeFalse())
expectedNAPodCgroup := cm.NewCgroupName(cm.RootCgroupName, nodeAllocatableCgroup)
// Cleanup from the previous kubelet, to verify the new one creates it correctly
if err := cgroupManager.Destroy(&cm.CgroupConfig{
Name: cm.NewCgroupName(expectedNAPodCgroup),
}); err != nil {
return err
}
if cgroupManager.Exists(expectedNAPodCgroup) {
return fmt.Errorf("Expected Node Allocatable Cgroup %q not to exist", expectedNAPodCgroup)
}
framework.ExpectNoError(e2enodekubelet.WriteKubeletConfigFile(newCfg))
ginkgo.By("Starting the kubelet")
@@ -239,10 +248,8 @@ func runTest(ctx context.Context, f *framework.Framework) error {
// Set new config and current config.
currentConfig := newCfg
expectedNAPodCgroup := cm.ParseCgroupfsToCgroupName(currentConfig.CgroupRoot)
expectedNAPodCgroup = cm.NewCgroupName(expectedNAPodCgroup, "kubepods")
if !cgroupManager.Exists(expectedNAPodCgroup) {
return fmt.Errorf("Expected Node Allocatable Cgroup %q does not exist", expectedNAPodCgroup)
return fmt.Errorf("Expected Node Allocatable Cgroup %q to exist", expectedNAPodCgroup)
}
memoryLimitFile := "memory.limit_in_bytes"
@@ -260,9 +267,9 @@ func runTest(ctx context.Context, f *framework.Framework) error {
if len(nodeList.Items) != 1 {
return fmt.Errorf("Unexpected number of node objects for node e2e. Expects only one node: %+v", nodeList)
}
cgroupName := "kubepods"
cgroupName := nodeAllocatableCgroup
if currentConfig.CgroupDriver == "systemd" {
cgroupName = "kubepods.slice"
cgroupName = nodeAllocatableCgroup + ".slice"
}
node := nodeList.Items[0]
@@ -311,7 +318,7 @@ func runTest(ctx context.Context, f *framework.Framework) error {
cgroupPath := ""
if currentConfig.CgroupDriver == "systemd" {
cgroupPath = cm.ParseSystemdToCgroupName(kubeReservedCgroup).ToSystemd()
cgroupPath = cm.NewCgroupName(cm.RootCgroupName, kubeReservedCgroup).ToSystemd()
} else {
cgroupPath = cgroupManager.Name(cm.NewCgroupName(cm.RootCgroupName, kubeReservedCgroup))
}
@@ -339,7 +346,7 @@ func runTest(ctx context.Context, f *framework.Framework) error {
}
if currentConfig.CgroupDriver == "systemd" {
cgroupPath = cm.ParseSystemdToCgroupName(systemReservedCgroup).ToSystemd()
cgroupPath = cm.NewCgroupName(cm.RootCgroupName, systemReservedCgroup).ToSystemd()
} else {
cgroupPath = cgroupManager.Name(cm.NewCgroupName(cm.RootCgroupName, systemReservedCgroup))
}