Merge pull request #135377 from harche/dra_flake_test

Fix race condition in DRA health e2e test pod status update
This commit is contained in:
Kubernetes Prow Robot 2026-01-08 03:01:46 +05:30 committed by GitHub
commit 817f68f75f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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.