Skip to content

Commit 3e6df4a

Browse files
committed
test: remove container runtime check and fix other nits
1 parent d72c731 commit 3e6df4a

File tree

3 files changed

+57
-89
lines changed

3 files changed

+57
-89
lines changed

test/e2e/common/node/pod_resize.go

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ import (
2323
"strconv"
2424
"time"
2525

26-
"github.com/onsi/ginkgo/v2"
27-
"github.com/onsi/gomega"
28-
v1 "k8s.io/api/core/v1"
2926
"k8s.io/apimachinery/pkg/api/resource"
3027
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3128
"k8s.io/apimachinery/pkg/types"
3229
"k8s.io/apimachinery/pkg/util/strategicpatch"
3330
clientset "k8s.io/client-go/kubernetes"
34-
3531
"k8s.io/kubernetes/test/e2e/feature"
3632
"k8s.io/kubernetes/test/e2e/framework"
3733
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
3834
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3935
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
36+
37+
"github.com/onsi/ginkgo/v2"
38+
"github.com/onsi/gomega"
39+
v1 "k8s.io/api/core/v1"
4040
)
4141

4242
const (
@@ -115,13 +115,7 @@ func removeExtendedResource(clientSet clientset.Interface, nodeName, extendedRes
115115
}).WithTimeout(30 * time.Second).WithPolling(time.Second).ShouldNot(gomega.HaveOccurred())
116116
}
117117

118-
func doPodResizeTests() {
119-
f := framework.NewDefaultFramework("pod-resize-test")
120-
var podClient *e2epod.PodClient
121-
ginkgo.BeforeEach(func() {
122-
podClient = e2epod.NewPodClient(f)
123-
})
124-
118+
func doPodResizeTests(f *framework.Framework) {
125119
type testCase struct {
126120
name string
127121
containers []e2epod.ResizableContainerInfo
@@ -861,13 +855,7 @@ func doPodResizeTests() {
861855
for idx := range tests {
862856
tc := tests[idx]
863857
ginkgo.It(tc.name, func(ctx context.Context) {
864-
ginkgo.By("check if in place pod vertical scaling is supported", func() {
865-
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
866-
framework.ExpectNoError(err)
867-
if !e2epod.IsInPlacePodVerticalScalingSupportedByRuntime(node) || framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
868-
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
869-
}
870-
})
858+
podClient := e2epod.NewPodClient(f)
871859
var testPod, patchedPod *v1.Pod
872860
var pErr error
873861

@@ -945,12 +933,7 @@ func doPodResizeTests() {
945933
}
946934
}
947935

948-
func doPodResizeErrorTests() {
949-
f := framework.NewDefaultFramework("pod-resize-errors")
950-
var podClient *e2epod.PodClient
951-
ginkgo.BeforeEach(func() {
952-
podClient = e2epod.NewPodClient(f)
953-
})
936+
func doPodResizeErrorTests(f *framework.Framework) {
954937

955938
type testCase struct {
956939
name string
@@ -985,13 +968,7 @@ func doPodResizeErrorTests() {
985968
for idx := range tests {
986969
tc := tests[idx]
987970
ginkgo.It(tc.name, func(ctx context.Context) {
988-
ginkgo.By("check if in place pod vertical scaling is supported", func() {
989-
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
990-
framework.ExpectNoError(err)
991-
if !e2epod.IsInPlacePodVerticalScalingSupportedByRuntime(node) || framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
992-
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
993-
}
994-
})
971+
podClient := e2epod.NewPodClient(f)
995972
var testPod, patchedPod *v1.Pod
996973
var pErr error
997974

@@ -1043,7 +1020,17 @@ func doPodResizeErrorTests() {
10431020
// Above tests are performed by doSheduletTests() and doPodResizeResourceQuotaTests()
10441021
// in test/e2e/node/pod_resize.go
10451022

1046-
var _ = SIGDescribe("Pod InPlace Resize Container", framework.WithSerial(), feature.InPlacePodVerticalScaling, func() {
1047-
doPodResizeTests()
1048-
doPodResizeErrorTests()
1023+
var _ = SIGDescribe("Pod InPlace Resize Container", framework.WithSerial(), feature.InPlacePodVerticalScaling, "[NodeAlphaFeature:InPlacePodVerticalScaling]", func() {
1024+
f := framework.NewDefaultFramework("pod-resize-tests")
1025+
1026+
ginkgo.BeforeEach(func(ctx context.Context) {
1027+
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
1028+
framework.ExpectNoError(err)
1029+
if framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
1030+
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
1031+
}
1032+
})
1033+
1034+
doPodResizeTests(f)
1035+
doPodResizeErrorTests(f)
10491036
})

test/e2e/framework/pod/resize.go

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,20 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"regexp"
2423
"strconv"
2524
"strings"
2625

27-
semver "github.com/blang/semver/v4"
28-
"github.com/google/go-cmp/cmp"
29-
"github.com/onsi/ginkgo/v2"
30-
"github.com/onsi/gomega"
3126
v1 "k8s.io/api/core/v1"
3227
"k8s.io/apimachinery/pkg/api/resource"
3328
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34-
3529
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3630
kubecm "k8s.io/kubernetes/pkg/kubelet/cm"
3731
"k8s.io/kubernetes/test/e2e/framework"
3832
imageutils "k8s.io/kubernetes/test/utils/image"
33+
34+
"github.com/google/go-cmp/cmp"
35+
"github.com/onsi/ginkgo/v2"
36+
"github.com/onsi/gomega"
3937
)
4038

4139
const (
@@ -104,21 +102,6 @@ type patchSpec struct {
104102
} `json:"spec"`
105103
}
106104

107-
func IsInPlacePodVerticalScalingSupportedByRuntime(node *v1.Node) bool {
108-
re := regexp.MustCompile("containerd://(.*)")
109-
match := re.FindStringSubmatch(node.Status.NodeInfo.ContainerRuntimeVersion)
110-
if len(match) != 2 {
111-
return false
112-
}
113-
if ver, verr := semver.ParseTolerant(match[1]); verr == nil {
114-
if ver.Compare(semver.MustParse(MinContainerRuntimeVersion)) < 0 {
115-
return false
116-
}
117-
return true
118-
}
119-
return false
120-
}
121-
122105
func getTestResourceInfo(tcInfo ResizableContainerInfo) (v1.ResourceRequirements, v1.ResourceList, []v1.ContainerResizePolicy) {
123106
var res v1.ResourceRequirements
124107
var alloc v1.ResourceList
@@ -237,6 +220,7 @@ func MakePodWithResizableContainers(ns, name, timeStamp string, tcInfo []Resizab
237220

238221
func VerifyPodResizePolicy(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) {
239222
ginkgo.GinkgoHelper()
223+
gomega.Expect(gotPod.Spec.Containers).To(gomega.HaveLen(len(wantCtrs)), "number of containers in pod spec should match")
240224
for i, wantCtr := range wantCtrs {
241225
gotCtr := &gotPod.Spec.Containers[i]
242226
ctr, _ := makeResizableContainer(wantCtr)
@@ -247,6 +231,7 @@ func VerifyPodResizePolicy(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) {
247231

248232
func VerifyPodResources(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) {
249233
ginkgo.GinkgoHelper()
234+
gomega.Expect(gotPod.Spec.Containers).To(gomega.HaveLen(len(wantCtrs)), "number of containers in pod spec should match")
250235
for i, wantCtr := range wantCtrs {
251236
gotCtr := &gotPod.Spec.Containers[i]
252237
ctr, _ := makeResizableContainer(wantCtr)
@@ -257,6 +242,7 @@ func VerifyPodResources(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) {
257242

258243
func VerifyPodAllocations(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) error {
259244
ginkgo.GinkgoHelper()
245+
gomega.Expect(gotPod.Status.ContainerStatuses).To(gomega.HaveLen(len(wantCtrs)), "number of containers in pod spec should match")
260246
for i, wantCtr := range wantCtrs {
261247
gotCtrStatus := &gotPod.Status.ContainerStatuses[i]
262248
if wantCtr.Allocations == nil {
@@ -280,6 +266,7 @@ func VerifyPodAllocations(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) err
280266

281267
func VerifyPodStatusResources(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo) {
282268
ginkgo.GinkgoHelper()
269+
gomega.Expect(gotPod.Status.ContainerStatuses).To(gomega.HaveLen(len(wantCtrs)), "number of containers in pod spec should match")
283270
for i, wantCtr := range wantCtrs {
284271
gotCtrStatus := &gotPod.Status.ContainerStatuses[i]
285272
ctr, _ := makeResizableContainer(wantCtr)
@@ -288,9 +275,10 @@ func VerifyPodStatusResources(gotPod *v1.Pod, wantCtrs []ResizableContainerInfo)
288275
}
289276
}
290277

278+
// isPodOnCgroupv2Node checks whether the pod is running on cgroupv2 node.
279+
// TODO: Deduplicate this function with NPD cluster e2e test:
280+
// https://github.com/kubernetes/kubernetes/blob/2049360379bcc5d6467769cef112e6e492d3d2f0/test/e2e/node/node_problem_detector.go#L369
291281
func isPodOnCgroupv2Node(f *framework.Framework, pod *v1.Pod) bool {
292-
// Determine if pod is running on cgroupv2 or cgroupv1 node
293-
//TODO(vinaykul,InPlacePodVerticalScaling): Is there a better way to determine this?
294282
cmd := "mount -t cgroup2"
295283
out, _, err := ExecCommandInContainerWithFullOutput(f, pod.Name, pod.Spec.Containers[0].Name, "/bin/sh", "-c", cmd)
296284
if err != nil {

test/e2e/node/pod_resize.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,26 @@ import (
2222
"strconv"
2323
"time"
2424

25-
"github.com/onsi/ginkgo/v2"
26-
"github.com/onsi/gomega"
2725
v1 "k8s.io/api/core/v1"
2826
"k8s.io/apimachinery/pkg/api/resource"
2927
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3028
"k8s.io/apimachinery/pkg/types"
31-
3229
resourceapi "k8s.io/kubernetes/pkg/api/v1/resource"
3330
"k8s.io/kubernetes/test/e2e/feature"
3431
"k8s.io/kubernetes/test/e2e/framework"
3532
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
3633
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3734
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
35+
36+
"github.com/onsi/ginkgo/v2"
37+
"github.com/onsi/gomega"
3838
)
3939

40-
func doPodResizeResourceQuotaTests() {
41-
f := framework.NewDefaultFramework("pod-resize-resource-quota")
42-
var podClient *e2epod.PodClient
43-
ginkgo.BeforeEach(func() {
44-
podClient = e2epod.NewPodClient(f)
45-
})
40+
func doPodResizeResourceQuotaTests(f *framework.Framework) {
4641
timeouts := framework.NewTimeoutContext()
4742

4843
ginkgo.It("pod-resize-resource-quota-test", func(ctx context.Context) {
49-
ginkgo.By("check if in place pod vertical scaling is supported", func() {
50-
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
51-
framework.ExpectNoError(err)
52-
if !e2epod.IsInPlacePodVerticalScalingSupportedByRuntime(node) || framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
53-
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
54-
}
55-
})
44+
podClient := e2epod.NewPodClient(f)
5645
resourceQuota := v1.ResourceQuota{
5746
ObjectMeta: metav1.ObjectMeta{
5847
Name: "resize-resource-quota",
@@ -166,21 +155,9 @@ func doPodResizeResourceQuotaTests() {
166155
})
167156
}
168157

169-
func doPodResizeSchedulerTests() {
170-
f := framework.NewDefaultFramework("pod-resize-scheduler")
171-
var podClient *e2epod.PodClient
172-
ginkgo.BeforeEach(func() {
173-
podClient = e2epod.NewPodClient(f)
174-
})
175-
158+
func doPodResizeSchedulerTests(f *framework.Framework) {
176159
ginkgo.It("pod-resize-scheduler-tests", func(ctx context.Context) {
177-
ginkgo.By("check if in place pod vertical scaling is supported", func() {
178-
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
179-
framework.ExpectNoError(err)
180-
if !e2epod.IsInPlacePodVerticalScalingSupportedByRuntime(node) || framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
181-
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
182-
}
183-
})
160+
podClient := e2epod.NewPodClient(f)
184161
nodes, err := e2enode.GetReadySchedulableNodes(ctx, f.ClientSet)
185162
framework.ExpectNoError(err, "failed to get running nodes")
186163
gomega.Expect(nodes.Items).ShouldNot(gomega.BeEmpty())
@@ -342,9 +319,25 @@ func doPodResizeSchedulerTests() {
342319
}
343320

344321
var _ = SIGDescribe(framework.WithSerial(), "Pod InPlace Resize Container (scheduler-focused)", feature.InPlacePodVerticalScaling, func() {
345-
doPodResizeSchedulerTests()
322+
f := framework.NewDefaultFramework("pod-resize-scheduler-tests")
323+
ginkgo.BeforeEach(func(ctx context.Context) {
324+
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
325+
framework.ExpectNoError(err)
326+
if framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
327+
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
328+
}
329+
})
330+
doPodResizeSchedulerTests(f)
346331
})
347332

348333
var _ = SIGDescribe("Pod InPlace Resize Container", feature.InPlacePodVerticalScaling, func() {
349-
doPodResizeResourceQuotaTests()
334+
f := framework.NewDefaultFramework("pod-resize-tests")
335+
ginkgo.BeforeEach(func(ctx context.Context) {
336+
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
337+
framework.ExpectNoError(err)
338+
if framework.NodeOSDistroIs("windows") || e2enode.IsARM64(node) {
339+
e2eskipper.Skipf("runtime does not support InPlacePodVerticalScaling -- skipping")
340+
}
341+
})
342+
doPodResizeResourceQuotaTests(f)
350343
})

0 commit comments

Comments
 (0)