Skip to content

Commit e59c785

Browse files
authored
Merge pull request #6262 from ykakarap/retry-listObjByGVK
🐛 make `listObjByGVK` resilient
2 parents e41b201 + 92aafaa commit e59c785

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cmd/clusterctl/client/cluster/proxy.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/pkg/errors"
2525
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
26-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2928
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -359,11 +358,13 @@ func listObjByGVK(c client.Client, groupVersion, kind string, options []client.L
359358
objList.SetAPIVersion(groupVersion)
360359
objList.SetKind(kind)
361360

362-
if err := c.List(ctx, objList, options...); err != nil {
363-
if !apierrors.IsNotFound(err) {
364-
return nil, errors.Wrapf(err, "failed to list objects for the %q GroupVersionKind", objList.GroupVersionKind())
365-
}
361+
resourceListBackoff := newReadBackoff()
362+
if err := retryWithExponentialBackoff(resourceListBackoff, func() error {
363+
return c.List(ctx, objList, options...)
364+
}); err != nil {
365+
return nil, errors.Wrapf(err, "failed to list objects for the %q GroupVersionKind", objList.GroupVersionKind())
366366
}
367+
367368
return objList, nil
368369
}
369370

0 commit comments

Comments
 (0)