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

Code before:
			ginkgo.By("waiting for claim to get deallocated")
			gomega.Eventually(ctx, func(ctx context.Context) (*resourceapi.ResourceClaim, error) {
				return f.ClientSet.ResourceV1().ResourceClaims(f.Namespace.Name).Get(ctx, claim.Name, metav1.GetOptions{})
			}).WithTimeout(f.Timeouts.PodDelete).Should(gomega.HaveField("Status.Allocation", (*resourceapi.AllocationResult)(nil)))
		})
	}

	singleNodeMultipleClaimsTests := func(withKubelet bool) {
		nodes := drautils.NewNodes(f, 1, 1)
		// Allow allocating more than one device so that multiple claims can be prepared on the same node.
		maxAllocations := 2
		driver := drautils.NewDriver(f, nodes, drautils.DriverResources(maxAllocations)) // All tests get their own driver instance.
		driver.WithKubelet = withKubelet
		b := drautils.NewBuilder(f, driver)
		// We have to set the parameters *before* creating the class.
		b.ClassParameters = `{"x":"y"}`
		expectedEnv := []string{"admin_x", "y"}
		_, expected := b.ParametersEnv()
		expectedEnv = append(expectedEnv, expected...)

		ginkgo.It("requests an already allocated and a new claim for a pod", func(ctx context.Context) {
			// This test covers a situation when a pod references a mix of already-prepared and new claims.
			firstClaim := b.ExternalClaim()

			secondClaim := firstClaim.DeepCopy()
			secondClaim.Name = "second-external-claim" + driver.NameSuffix

			b.Create(ctx, firstClaim, secondClaim)

			// First pod uses only firstClaim
			firstPod := b.PodExternal()
			b.Create(ctx, firstPod)
			b.TestPod(ctx, f, firstPod)

			// Second pod uses firstClaim (already prepared) + secondClaim (new)
			secondPod := firstPod.DeepCopy()
			secondPod.Name = "second-pod"

			firstClaimName := firstClaim.Name
			secondClaimName := secondClaim.Name

			secondPod.Spec.ResourceClaims = []v1.PodResourceClaim{
				{
					Name:              "first",
					ResourceClaimName: &firstClaimName,
				},
				{
					Name:              "second",
					ResourceClaimName: &secondClaimName,
				},
			}

Review comment (suggestion):
```suggestion
			secondClaim := b.ExternalClaim()
```

Code after:
			gomega.Eventually(ctx, func(ctx context.Context) (*resourceapi.ResourceClaim, error) {
				return f.ClientSet.ResourceV1().ResourceClaims(f.Namespace.Name).Get(ctx, claim.Name, metav1.GetOptions{})
			}).WithTimeout(f.Timeouts.PodDelete).ShouldNot(gomega.HaveField("Status.Allocation", (*resourceapi.AllocationResult)(nil)))

			b.TestPod(tCtx, pod)

			ginkgo.By(fmt.Sprintf("deleting pod %s", klog.KObj(pod)))
			framework.ExpectNoError(f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(ctx, pod.Name, metav1.DeleteOptions{}))

			ginkgo.By("waiting for claim to get deallocated")
			gomega.Eventually(ctx, func(ctx context.Context) (*resourceapi.ResourceClaim, error) {
				return f.ClientSet.ResourceV1().ResourceClaims(f.Namespace.Name).Get(ctx, claim.Name, metav1.GetOptions{})
			}).WithTimeout(f.Timeouts.PodDelete).Should(gomega.HaveField("Status.Allocation", (*resourceapi.AllocationResult)(nil)))
		})

		if withKubelet {
			// Serial because the example device plugin can only be deployed with one instance at a time.
			f.It("supports extended resources together with ResourceClaim", f.WithSerial(), func(ctx context.Context) {
				tCtx := f.TContext(ctx)
				extendedResourceName := deployDevicePlugin(ctx, f, nodes.NodeNames[0:1])

				pod := b.PodExternal()
				resources := v1.ResourceList{extendedResourceName: resource.MustParse("1")}
				pod.Spec.Containers[0].Resources.Requests = resources
				pod.Spec.Containers[0].Resources.Limits = resources
				claim := b.ExternalClaim()
				b.Create(tCtx, claim, pod)
				b.TestPod(tCtx, pod)
			})
		}
	}

	singleNodeMultipleClaimsTests := func() {
		nodes := drautils.NewNodes(f, 1, 1)
		// Allow allocating more than one device so that multiple claims can be prepared on the same node.
		maxAllocations := 2
		driver := drautils.NewDriver(f, nodes, drautils.DriverResources(maxAllocations)) // All tests get their own driver instance.
		driver.WithKubelet = true
		b := drautils.NewBuilder(f, driver)

		// https://github.com/kubernetes/kubernetes/issues/135901 was fixed in master for Kubernetes 1.35 and not backported
		// so this test only passes for kubelet >= 1.35.
		f.It("requests an already allocated and a new claim for a pod", f.WithLabel("KubeletMinVersion:1.35"), func(ctx context.Context) {
			// This test covers a situation when a pod references a mix of already-prepared and new claims.
			tCtx := f.TContext(ctx)

			firstClaim := b.ExternalClaim()
			secondClaim := b.ExternalClaim()

			b.Create(tCtx, firstClaim, secondClaim)