Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate most of the remaining integration tests to run in dedicated namespace (when possible). #28490

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/client/unversioned/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type NodeInterface interface {
Create(node *api.Node) (*api.Node, error)
List(opts api.ListOptions) (*api.NodeList, error)
Delete(name string) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Update(*api.Node) (*api.Node, error)
UpdateStatus(*api.Node) (*api.Node, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Expand Down Expand Up @@ -76,6 +77,16 @@ func (c *nodes) Delete(name string) error {
return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error()
}

// DeleteCollection deletes a collection of nodes.
func (c *nodes) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
return c.r.Delete().
Resource(c.resourceName()).
VersionedParams(&listOptions, api.ParameterCodec).
Body(options).
Do().
Error()
}

// Update updates an existing node.
func (c *nodes) Update(node *api.Node) (*api.Node, error) {
result := &api.Node{}
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/unversioned/testclient/fake_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (c *FakeNodes) Delete(name string) error {
return err
}

func (c *FakeNodes) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
_, err := c.Fake.Invokes(NewRootDeleteCollectionAction("nodes", listOptions), &api.NodeList{})
return err
}

func (c *FakeNodes) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.Fake.InvokesWatch(NewRootWatchAction("nodes", opts))
}
Expand Down
20 changes: 12 additions & 8 deletions test/integration/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ func machine_3_Prioritizer(pod *api.Pod, nodes *api.NodeList) (*schedulerapi.Hos
}

func TestSchedulerExtender(t *testing.T) {
// TODO: Limit the test to a single non-default namespace and clean this up at the end.
framework.DeleteAllEtcdKeys()

_, s := framework.RunAMaster(nil)
defer s.Close()

ns := framework.CreateTestingNamespace("scheduler-extender", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)

restClient := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})

extender1 := &Extender{
Expand Down Expand Up @@ -240,15 +240,19 @@ func TestSchedulerExtender(t *testing.T) {
}
eventBroadcaster := record.NewBroadcaster()
schedulerConfig.Recorder = eventBroadcaster.NewRecorder(api.EventSource{Component: api.DefaultSchedulerName})
eventBroadcaster.StartRecordingToSink(restClient.Events(""))
eventBroadcaster.StartRecordingToSink(restClient.Events(ns.Name))
scheduler.New(schedulerConfig).Run()

defer close(schedulerConfig.StopEverything)

DoTestPodScheduling(t, restClient)
DoTestPodScheduling(ns, t, restClient)
}

func DoTestPodScheduling(t *testing.T, restClient *client.Client) {
func DoTestPodScheduling(ns *api.Namespace, t *testing.T, restClient *client.Client) {
// NOTE: This test cannot run in parallel, because it is creating and deleting
// non-namespaced objects (Nodes).
defer restClient.Nodes().DeleteCollection(nil, api.ListOptions{})

goodCondition := api.NodeCondition{
Type: api.NodeReady,
Status: api.ConditionTrue,
Expand Down Expand Up @@ -279,7 +283,7 @@ func DoTestPodScheduling(t *testing.T, restClient *client.Client) {
},
}

myPod, err := restClient.Pods(api.NamespaceDefault).Create(pod)
myPod, err := restClient.Pods(ns.Name).Create(pod)
if err != nil {
t.Fatalf("Failed to create pod: %v", err)
}
Expand All @@ -289,7 +293,7 @@ func DoTestPodScheduling(t *testing.T, restClient *client.Client) {
t.Fatalf("Failed to schedule pod: %v", err)
}

if myPod, err := restClient.Pods(api.NamespaceDefault).Get(myPod.Name); err != nil {
if myPod, err := restClient.Pods(ns.Name).Get(myPod.Name); err != nil {
t.Fatalf("Failed to get pod: %v", err)
} else if myPod.Spec.NodeName != "machine3" {
t.Fatalf("Failed to schedule using extender, expected machine3, got %v", myPod.Spec.NodeName)
Expand Down
17 changes: 9 additions & 8 deletions test/integration/framework/master_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ const (
// Rc manifest used to create pods for benchmarks.
// TODO: Convert this to a full path?
TestRCManifest = "benchmark-controller.json"

// Test Namspace, for pods and rcs.
TestNS = "test"
)

// MasterComponents is a control struct for all master components started via NewMasterComponents.
Expand Down Expand Up @@ -326,23 +323,27 @@ func StartRC(controller *api.ReplicationController, restClient *client.Client) (
return ScaleRC(created.Name, created.Namespace, controller.Spec.Replicas, restClient)
}

// StartPods check for numPods in TestNS. If they exist, it no-ops, otherwise it starts up
// StartPods check for numPods in namespace. If they exist, it no-ops, otherwise it starts up
// a temp rc, scales it to match numPods, then deletes the rc leaving behind the pods.
func StartPods(numPods int, host string, restClient *client.Client) error {
func StartPods(namespace string, numPods int, host string, restClient *client.Client) error {
start := time.Now()
defer func() {
glog.Infof("StartPods took %v with numPods %d", time.Since(start), numPods)
}()
hostField := fields.OneTermEqualSelector(api.PodHostField, host)
options := api.ListOptions{FieldSelector: hostField}
pods, err := restClient.Pods(TestNS).List(options)
pods, err := restClient.Pods(namespace).List(options)
if err != nil || len(pods.Items) == numPods {
return err
}
glog.Infof("Found %d pods that match host %v, require %d", len(pods.Items), hostField, numPods)
// For the sake of simplicity, assume all pods in TestNS have selectors matching TestRCManifest.
// For the sake of simplicity, assume all pods in namespace have selectors matching TestRCManifest.
controller := RCFromManifest(TestRCManifest)

// Overwrite namespace
controller.ObjectMeta.Namespace = namespace
controller.Spec.Template.ObjectMeta.Namespace = namespace

// Make the rc unique to the given host.
controller.Spec.Replicas = int32(numPods)
controller.Spec.Template.Spec.NodeName = host
Expand All @@ -355,7 +356,7 @@ func StartPods(numPods int, host string, restClient *client.Client) error {
} else {
// Delete the rc, otherwise when we restart master components for the next benchmark
// the rc controller will race with the pods controller in the rc manager.
return restClient.ReplicationControllers(TestNS).Delete(rc.Name)
return restClient.ReplicationControllers(namespace).Delete(rc.Name)
}
}

Expand Down