Skip to content

Commit 9c3cdfb

Browse files
authored
fix: Using retryOnConflict to fix v4overlay scale tests failing. (#2314)
* fix: ctry using retryOnConflict for v4overlay scale test * fix: typo
1 parent 29502bc commit 9c3cdfb

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.pipelines/singletenancy/dualstack-overlay/dualstackoverlay-e2e-step-template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ steps:
154154
cd test/integration/datapath
155155
sudo -E env "PATH=$PATH" go test -count=1 datapath_windows_test.go -timeout 3m -tags connection -restartKubeproxy true -run ^TestDatapathWin$
156156
name: "WindowsDualStackOverlayDatapathTests"
157-
displayName: "Windows DaulStack Overlay Datapath Tests"
157+
displayName: "Windows DualStack Overlay Datapath Tests"
158158
retryCountOnTaskFailure: 3

test/internal/kubernetes/utils.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/client-go/tools/clientcmd"
2828
"k8s.io/client-go/tools/remotecommand"
2929
"k8s.io/client-go/util/homedir"
30+
k8sRetry "k8s.io/client-go/util/retry"
3031
)
3132

3233
const (
@@ -301,14 +302,27 @@ func WaitForPodDaemonset(ctx context.Context, clientset *kubernetes.Clientset, n
301302
}
302303

303304
func MustUpdateReplica(ctx context.Context, deploymentsClient typedappsv1.DeploymentInterface, deploymentName string, replicas int32) {
304-
deployment, err := deploymentsClient.Get(ctx, deploymentName, metav1.GetOptions{})
305-
if err != nil {
306-
panic(errors.Wrapf(err, "could not get deployment %s", deploymentName))
307-
}
305+
retryErr := k8sRetry.RetryOnConflict(k8sRetry.DefaultRetry, func() error {
306+
// Get the latest Deployment resource.
307+
deployment, getErr := deploymentsClient.Get(ctx, deploymentName, metav1.GetOptions{})
308+
if getErr != nil {
309+
return fmt.Errorf("failed to get deployment: %w", getErr)
310+
}
311+
312+
// Modify the number of replicas.
313+
deployment.Spec.Replicas = Int32ToPtr(replicas)
314+
315+
// Attempt to update the Deployment.
316+
_, updateErr := deploymentsClient.Update(ctx, deployment, metav1.UpdateOptions{})
317+
if updateErr != nil {
318+
return fmt.Errorf("failed to update deployment: %w", updateErr)
319+
}
320+
321+
return nil // No error, operation succeeded.
322+
})
308323

309-
deployment.Spec.Replicas = Int32ToPtr(replicas)
310-
if _, err := deploymentsClient.Update(ctx, deployment, metav1.UpdateOptions{}); err != nil {
311-
panic(errors.Wrapf(err, "could not update deployment %s", deploymentName))
324+
if retryErr != nil {
325+
panic(errors.Wrapf(retryErr, "could not update deployment %s", deploymentName))
312326
}
313327
}
314328

0 commit comments

Comments
 (0)