Skip to content

Commit 8e4e43a

Browse files
gcs278claude
andcommitted
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 <noreply@anthropic.com>
1 parent c77ff4a commit 8e4e43a

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

test/extended/router/gatewayapicontroller.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/util/wait"
3535
"k8s.io/apiserver/pkg/storage/names"
36+
"k8s.io/client-go/util/retry"
3637
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
3738
)
3839

@@ -1121,14 +1122,19 @@ func annotationKeyForTest(testName string) string {
11211122
// These annotations are used to determine whether it is safe to clean up the
11221123
// gatewayclass and other shared resources.
11231124
func markTestDone(oc *exutil.CLI, testName string) {
1124-
gwc, err := oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Get(context.Background(), gatewayClassName, metav1.GetOptions{})
1125-
o.Expect(err).NotTo(o.HaveOccurred())
1125+
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
1126+
gwc, err := oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Get(context.Background(), gatewayClassName, metav1.GetOptions{})
1127+
if err != nil {
1128+
return err
1129+
}
11261130

1127-
if gwc.Annotations == nil {
1128-
gwc.Annotations = map[string]string{}
1129-
}
1130-
gwc.Annotations[annotationKeyForTest(testName)] = ""
1131-
_, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Update(context.Background(), gwc, metav1.UpdateOptions{})
1131+
if gwc.Annotations == nil {
1132+
gwc.Annotations = map[string]string{}
1133+
}
1134+
gwc.Annotations[annotationKeyForTest(testName)] = ""
1135+
_, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Update(context.Background(), gwc, metav1.UpdateOptions{})
1136+
return err
1137+
})
11321138
o.Expect(err).NotTo(o.HaveOccurred())
11331139
}
11341140

0 commit comments

Comments
 (0)