Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 7973a13

Browse files
committed
Retry APIExports watch when channel got closed on idle
1 parent 48e00a7 commit 7973a13

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ func restConfigForAPIExport(ctx context.Context, cfg *rest.Config, apiExportName
191191
select {
192192
case <-ctx.Done():
193193
return nil, ctx.Err()
194-
case e := <-watch.ResultChan():
194+
case e, ok := <-watch.ResultChan():
195+
if !ok {
196+
// The channel has been closed. Let's retry watching in case it timed out on idle,
197+
// or fail in case connection to the server cannot be re-established.
198+
watch, err = apiExportClient.Watch(ctx, &apisv1alpha1.APIExportList{}, opts...)
199+
if err != nil {
200+
return nil, fmt.Errorf("error watching for APIExport: %w", err)
201+
}
202+
}
203+
195204
apiExport, ok := e.Object.(*apisv1alpha1.APIExport)
196205
if !ok {
197206
continue

0 commit comments

Comments
 (0)