Repository: kubernetes/kubernetes
File: test/integration/dra/dra_test.go (Go)

Code before:
		startScheduler(tCtx)

		podWithOneContainer := st.MakePod().Name("test-pod").Namespace(namespace).Container("test-container").Obj()
		pod := createPodWithExtendedResource(tCtx, namespace, resourceName, "1", podWithOneContainer)

		schedulingAttempted := gomega.HaveField("Status.Conditions", gomega.ContainElement(
			gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
				"Type":    gomega.Equal(v1.PodScheduled),
				"Status":  gomega.Equal(v1.ConditionFalse),
				"Reason":  gomega.Equal("Unschedulable"),
				"Message": gomega.Equal(fmt.Sprintf("0/8 nodes are available: 8 Insufficient %s. no new claims to deallocate, preemption: 0/8 nodes are available: 8 Preemption is not helpful for scheduling.", resourceName)),
			}),
		))
		if enabled {
			// pod can be scheduled as the drivers in testPublishResourceSlices provide the devices.
			schedulingAttempted = gomega.HaveField("Status.Conditions", gomega.ContainElement(
				gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
					"Type":   gomega.Equal(v1.PodScheduled),
					"Status": gomega.Equal(v1.ConditionTrue),
				}),
			))
		}
		tCtx.Eventually(func(tCtx ktesting.TContext) (*v1.Pod, error) {
			return tCtx.Client().CoreV1().Pods(namespace).Get(tCtx, pod.Name, metav1.GetOptions{})
		}).WithTimeout(time.Minute).WithPolling(time.Second).Should(schedulingAttempted)
	})
}

func testPublishResourceSlices(tCtx ktesting.TContext, haveLatestAPI bool, disabledFeatures ...featuregate.Feature) {
	tCtx.Parallel()

	namespace := createTestNamespace(tCtx, nil)
	driverName := namespace + ".example.com"
	listDriverSlices := metav1.ListOptions{
		FieldSelector: resourceapi.ResourceSliceSelectorDriver + "=" + driverName,
	}
	poolName := "global"
	resources := &resourceslice.DriverResources{
		Pools: map[string]resourceslice.Pool{
			poolName: {
				Slices: []resourceslice.Slice{
					{
						Devices: []resourceapi.Device{
							{
								Name: "device-simple",
							},
						},
					},
					{
						SharedCounters: []resourceapi.CounterSet{
							{

Review comment (suggestion):
It's not directly visible that this is the `!enabled` matcher, it's too far removed from the following if check, which wasn't shown in the context of the diff.

Can we make this more explicit with
```
var schedulingAttempted gomega.GomegaMatcher

if enabled {
    schedulingAttempted = ...
} else 
   schedulingAttempted = ...
}

Code after:
	}

	slice := st.MakeResourceSlice("worker-0", driverName).Devices(device1)
	createSlice(tCtx, slice.Obj())

	startScheduler(tCtx)

	podWithOneContainer := st.MakePod().Name(podName).Namespace(namespace).Container("test-container").Obj()
	pod := createPodWithExtendedResource(tCtx, namespace, resourceName, "1", podWithOneContainer)

	var schedulingAttempted gtypes.GomegaMatcher
	if enabled {
		// Scheduled using device1 in the slice above.
		schedulingAttempted = gomega.HaveField("Status.Conditions", gomega.ContainElement(
			gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
				"Type":   gomega.Equal(v1.PodScheduled),
				"Status": gomega.Equal(v1.ConditionTrue),
			}),
		))
	} else {
		schedulingAttempted = gomega.HaveField("Status.Conditions", gomega.ContainElement(
			gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
				"Type":    gomega.Equal(v1.PodScheduled),
				"Status":  gomega.Equal(v1.ConditionFalse),
				"Reason":  gomega.Equal("Unschedulable"),
				"Message": gomega.Equal(fmt.Sprintf("0/8 nodes are available: 8 Insufficient %s. no new claims to deallocate, preemption: 0/8 nodes are available: 8 Preemption is not helpful for scheduling.", resourceName)),
			}),
		))
	}
	tCtx.Eventually(func(tCtx ktesting.TContext) (*v1.Pod, error) {
		return tCtx.Client().CoreV1().Pods(namespace).Get(tCtx, pod.Name, metav1.GetOptions{})
	}).WithTimeout(time.Minute).WithPolling(time.Second).Should(schedulingAttempted)
}

func testPublishResourceSlices(tCtx ktesting.TContext, haveLatestAPI bool, disabledFeatures ...featuregate.Feature) {
	tCtx.Parallel()

	namespace := createTestNamespace(tCtx, nil)
	driverName := namespace + ".example.com"
	listDriverSlices := metav1.ListOptions{
		FieldSelector: resourceapi.ResourceSliceSelectorDriver + "=" + driverName,
	}
	poolName := "global"
	resources := &resourceslice.DriverResources{
		Pools: map[string]resourceslice.Pool{
			poolName: {
				Slices: []resourceslice.Slice{
					{
						Devices: []resourceapi.Device{
							{
								Name: "device-simple",