Skip to content

Commit

Permalink
fix(e2e): retry on conflict when deleting extended resource
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Nov 24, 2024
1 parent cf480a3 commit 89e23dd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions test/e2e/framework/node/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/retry"

"k8s.io/kubernetes/test/e2e/framework"
testutils "k8s.io/kubernetes/test/utils"
Expand Down Expand Up @@ -204,10 +205,15 @@ func RemoveExtendedResource(ctx context.Context, clientSet clientset.Interface,
extendedResource := v1.ResourceName(extendedResourceName)

ginkgo.By("Removing a custom resource")
node, err := clientSet.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
framework.ExpectNoError(err)
delete(node.Status.Capacity, extendedResource)
delete(node.Status.Allocatable, extendedResource)
_, err = clientSet.CoreV1().Nodes().UpdateStatus(ctx, node, metav1.UpdateOptions{})
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
node, err := clientSet.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get node %s: %w", nodeName, err)
}
delete(node.Status.Capacity, extendedResource)
delete(node.Status.Allocatable, extendedResource)
_, err = clientSet.CoreV1().Nodes().UpdateStatus(ctx, node, metav1.UpdateOptions{})
return err
})
framework.ExpectNoError(err)
}

0 comments on commit 89e23dd

Please sign in to comment.