Skip to content

Commit a221d3a

Browse files
authored
Merge pull request kubernetes#126602 from haircommander/node-cm-test
Revert "Skip node container manager test on systemd" and fix test
2 parents b860feb + c7b7ea0 commit a221d3a

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

test/e2e_node/node_container_manager_test.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ import (
3737
admissionapi "k8s.io/pod-security-admission/api"
3838

3939
"k8s.io/kubernetes/test/e2e/framework"
40-
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
4140
"k8s.io/kubernetes/test/e2e/nodefeature"
4241
e2enodekubelet "k8s.io/kubernetes/test/e2e_node/kubeletconfig"
4342

4443
"github.com/onsi/ginkgo/v2"
4544
"github.com/onsi/gomega"
4645
)
4746

48-
func setDesiredConfiguration(initialConfig *kubeletconfig.KubeletConfiguration) {
47+
func setDesiredConfiguration(initialConfig *kubeletconfig.KubeletConfiguration, cgroupManager cm.CgroupManager) {
4948
initialConfig.EnforceNodeAllocatable = []string{"pods", kubeReservedCgroup, systemReservedCgroup}
5049
initialConfig.SystemReserved = map[string]string{
5150
string(v1.ResourceCPU): "100m",
@@ -62,6 +61,11 @@ func setDesiredConfiguration(initialConfig *kubeletconfig.KubeletConfiguration)
6261
initialConfig.CgroupsPerQOS = true
6362
initialConfig.KubeReservedCgroup = kubeReservedCgroup
6463
initialConfig.SystemReservedCgroup = systemReservedCgroup
64+
65+
if initialConfig.CgroupDriver == "systemd" {
66+
initialConfig.KubeReservedCgroup = cm.NewCgroupName(cm.RootCgroupName, kubeReservedCgroup).ToSystemd()
67+
initialConfig.SystemReservedCgroup = cm.NewCgroupName(cm.RootCgroupName, systemReservedCgroup).ToSystemd()
68+
}
6569
}
6670

6771
var _ = SIGDescribe("Node Container Manager", framework.WithSerial(), func() {
@@ -116,8 +120,9 @@ func getAllocatableLimits(cpu, memory, pids string, capacity v1.ResourceList) (*
116120
}
117121

118122
const (
119-
kubeReservedCgroup = "kube-reserved"
120-
systemReservedCgroup = "system-reserved"
123+
kubeReservedCgroup = "kube-reserved"
124+
systemReservedCgroup = "system-reserved"
125+
nodeAllocatableCgroup = "kubepods"
121126
)
122127

123128
func createIfNotExists(cm cm.CgroupManager, cgroupConfig *cm.CgroupConfig) error {
@@ -172,15 +177,6 @@ func runTest(ctx context.Context, f *framework.Framework) error {
172177
return err
173178
}
174179

175-
// Test needs to be updated to make it run properly on systemd.
176-
// In its current state it will result in kubelet error since
177-
// kubeReservedCgroup and systemReservedCgroup are not configured
178-
// correctly for systemd.
179-
// See: https://github.com/kubernetes/kubernetes/issues/102394
180-
if oldCfg.CgroupDriver == "systemd" {
181-
e2eskipper.Skipf("unable to run test when using systemd as cgroup driver")
182-
}
183-
184180
// Create a cgroup manager object for manipulating cgroups.
185181
cgroupManager := cm.NewCgroupManager(subsystems, oldCfg.CgroupDriver)
186182

@@ -210,9 +206,10 @@ func runTest(ctx context.Context, f *framework.Framework) error {
210206
if err := createTemporaryCgroupsForReservation(cgroupManager); err != nil {
211207
return err
212208
}
209+
213210
newCfg := oldCfg.DeepCopy()
214211
// Change existing kubelet configuration
215-
setDesiredConfiguration(newCfg)
212+
setDesiredConfiguration(newCfg, cgroupManager)
216213
// Set the new kubelet configuration.
217214
// Update the Kubelet configuration.
218215
ginkgo.By("Stopping the kubelet")
@@ -223,6 +220,18 @@ func runTest(ctx context.Context, f *framework.Framework) error {
223220
return kubeletHealthCheck(kubeletHealthCheckURL)
224221
}, time.Minute, time.Second).Should(gomega.BeFalse())
225222

223+
expectedNAPodCgroup := cm.NewCgroupName(cm.RootCgroupName, nodeAllocatableCgroup)
224+
225+
// Cleanup from the previous kubelet, to verify the new one creates it correctly
226+
if err := cgroupManager.Destroy(&cm.CgroupConfig{
227+
Name: cm.NewCgroupName(expectedNAPodCgroup),
228+
}); err != nil {
229+
return err
230+
}
231+
if cgroupManager.Exists(expectedNAPodCgroup) {
232+
return fmt.Errorf("Expected Node Allocatable Cgroup %q not to exist", expectedNAPodCgroup)
233+
}
234+
226235
framework.ExpectNoError(e2enodekubelet.WriteKubeletConfigFile(newCfg))
227236

228237
ginkgo.By("Starting the kubelet")
@@ -239,10 +248,8 @@ func runTest(ctx context.Context, f *framework.Framework) error {
239248
// Set new config and current config.
240249
currentConfig := newCfg
241250

242-
expectedNAPodCgroup := cm.ParseCgroupfsToCgroupName(currentConfig.CgroupRoot)
243-
expectedNAPodCgroup = cm.NewCgroupName(expectedNAPodCgroup, "kubepods")
244251
if !cgroupManager.Exists(expectedNAPodCgroup) {
245-
return fmt.Errorf("Expected Node Allocatable Cgroup %q does not exist", expectedNAPodCgroup)
252+
return fmt.Errorf("Expected Node Allocatable Cgroup %q to exist", expectedNAPodCgroup)
246253
}
247254

248255
memoryLimitFile := "memory.limit_in_bytes"
@@ -260,9 +267,9 @@ func runTest(ctx context.Context, f *framework.Framework) error {
260267
if len(nodeList.Items) != 1 {
261268
return fmt.Errorf("Unexpected number of node objects for node e2e. Expects only one node: %+v", nodeList)
262269
}
263-
cgroupName := "kubepods"
270+
cgroupName := nodeAllocatableCgroup
264271
if currentConfig.CgroupDriver == "systemd" {
265-
cgroupName = "kubepods.slice"
272+
cgroupName = nodeAllocatableCgroup + ".slice"
266273
}
267274

268275
node := nodeList.Items[0]
@@ -311,7 +318,7 @@ func runTest(ctx context.Context, f *framework.Framework) error {
311318

312319
cgroupPath := ""
313320
if currentConfig.CgroupDriver == "systemd" {
314-
cgroupPath = cm.ParseSystemdToCgroupName(kubeReservedCgroup).ToSystemd()
321+
cgroupPath = cm.NewCgroupName(cm.RootCgroupName, kubeReservedCgroup).ToSystemd()
315322
} else {
316323
cgroupPath = cgroupManager.Name(cm.NewCgroupName(cm.RootCgroupName, kubeReservedCgroup))
317324
}
@@ -339,7 +346,7 @@ func runTest(ctx context.Context, f *framework.Framework) error {
339346
}
340347

341348
if currentConfig.CgroupDriver == "systemd" {
342-
cgroupPath = cm.ParseSystemdToCgroupName(systemReservedCgroup).ToSystemd()
349+
cgroupPath = cm.NewCgroupName(cm.RootCgroupName, systemReservedCgroup).ToSystemd()
343350
} else {
344351
cgroupPath = cgroupManager.Name(cm.NewCgroupName(cm.RootCgroupName, systemReservedCgroup))
345352
}

0 commit comments

Comments
 (0)