Addressed reviewer comments

pull/6/head
Bobby (Babak) Salamat 2017-07-20 14:39:34 -07:00
parent c6bf7b8f52
commit 2612422a7f
4 changed files with 38 additions and 39 deletions

View File

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// TODO: This file can potentially be moved to a common place used by both e2e and integration tests.
package framework
import (

View File

@ -32,7 +32,7 @@ func TestNodeAffinity(t *testing.T) {
context := initTest(t, "node-affinity")
defer cleanupTest(t, context)
// Add a few nodes.
nodes, err := createNodes(context.clientSet, "testnode", 5)
nodes, err := createNodes(context.clientSet, "testnode", nil, 5)
if err != nil {
t.Fatalf("Cannot create nodes: %v", err)
}
@ -89,7 +89,7 @@ func TestPodAffinity(t *testing.T) {
context := initTest(t, "pod-affinity")
defer cleanupTest(t, context)
// Add a few nodes.
nodesInTopology, err := createNodes(context.clientSet, "in-topology", 5)
nodesInTopology, err := createNodes(context.clientSet, "in-topology", nil, 5)
if err != nil {
t.Fatalf("Cannot create nodes: %v", err)
}
@ -119,7 +119,7 @@ func TestPodAffinity(t *testing.T) {
t.Fatalf("Error running the attractor pod: %v", err)
}
// Add a few more nodes without the topology label.
_, err = createNodes(context.clientSet, "other-node", 5)
_, err = createNodes(context.clientSet, "other-node", nil, 5)
if err != nil {
t.Fatalf("Cannot create the second set of nodes: %v", err)
}

View File

@ -228,11 +228,11 @@ func TestSchedulerCreationInLegacyMode(t *testing.T) {
defer close(sched.Config().StopEverything)
sched.Run()
_, err = createNode(clientSet, "test-node")
_, err = createNode(clientSet, "test-node", nil)
if err != nil {
t.Fatalf("Failed to create node: %v", err)
}
pod, err := createDefaultPausePod(clientSet, "test-pod", "configmap")
pod, err := createPausePodWithResource(clientSet, "test-pod", "configmap", nil)
if err != nil {
t.Fatalf("Failed to create pod: %v", err)
}
@ -373,7 +373,7 @@ func TestUnschedulableNodes(t *testing.T) {
// Create the new pod, note that this needs to happen post unschedulable
// modification or we have a race in the test.
myPod, err := createDefaultPausePod(context.clientSet, "node-scheduling-test-pod", context.ns.Name)
myPod, err := createPausePodWithResource(context.clientSet, "node-scheduling-test-pod", context.ns.Name, nil)
if err != nil {
t.Fatalf("Failed to create pod: %v", err)
}
@ -451,7 +451,7 @@ func TestMultiScheduler(t *testing.T) {
context.clientSet.Core().Nodes().Create(node)
// 3. create 3 pods for testing
testPod, err := createDefaultPausePod(context.clientSet, "pod-without-scheduler-name", context.ns.Name)
testPod, err := createPausePodWithResource(context.clientSet, "pod-without-scheduler-name", context.ns.Name, nil)
if err != nil {
t.Fatalf("Failed to create pod: %v", err)
}
@ -587,7 +587,7 @@ func TestAllocatable(t *testing.T) {
v1.ResourceCPU: *resource.NewMilliQuantity(30, resource.DecimalSI),
v1.ResourceMemory: *resource.NewQuantity(30, resource.BinarySI),
}
allocNode, err := createNodeWithResource(context.clientSet, "node-allocatable-scheduler-test-node", nodeRes)
allocNode, err := createNode(context.clientSet, "node-allocatable-scheduler-test-node", nodeRes)
if err != nil {
t.Fatalf("Failed to create node: %v", err)
}

View File

@ -162,9 +162,16 @@ func waitForNodeLabels(cs clientset.Interface, nodeName string, labels map[strin
return wait.Poll(time.Millisecond*100, wait.ForeverTestTimeout, nodeHasLabels(cs, nodeName, labels))
}
// createNodeWithResource creates a node with the given resource list and
// returns a pointer and error status.
func createNodeWithResource(cs clientset.Interface, name string, res *v1.ResourceList) (*v1.Node, error) {
// createNode creates a node with the given resource list and
// returns a pointer and error status. If 'res' is nil, a predefined amount of
// resource will be used.
func createNode(cs clientset.Interface, name string, res *v1.ResourceList) (*v1.Node, error) {
// if resource is nil, we use a default amount of resources for the node.
if res == nil {
res = &v1.ResourceList{
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
}
}
n := &v1.Node{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: v1.NodeSpec{Unschedulable: false},
@ -175,22 +182,13 @@ func createNodeWithResource(cs clientset.Interface, name string, res *v1.Resourc
return cs.CoreV1().Nodes().Create(n)
}
// createNode creates a node with predefined resources and returns a pointer and
// error status.
func createNode(cs clientset.Interface, name string) (*v1.Node, error) {
res := v1.ResourceList{
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
}
return createNodeWithResource(cs, name, &res)
}
// createNodes creates `numNodes` nodes. The created node names will be in the
// form of "`prefix`-X" where X is an ordinal.
func createNodes(cs clientset.Interface, prefix string, numNodes int) ([]*v1.Node, error) {
func createNodes(cs clientset.Interface, prefix string, res *v1.ResourceList, numNodes int) ([]*v1.Node, error) {
nodes := make([]*v1.Node, numNodes)
for i := 0; i < numNodes; i++ {
nodeName := fmt.Sprintf("%v-%d", prefix, i)
node, err := createNode(cs, nodeName)
node, err := createNode(cs, nodeName, res)
if err != nil {
return nodes[:], err
}
@ -247,24 +245,23 @@ func createPausePod(cs clientset.Interface, conf *pausePodConfig) (*v1.Pod, erro
}
// createPausePodWithResource creates a pod with "Pause" image and the given
// resources and returns its pointer and error status.
// resources and returns its pointer and error status. The resource list can be
// nil.
func createPausePodWithResource(cs clientset.Interface, podName string, nsName string, res *v1.ResourceList) (*v1.Pod, error) {
conf := pausePodConfig{
Name: podName,
Namespace: nsName,
Resources: &v1.ResourceRequirements{
Requests: *res,
},
}
return createPausePod(cs, &conf)
}
// createDefaultPausePod creates a pod with "Pause" image and returns its pointer
// and error status.
func createDefaultPausePod(cs clientset.Interface, podName string, nsName string) (*v1.Pod, error) {
conf := pausePodConfig{
Name: podName,
Namespace: nsName,
var conf pausePodConfig
if res == nil {
conf = pausePodConfig{
Name: podName,
Namespace: nsName,
}
} else {
conf = pausePodConfig{
Name: podName,
Namespace: nsName,
Resources: &v1.ResourceRequirements{
Requests: *res,
},
}
}
return createPausePod(cs, &conf)
}