@@ -157,9 +157,7 @@ func TestAdmitCaps(t *testing.T) {
157
157
}
158
158
159
159
func testSCCAdmit (testCaseName string , sccs []* securityapi.SecurityContextConstraints , pod * kapi.Pod , shouldPass bool , t * testing.T ) {
160
- namespace := admissiontesting .CreateNamespaceForTest ()
161
- serviceAccount := admissiontesting .CreateSAForTest ()
162
- tc := clientsetfake .NewSimpleClientset (namespace , serviceAccount )
160
+ tc := setupClientSet ()
163
161
indexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc })
164
162
cache := securitylisters .NewSecurityContextConstraintsLister (indexer )
165
163
for _ , scc := range sccs {
@@ -180,15 +178,11 @@ func testSCCAdmit(testCaseName string, sccs []*securityapi.SecurityContextConstr
180
178
}
181
179
182
180
func TestAdmitSuccess (t * testing.T ) {
183
- // create the annotated namespace and add it to the fake client
184
- namespace := admissiontesting .CreateNamespaceForTest ()
185
- serviceAccount := admissiontesting .CreateSAForTest ()
181
+ tc := setupClientSet ()
186
182
187
183
// used for cases where things are preallocated
188
184
defaultGroup := int64 (2 )
189
185
190
- tc := clientsetfake .NewSimpleClientset (namespace , serviceAccount )
191
-
192
186
// create scc that requires allocation retrieval
193
187
saSCC := & securityapi.SecurityContextConstraints {
194
188
ObjectMeta : metav1.ObjectMeta {
@@ -374,11 +368,7 @@ func TestAdmitSuccess(t *testing.T) {
374
368
}
375
369
376
370
func TestAdmitFailure (t * testing.T ) {
377
- // create the annotated namespace and add it to the fake client
378
- namespace := admissiontesting .CreateNamespaceForTest ()
379
- serviceAccount := admissiontesting .CreateSAForTest ()
380
-
381
- tc := clientsetfake .NewSimpleClientset (namespace , serviceAccount )
371
+ tc := setupClientSet ()
382
372
383
373
// create scc that requires allocation retrieval
384
374
saSCC := & securityapi.SecurityContextConstraints {
@@ -954,10 +944,7 @@ func TestAdmitWithPrioritizedSCC(t *testing.T) {
954
944
// SCCs and ensure that they come out with the right annotation. This means admission
955
945
// is using the sort strategy we expect.
956
946
957
- namespace := admissiontesting .CreateNamespaceForTest ()
958
- serviceAccount := admissiontesting .CreateSAForTest ()
959
- serviceAccount .Namespace = namespace .Name
960
- tc := clientsetfake .NewSimpleClientset (namespace , serviceAccount )
947
+ tc := setupClientSet ()
961
948
962
949
indexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc })
963
950
cache := securitylisters .NewSecurityContextConstraintsLister (indexer )
@@ -1191,3 +1178,12 @@ func goodPod() *kapi.Pod {
1191
1178
},
1192
1179
}
1193
1180
}
1181
+
1182
+ func setupClientSet () * clientsetfake.Clientset {
1183
+ // create the annotated namespace and add it to the fake client
1184
+ namespace := admissiontesting .CreateNamespaceForTest ()
1185
+ serviceAccount := admissiontesting .CreateSAForTest ()
1186
+ serviceAccount .Namespace = namespace .Name
1187
+
1188
+ return clientsetfake .NewSimpleClientset (namespace , serviceAccount )
1189
+ }
0 commit comments