From 8e4e43a1204d457430a309153d475cd7ef421649 Mon Sep 17 00:00:00 2001 From: Grant Spence Date: Mon, 6 Apr 2026 15:10:24 -0400 Subject: [PATCH] OCPBUGS-81751: Fix GatewayClass update conflict in markTestDone Add retry logic to markTestDone to handle optimistic locking conflicts when updating GatewayClass annotations. The CIO actively manages the GatewayClass (updating conditions, status, finalizers) which can cause 409 Conflict errors when tests try to update annotations. Using RetryOnConflict ensures the test automatically retries with the latest resourceVersion when concurrent updates occur. Fixes flake: Operation cannot be fulfilled on gatewayclasses.gateway.networking.k8s.io "openshift-default": the object has been modified; please apply your changes to the latest version and try again https://redhat.atlassian.net/browse/OCPBUGS-81751 Co-Authored-By: Claude Opus 4.6 --- test/extended/router/gatewayapicontroller.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/extended/router/gatewayapicontroller.go b/test/extended/router/gatewayapicontroller.go index 4d77832a0b6f..8570117f7481 100644 --- a/test/extended/router/gatewayapicontroller.go +++ b/test/extended/router/gatewayapicontroller.go @@ -33,6 +33,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apiserver/pkg/storage/names" + "k8s.io/client-go/util/retry" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" ) @@ -1121,14 +1122,19 @@ func annotationKeyForTest(testName string) string { // These annotations are used to determine whether it is safe to clean up the // gatewayclass and other shared resources. func markTestDone(oc *exutil.CLI, testName string) { - gwc, err := oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Get(context.Background(), gatewayClassName, metav1.GetOptions{}) - o.Expect(err).NotTo(o.HaveOccurred()) + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + gwc, err := oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Get(context.Background(), gatewayClassName, metav1.GetOptions{}) + if err != nil { + return err + } - if gwc.Annotations == nil { - gwc.Annotations = map[string]string{} - } - gwc.Annotations[annotationKeyForTest(testName)] = "" - _, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Update(context.Background(), gwc, metav1.UpdateOptions{}) + if gwc.Annotations == nil { + gwc.Annotations = map[string]string{} + } + gwc.Annotations[annotationKeyForTest(testName)] = "" + _, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Update(context.Background(), gwc, metav1.UpdateOptions{}) + return err + }) o.Expect(err).NotTo(o.HaveOccurred()) }