@@ -157,9 +157,7 @@ func TestAdmitCaps(t *testing.T) {
157157}
158158
159159func 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 ()
163161 indexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc })
164162 cache := securitylisters .NewSecurityContextConstraintsLister (indexer )
165163 for _ , scc := range sccs {
@@ -180,15 +178,11 @@ func testSCCAdmit(testCaseName string, sccs []*securityapi.SecurityContextConstr
180178}
181179
182180func 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 ()
186182
187183 // used for cases where things are preallocated
188184 defaultGroup := int64 (2 )
189185
190- tc := clientsetfake .NewSimpleClientset (namespace , serviceAccount )
191-
192186 // create scc that requires allocation retrieval
193187 saSCC := & securityapi.SecurityContextConstraints {
194188 ObjectMeta : metav1.ObjectMeta {
@@ -374,11 +368,7 @@ func TestAdmitSuccess(t *testing.T) {
374368}
375369
376370func 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 ()
382372
383373 // create scc that requires allocation retrieval
384374 saSCC := & securityapi.SecurityContextConstraints {
@@ -954,10 +944,7 @@ func TestAdmitWithPrioritizedSCC(t *testing.T) {
954944 // SCCs and ensure that they come out with the right annotation. This means admission
955945 // is using the sort strategy we expect.
956946
957- namespace := admissiontesting .CreateNamespaceForTest ()
958- serviceAccount := admissiontesting .CreateSAForTest ()
959- serviceAccount .Namespace = namespace .Name
960- tc := clientsetfake .NewSimpleClientset (namespace , serviceAccount )
947+ tc := setupClientSet ()
961948
962949 indexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc })
963950 cache := securitylisters .NewSecurityContextConstraintsLister (indexer )
@@ -1191,3 +1178,12 @@ func goodPod() *kapi.Pod {
11911178 },
11921179 }
11931180}
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