@@ -75,16 +75,34 @@ jobs:
7575 apply_file="$(go env GOMODCACHE)/sigs.k8s.io/gateway-api/conformance@v1.5.1/utils/kubernetes/apply.go"
7676 chmod u+w "$apply_file"
7777 python3 - "$apply_file" << 'PYEOF'
78- import sys, re
78+ import sys
7979 path = sys.argv[1]
8080 content = open(path).read()
81+ old = '\t\tuObj.SetResourceVersion(fetchedObj.GetResourceVersion())\n\t\ttlog.Logf(t, "Updating %s %s", uObj.GetName(), uObj.GetKind())\n\t\terr = c.Update(ctx, uObj)'
82+ new = '''\t\tuObj.SetResourceVersion(fetchedObj.GetResourceVersion())
83+ \t\ttlog.Logf(t, "Updating %s %s", uObj.GetName(), uObj.GetKind())
84+ \t\tfor i := 0; i < 5; i++ {
85+ \t\t\tif i > 0 {
86+ \t\t\t\ttime.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)
87+ \t\t\t\tlatest := &unstructured.Unstructured{}
88+ \t\t\t\tlatest.SetGroupVersionKind(uObj.GroupVersionKind())
89+ \t\t\t\tif getErr := c.Get(ctx, client.ObjectKeyFromObject(uObj), latest); getErr != nil {
90+ \t\t\t\t\terr = getErr
91+ \t\t\t\t\tbreak
92+ \t\t\t\t}
93+ \t\t\t\tuObj.SetResourceVersion(latest.GetResourceVersion())
94+ \t\t\t}
95+ \t\t\terr = c.Update(ctx, uObj)
96+ \t\t\tif err == nil || !apierrors.IsConflict(err) {
97+ \t\t\t\tbreak
98+ \t\t\t}
99+ \t\t}'''
100+ content = content.replace(old, new)
101+ # Add time import
81102 content = content.replace(
82- '"sigs.k8s.io/controller-runtime/pkg/client "',
83- '"sigs.k8s.io/controller-runtime/pkg/client "\n\t"k8s.io/client-go/util/retry "'
103+ '"testing "',
104+ '"testing "\n\t"time "'
84105 )
85- old = ' uObj.SetResourceVersion(fetchedObj.GetResourceVersion())\n tlog.Logf(t, "Updating %s %s", uObj.GetName(), uObj.GetKind())\n err = c.Update(ctx, uObj)'
86- new = ' uObj.SetResourceVersion(fetchedObj.GetResourceVersion())\n tlog.Logf(t, "Updating %s %s", uObj.GetName(), uObj.GetKind())\n err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {\n latest := &unstructured.Unstructured{}\n latest.SetGroupVersionKind(uObj.GroupVersionKind())\n if getErr := c.Get(ctx, client.ObjectKeyFromObject(uObj), latest); getErr != nil {\n return getErr\n }\n uObj.SetResourceVersion(latest.GetResourceVersion())\n return c.Update(ctx, uObj)\n })'
87- content = content.replace(old, new)
88106 open(path, 'w').write(content)
89107 print("Patched apply.go with conflict retry")
90108 PYEOF
0 commit comments