Fix race condition in DRA health e2e test pod status update

Signed-off-by: Harshal Patil <12152047+harche@users.noreply.github.com>
This commit is contained in:
Harshal Patil
2025-11-20 14:43:04 -05:00
parent b2ac9e206f
commit 1e71a25950

View File

@@ -26,6 +26,7 @@ package e2enode
import (
"context"
"encoding/json"
"errors"
"fmt"
"net"
@@ -47,6 +48,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
apitypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/kubernetes"
"k8s.io/component-base/metrics/testutil"
@@ -1736,14 +1738,17 @@ func createHealthTestPodAndClaim(ctx context.Context, f *framework.Framework, dr
e2epod.DeletePodOrFail(ctx, f.ClientSet, createdPod.Namespace, createdPod.Name)
})
// Update the Pod's status to include the ResourceClaimStatuses, mimicking the scheduler.
podToUpdate, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, createdPod.Name, metav1.GetOptions{})
framework.ExpectNoError(err)
podToUpdate.Status.ResourceClaimStatuses = []v1.PodResourceClaimStatus{
{Name: claimName, ResourceClaimName: &claimName},
}
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).UpdateStatus(ctx, podToUpdate, metav1.UpdateOptions{})
framework.ExpectNoError(err, "failed to update Pod status with ResourceClaimStatuses")
// Patch the Pod's status to include the ResourceClaimStatuses, mimicking the scheduler.
patch, err := json.Marshal(v1.Pod{
Status: v1.PodStatus{
ResourceClaimStatuses: []v1.PodResourceClaimStatus{
{Name: claimName, ResourceClaimName: &claimName},
},
},
})
framework.ExpectNoError(err, "failed to marshal patch for Pod status")
_, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Patch(ctx, createdPod.Name, apitypes.StrategicMergePatchType, patch, metav1.PatchOptions{}, "status")
framework.ExpectNoError(err, "failed to patch Pod status with ResourceClaimStatuses")
ginkgo.By(fmt.Sprintf("Allocating claim %q to pod %q with its real UID", claimName, podName))
// Get the created claim to ensure the latest version before updating.