Simplify Create/Delete-TestingNamespace functions

This commit is contained in:
Wojciech Tyczyński
2022-05-15 15:33:19 +02:00
parent 9720d130e4
commit deef9e40de
35 changed files with 326 additions and 333 deletions

View File

@@ -19,7 +19,6 @@ package replicationcontroller
import (
"context"
"fmt"
"net/http/httptest"
"reflect"
"testing"
"time"
@@ -110,7 +109,7 @@ func newMatchingPod(podName, namespace string) *v1.Pod {
}
}
func rmSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, *replication.ReplicationManager, informers.SharedInformerFactory, clientset.Interface) {
func rmSetup(t *testing.T) (framework.CloseFunc, *replication.ReplicationManager, informers.SharedInformerFactory, clientset.Interface) {
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
_, s, closeFn := framework.RunAnAPIServer(controlPlaneConfig)
@@ -129,7 +128,7 @@ func rmSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, *replication.
replication.BurstReplicas,
)
return s, closeFn, rm, informers, clientSet
return closeFn, rm, informers, clientSet
}
// Run RC controller and informers
@@ -411,10 +410,10 @@ func TestAdoption(t *testing.T) {
}
for i, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
s, closeFn, rm, informers, clientSet := rmSetup(t)
closeFn, rm, informers, clientSet := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace(fmt.Sprintf("rc-adoption-%d", i), s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace(fmt.Sprintf("rc-adoption-%d", i), t)
defer framework.DeleteTestingNamespace(ns, t)
rcClient := clientSet.CoreV1().ReplicationControllers(ns.Name)
podClient := clientSet.CoreV1().Pods(ns.Name)
@@ -454,10 +453,10 @@ func TestAdoption(t *testing.T) {
}
func TestSpecReplicasChange(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-spec-replicas-change", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-spec-replicas-change", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -497,10 +496,10 @@ func TestSpecReplicasChange(t *testing.T) {
func TestLogarithmicScaleDown(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.LogarithmicScaleDown, true)()
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-spec-replicas-change", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-spec-replicas-change", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -534,10 +533,10 @@ func TestLogarithmicScaleDown(t *testing.T) {
}
func TestDeletingAndFailedPods(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-deleting-and-failed-pods", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-deleting-and-failed-pods", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -599,10 +598,10 @@ func TestDeletingAndFailedPods(t *testing.T) {
}
func TestOverlappingRCs(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-overlapping-rcs", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-overlapping-rcs", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -634,10 +633,10 @@ func TestOverlappingRCs(t *testing.T) {
}
func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-pod-orphaning-and-adoption-when-labels-change", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-pod-orphaning-and-adoption-when-labels-change", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -711,10 +710,10 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
}
func TestGeneralPodAdoption(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-general-pod-adoption", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-general-pod-adoption", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -743,10 +742,10 @@ func TestGeneralPodAdoption(t *testing.T) {
}
func TestReadyAndAvailableReplicas(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-ready-and-available-replicas", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-ready-and-available-replicas", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -795,10 +794,10 @@ func TestReadyAndAvailableReplicas(t *testing.T) {
}
func TestRCScaleSubresource(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-rc-scale-subresource", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-rc-scale-subresource", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()
@@ -814,10 +813,10 @@ func TestRCScaleSubresource(t *testing.T) {
}
func TestExtraPodsAdoptionAndDeletion(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-extra-pods-adoption-and-deletion", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-extra-pods-adoption-and-deletion", t)
defer framework.DeleteTestingNamespace(ns, t)
rc := newRC("rc", ns.Name, 2)
// Create 3 pods, RC should adopt only 2 of them
@@ -846,10 +845,10 @@ func TestExtraPodsAdoptionAndDeletion(t *testing.T) {
}
func TestFullyLabeledReplicas(t *testing.T) {
s, closeFn, rm, informers, c := rmSetup(t)
closeFn, rm, informers, c := rmSetup(t)
defer closeFn()
ns := framework.CreateTestingNamespace("test-fully-labeled-replicas", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
ns := framework.CreateTestingNamespace("test-fully-labeled-replicas", t)
defer framework.DeleteTestingNamespace(ns, t)
stopControllers := runControllerAndInformers(t, rm, informers, 0)
defer stopControllers()