@@ -40,17 +40,17 @@ import (
40
40
func doPodResizeAdmissionPluginsTests (f * framework.Framework ) {
41
41
testcases := []struct {
42
42
name string
43
- enableAdmissionPlugin func (ctx context.Context , f * framework.Framework )
43
+ enableAdmissionPlugin func (ctx context.Context , f * framework.Framework , ns string )
44
44
wantMemoryError string
45
45
wantCPUError string
46
46
}{
47
47
{
48
48
name : "pod-resize-resource-quota-test" ,
49
- enableAdmissionPlugin : func (ctx context.Context , f * framework.Framework ) {
49
+ enableAdmissionPlugin : func (ctx context.Context , f * framework.Framework , ns string ) {
50
50
resourceQuota := v1.ResourceQuota {
51
51
ObjectMeta : metav1.ObjectMeta {
52
52
Name : "resize-resource-quota" ,
53
- Namespace : f . Namespace . Name ,
53
+ Namespace : ns ,
54
54
},
55
55
Spec : v1.ResourceQuotaSpec {
56
56
Hard : v1.ResourceList {
@@ -61,19 +61,19 @@ func doPodResizeAdmissionPluginsTests(f *framework.Framework) {
61
61
}
62
62
63
63
ginkgo .By ("Creating a ResourceQuota" )
64
- _ , rqErr := f .ClientSet .CoreV1 ().ResourceQuotas (f . Namespace . Name ).Create (ctx , & resourceQuota , metav1.CreateOptions {})
64
+ _ , rqErr := f .ClientSet .CoreV1 ().ResourceQuotas (ns ).Create (ctx , & resourceQuota , metav1.CreateOptions {})
65
65
framework .ExpectNoError (rqErr , "failed to create resource quota" )
66
66
},
67
67
wantMemoryError : "exceeded quota: resize-resource-quota, requested: memory=350Mi, used: memory=700Mi, limited: memory=800Mi" ,
68
68
wantCPUError : "exceeded quota: resize-resource-quota, requested: cpu=200m, used: cpu=700m, limited: cpu=800m" ,
69
69
},
70
70
{
71
71
name : "pod-resize-limit-ranger-test" ,
72
- enableAdmissionPlugin : func (ctx context.Context , f * framework.Framework ) {
72
+ enableAdmissionPlugin : func (ctx context.Context , f * framework.Framework , ns string ) {
73
73
lr := v1.LimitRange {
74
74
ObjectMeta : metav1.ObjectMeta {
75
75
Name : "resize-limit-ranger" ,
76
- Namespace : f . Namespace . Name ,
76
+ Namespace : ns ,
77
77
},
78
78
Spec : v1.LimitRangeSpec {
79
79
Limits : []v1.LimitRangeItem {
@@ -101,7 +101,7 @@ func doPodResizeAdmissionPluginsTests(f *framework.Framework) {
101
101
}
102
102
103
103
ginkgo .By ("Creating a LimitRanger" )
104
- _ , lrErr := f .ClientSet .CoreV1 ().LimitRanges (f . Namespace . Name ).Create (ctx , & lr , metav1.CreateOptions {})
104
+ _ , lrErr := f .ClientSet .CoreV1 ().LimitRanges (ns ).Create (ctx , & lr , metav1.CreateOptions {})
105
105
framework .ExpectNoError (lrErr , "failed to create limit ranger" )
106
106
},
107
107
wantMemoryError : "forbidden: maximum memory usage per Container is 500Mi, but limit is 750Mi" ,
@@ -111,6 +111,9 @@ func doPodResizeAdmissionPluginsTests(f *framework.Framework) {
111
111
112
112
for _ , tc := range testcases {
113
113
ginkgo .It (tc .name , func (ctx context.Context ) {
114
+ ns , err := f .CreateNamespace (ctx , tc .name , nil )
115
+ framework .ExpectNoError (err , "failed creating Namespace" )
116
+
114
117
containers := []e2epod.ResizableContainerInfo {
115
118
{
116
119
Name : "c1" ,
@@ -133,34 +136,33 @@ func doPodResizeAdmissionPluginsTests(f *framework.Framework) {
133
136
{"name":"c1", "resources":{"requests":{"cpu":"250m","memory":"750Mi"},"limits":{"cpu":"250m","memory":"750Mi"}}}
134
137
]}}`
135
138
136
- tc .enableAdmissionPlugin (ctx , f )
139
+ tc .enableAdmissionPlugin (ctx , f , ns . Name )
137
140
138
141
tStamp := strconv .Itoa (time .Now ().Nanosecond ())
139
142
e2epod .InitDefaultResizePolicy (containers )
140
143
e2epod .InitDefaultResizePolicy (expected )
141
- testPod1 := e2epod .MakePodWithResizableContainers (f . Namespace .Name , "testpod1" , tStamp , containers )
144
+ testPod1 := e2epod .MakePodWithResizableContainers (ns .Name , "testpod1" , tStamp , containers )
142
145
testPod1 = e2epod .MustMixinRestrictedPodSecurity (testPod1 )
143
- testPod2 := e2epod .MakePodWithResizableContainers (f . Namespace .Name , "testpod2" , tStamp , containers )
146
+ testPod2 := e2epod .MakePodWithResizableContainers (ns .Name , "testpod2" , tStamp , containers )
144
147
testPod2 = e2epod .MustMixinRestrictedPodSecurity (testPod2 )
145
148
146
149
ginkgo .By ("creating pods" )
147
150
podClient := e2epod .NewPodClient (f )
148
- newPod1 := podClient .CreateSync (ctx , testPod1 )
149
- newPod2 := podClient .CreateSync (ctx , testPod2 )
151
+ newPods := podClient .CreateBatch (ctx , []* v1.Pod {testPod1 , testPod2 })
150
152
151
153
ginkgo .By ("verifying initial pod resources, and policy are as expected" )
152
- e2epod .VerifyPodResources (newPod1 , containers )
154
+ e2epod .VerifyPodResources (newPods [ 0 ] , containers )
153
155
154
156
ginkgo .By ("patching pod for resize within resource quota" )
155
- patchedPod , pErr := f .ClientSet .CoreV1 ().Pods (newPod1 .Namespace ).Patch (ctx , newPod1 .Name ,
157
+ patchedPod , pErr := f .ClientSet .CoreV1 ().Pods (newPods [ 0 ] .Namespace ).Patch (ctx , newPods [ 0 ] .Name ,
156
158
types .StrategicMergePatchType , []byte (patchString ), metav1.PatchOptions {}, "resize" )
157
159
framework .ExpectNoError (pErr , "failed to patch pod for resize" )
158
160
159
161
ginkgo .By ("verifying pod patched for resize within resource quota" )
160
162
e2epod .VerifyPodResources (patchedPod , expected )
161
163
162
164
ginkgo .By ("waiting for resize to be actuated" )
163
- resizedPod := e2epod .WaitForPodResizeActuation (ctx , f , podClient , newPod1 )
165
+ resizedPod := e2epod .WaitForPodResizeActuation (ctx , f , podClient , newPods [ 0 ] )
164
166
e2epod .ExpectPodResized (ctx , f , resizedPod , expected )
165
167
166
168
ginkgo .By ("verifying pod resources after resize" )
@@ -189,10 +191,10 @@ func doPodResizeAdmissionPluginsTests(f *framework.Framework) {
189
191
framework .ExpectNoError (e2epod .VerifyPodStatusResources (patchedPodExceedMemory , expected ))
190
192
191
193
ginkgo .By ("deleting pods" )
192
- delErr1 := e2epod .DeletePodWithWait (ctx , f .ClientSet , newPod1 )
193
- framework .ExpectNoError (delErr1 , "failed to delete pod %s" , newPod1 .Name )
194
- delErr2 := e2epod .DeletePodWithWait (ctx , f .ClientSet , newPod2 )
195
- framework .ExpectNoError (delErr2 , "failed to delete pod %s" , newPod2 .Name )
194
+ delErr1 := e2epod .DeletePodWithWait (ctx , f .ClientSet , newPods [ 0 ] )
195
+ framework .ExpectNoError (delErr1 , "failed to delete pod %s" , newPods [ 0 ] .Name )
196
+ delErr2 := e2epod .DeletePodWithWait (ctx , f .ClientSet , newPods [ 1 ] )
197
+ framework .ExpectNoError (delErr2 , "failed to delete pod %s" , newPods [ 1 ] .Name )
196
198
})
197
199
}
198
200
0 commit comments