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

Code before:
			// 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) {
				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(ctx, claim, pod)
				b.TestPod(ctx, f, 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 and backported to Kubernetes 1.35.
		// An independent backport was introduced for 1.34: https://github.com/kubernetes/kubernetes/pull/136480
		f.It("requests an already allocated and a new claim for a pod", f.WithLabel("KubeletMinVersion:1.34"), 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 := b.ExternalClaim()

			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 := b.PodExternal()

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


Review comment (bug):
```suggestion
		// An independent backport was introduced for 1.34: https://github.com/kubernetes/kubernetes/pull/136480;
		// in the meantime this KubeletMinVersion:1.35 is necessary because
		// the latest 1.34 release still has the problem.
		f.It("requests an already allocated and a new claim for a pod", f.WithLabel("KubeletMinVersion:1.35"), func(ctx context.Context) {
```

I had an off-by-one error in my suggestion: this PR makes 1.35 okay for the test, but 1.34 isn't.

Code after:
			// 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) {
				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(ctx, claim, pod)
				b.TestPod(ctx, f, 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 and backported to Kubernetes 1.35.
		// An independent backport was introduced for 1.34: https://github.com/kubernetes/kubernetes/pull/136480;
		// in the meantime this KubeletMinVersion:1.35 is necessary because
		// the latest 1.34 release still has the problem.
		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.
			firstClaim := b.ExternalClaim()
			secondClaim := b.ExternalClaim()

			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 := b.PodExternal()

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