dra e2e: unify per-node resource specification
When using a builder pattern for the actual callback, some common code can be moved into a single function.
This commit is contained in:
		| @@ -48,12 +48,26 @@ const ( | |||||||
| 	podStartTimeout = 5 * time.Minute | 	podStartTimeout = 5 * time.Minute | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | // networkResources can be passed to NewDriver directly. | ||||||
| func networkResources() app.Resources { | func networkResources() app.Resources { | ||||||
| 	return app.Resources{ | 	return app.Resources{ | ||||||
| 		Shareable: true, | 		Shareable: true, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // perNode returns a function which can be passed to NewDriver. The nodes | ||||||
|  | // parameter has be instantiated, but not initialized yet, so the returned | ||||||
|  | // function has to capture it and use it when being called. | ||||||
|  | func perNode(maxAllocations int, nodes *Nodes) func() app.Resources { | ||||||
|  | 	return func() app.Resources { | ||||||
|  | 		return app.Resources{ | ||||||
|  | 			NodeLocal:      true, | ||||||
|  | 			MaxAllocations: maxAllocations, | ||||||
|  | 			Nodes:          nodes.NodeNames, | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, func() { | var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, func() { | ||||||
| 	f := framework.NewDefaultFramework("dra") | 	f := framework.NewDefaultFramework("dra") | ||||||
|  |  | ||||||
| @@ -567,13 +581,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, | |||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
| 		ginkgo.Context("with node-local resources", func() { | 		ginkgo.Context("with node-local resources", func() { | ||||||
| 			driver := NewDriver(f, nodes, func() app.Resources { | 			driver := NewDriver(f, nodes, perNode(1, nodes)) | ||||||
| 				return app.Resources{ |  | ||||||
| 					NodeLocal:      true, |  | ||||||
| 					MaxAllocations: 1, |  | ||||||
| 					Nodes:          nodes.NodeNames, |  | ||||||
| 				} |  | ||||||
| 			}) |  | ||||||
| 			b := newBuilder(f, driver) | 			b := newBuilder(f, driver) | ||||||
|  |  | ||||||
| 			tests := func(allocationMode resourcev1alpha2.AllocationMode) { | 			tests := func(allocationMode resourcev1alpha2.AllocationMode) { | ||||||
| @@ -628,13 +636,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, | |||||||
|  |  | ||||||
| 		ginkgo.Context("reallocation", func() { | 		ginkgo.Context("reallocation", func() { | ||||||
| 			var allocateWrapper2 app.AllocateWrapperType | 			var allocateWrapper2 app.AllocateWrapperType | ||||||
| 			driver := NewDriver(f, nodes, func() app.Resources { | 			driver := NewDriver(f, nodes, perNode(1, nodes)) | ||||||
| 				return app.Resources{ |  | ||||||
| 					NodeLocal:      true, |  | ||||||
| 					MaxAllocations: 1, |  | ||||||
| 					Nodes:          nodes.NodeNames, |  | ||||||
| 				} |  | ||||||
| 			}) |  | ||||||
| 			driver2 := NewDriver(f, nodes, func() app.Resources { | 			driver2 := NewDriver(f, nodes, func() app.Resources { | ||||||
| 				return app.Resources{ | 				return app.Resources{ | ||||||
| 					NodeLocal:      true, | 					NodeLocal:      true, | ||||||
| @@ -765,24 +767,12 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, | |||||||
|  |  | ||||||
| 	multipleDrivers := func(nodeV1alpha2, nodeV1alpha3 bool) { | 	multipleDrivers := func(nodeV1alpha2, nodeV1alpha3 bool) { | ||||||
| 		nodes := NewNodes(f, 1, 4) | 		nodes := NewNodes(f, 1, 4) | ||||||
| 		driver1 := NewDriver(f, nodes, func() app.Resources { | 		driver1 := NewDriver(f, nodes, perNode(2, nodes)) | ||||||
| 			return app.Resources{ |  | ||||||
| 				NodeLocal:      true, |  | ||||||
| 				MaxAllocations: 2, |  | ||||||
| 				Nodes:          nodes.NodeNames, |  | ||||||
| 			} |  | ||||||
| 		}) |  | ||||||
| 		driver1.NodeV1alpha2 = nodeV1alpha2 | 		driver1.NodeV1alpha2 = nodeV1alpha2 | ||||||
| 		driver1.NodeV1alpha3 = nodeV1alpha3 | 		driver1.NodeV1alpha3 = nodeV1alpha3 | ||||||
| 		b1 := newBuilder(f, driver1) | 		b1 := newBuilder(f, driver1) | ||||||
|  |  | ||||||
| 		driver2 := NewDriver(f, nodes, func() app.Resources { | 		driver2 := NewDriver(f, nodes, perNode(2, nodes)) | ||||||
| 			return app.Resources{ |  | ||||||
| 				NodeLocal:      true, |  | ||||||
| 				MaxAllocations: 2, |  | ||||||
| 				Nodes:          nodes.NodeNames, |  | ||||||
| 			} |  | ||||||
| 		}) |  | ||||||
| 		driver2.NameSuffix = "-other" | 		driver2.NameSuffix = "-other" | ||||||
| 		driver2.NodeV1alpha2 = nodeV1alpha2 | 		driver2.NodeV1alpha2 = nodeV1alpha2 | ||||||
| 		driver2.NodeV1alpha3 = nodeV1alpha3 | 		driver2.NodeV1alpha3 = nodeV1alpha3 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Patrick Ohly
					Patrick Ohly