Skip to content

Commit d1361d1

Browse files
author
Kenichi Omichi
committed
Move NewTestPod() to e2e/scheduling
because the function is called in e2e/scheduling tests.
1 parent 0641e0c commit d1361d1

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

test/e2e/framework/util.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,27 +1583,6 @@ func DescribeIng(ns string) {
15831583
Logf(desc)
15841584
}
15851585

1586-
// NewTestPod returns a pod that has the specified requests and limits
1587-
func (f *Framework) NewTestPod(name string, requests v1.ResourceList, limits v1.ResourceList) *v1.Pod {
1588-
return &v1.Pod{
1589-
ObjectMeta: metav1.ObjectMeta{
1590-
Name: name,
1591-
},
1592-
Spec: v1.PodSpec{
1593-
Containers: []v1.Container{
1594-
{
1595-
Name: "pause",
1596-
Image: imageutils.GetPauseImageName(),
1597-
Resources: v1.ResourceRequirements{
1598-
Requests: requests,
1599-
Limits: limits,
1600-
},
1601-
},
1602-
},
1603-
},
1604-
}
1605-
}
1606-
16071586
// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
16081587
// that behave the same, no matter the underlying OS.
16091588
func (f *Framework) NewAgnhostPod(name string, args ...string) *v1.Pod {

test/e2e/scheduling/limit_range.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
watchtools "k8s.io/client-go/tools/watch"
3636
"k8s.io/kubernetes/test/e2e/framework"
3737
e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
38+
imageutils "k8s.io/kubernetes/test/utils/image"
3839

3940
"github.com/onsi/ginkgo"
4041
"github.com/onsi/gomega"
@@ -129,7 +130,7 @@ var _ = SIGDescribe("LimitRange", func() {
129130
framework.ExpectNoError(err)
130131

131132
ginkgo.By("Creating a Pod with no resource requirements")
132-
pod := f.NewTestPod("pod-no-resources", v1.ResourceList{}, v1.ResourceList{})
133+
pod := newTestPod("pod-no-resources", v1.ResourceList{}, v1.ResourceList{})
133134
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
134135
framework.ExpectNoError(err)
135136

@@ -146,7 +147,7 @@ var _ = SIGDescribe("LimitRange", func() {
146147
}
147148

148149
ginkgo.By("Creating a Pod with partial resource requirements")
149-
pod = f.NewTestPod("pod-partial-resources", getResourceList("", "150Mi", "150Gi"), getResourceList("300m", "", ""))
150+
pod = newTestPod("pod-partial-resources", getResourceList("", "150Mi", "150Gi"), getResourceList("300m", "", ""))
150151
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
151152
framework.ExpectNoError(err)
152153

@@ -167,12 +168,12 @@ var _ = SIGDescribe("LimitRange", func() {
167168
}
168169

169170
ginkgo.By("Failing to create a Pod with less than min resources")
170-
pod = f.NewTestPod(podName, getResourceList("10m", "50Mi", "50Gi"), v1.ResourceList{})
171+
pod = newTestPod(podName, getResourceList("10m", "50Mi", "50Gi"), v1.ResourceList{})
171172
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
172173
framework.ExpectError(err)
173174

174175
ginkgo.By("Failing to create a Pod with more than max resources")
175-
pod = f.NewTestPod(podName, getResourceList("600m", "600Mi", "600Gi"), v1.ResourceList{})
176+
pod = newTestPod(podName, getResourceList("600m", "600Mi", "600Gi"), v1.ResourceList{})
176177
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
177178
framework.ExpectError(err)
178179

@@ -191,12 +192,12 @@ var _ = SIGDescribe("LimitRange", func() {
191192
framework.ExpectNoError(err)
192193

193194
ginkgo.By("Creating a Pod with less than former min resources")
194-
pod = f.NewTestPod(podName, getResourceList("10m", "50Mi", "50Gi"), v1.ResourceList{})
195+
pod = newTestPod(podName, getResourceList("10m", "50Mi", "50Gi"), v1.ResourceList{})
195196
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
196197
framework.ExpectNoError(err)
197198

198199
ginkgo.By("Failing to create a Pod with more than max resources")
199-
pod = f.NewTestPod(podName, getResourceList("600m", "600Mi", "600Gi"), v1.ResourceList{})
200+
pod = newTestPod(podName, getResourceList("600m", "600Mi", "600Gi"), v1.ResourceList{})
200201
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
201202
framework.ExpectError(err)
202203

@@ -235,7 +236,7 @@ var _ = SIGDescribe("LimitRange", func() {
235236
framework.ExpectNoError(err, "kubelet never observed the termination notice")
236237

237238
ginkgo.By("Creating a Pod with more than former max resources")
238-
pod = f.NewTestPod(podName+"2", getResourceList("600m", "600Mi", "600Gi"), v1.ResourceList{})
239+
pod = newTestPod(podName+"2", getResourceList("600m", "600Mi", "600Gi"), v1.ResourceList{})
239240
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
240241
framework.ExpectNoError(err)
241242
})
@@ -307,3 +308,24 @@ func newLimitRange(name, value string, limitType v1.LimitType,
307308
},
308309
}
309310
}
311+
312+
// newTestPod returns a pod that has the specified requests and limits
313+
func newTestPod(name string, requests v1.ResourceList, limits v1.ResourceList) *v1.Pod {
314+
return &v1.Pod{
315+
ObjectMeta: metav1.ObjectMeta{
316+
Name: name,
317+
},
318+
Spec: v1.PodSpec{
319+
Containers: []v1.Container{
320+
{
321+
Name: "pause",
322+
Image: imageutils.GetPauseImageName(),
323+
Resources: v1.ResourceRequirements{
324+
Requests: requests,
325+
Limits: limits,
326+
},
327+
},
328+
},
329+
},
330+
}
331+
}

0 commit comments

Comments
 (0)