From f0a0019039d4b5635eccb793b7743a3a92e433ab Mon Sep 17 00:00:00 2001 From: muhammad adil ghaffar Date: Wed, 13 Mar 2024 15:08:26 +0200 Subject: [PATCH] Adding pagination to ListOverlappingIPs to fix context deadline error. Signed-off-by: muhammad adil ghaffar --- pkg/storage/kubernetes/client.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/storage/kubernetes/client.go b/pkg/storage/kubernetes/client.go index 2fdc517af..a7f414967 100644 --- a/pkg/storage/kubernetes/client.go +++ b/pkg/storage/kubernetes/client.go @@ -120,12 +120,22 @@ func (i *Client) ListOverlappingIPs(ctx context.Context) ([]whereaboutsv1alpha1. ctxWithTimeout, cancel := context.WithTimeout(ctx, storage.RequestTimeout) defer cancel() - overlappingIPsList, err := i.client.WhereaboutsV1alpha1().OverlappingRangeIPReservations("").List(ctxWithTimeout, metav1.ListOptions{}) - if err != nil { - return nil, err + listOptions := metav1.ListOptions{ + Limit: 50, } - - return overlappingIPsList.Items, nil + var overlappingIPsList []whereaboutsv1alpha1.OverlappingRangeIPReservation + for { + overlappingIPs, err := i.client.WhereaboutsV1alpha1().OverlappingRangeIPReservations("").List(ctxWithTimeout, listOptions) + if err != nil { + return nil, err + } + overlappingIPsList = append(overlappingIPsList, overlappingIPs.Items...) + if overlappingIPs.Continue == "" { + break + } + listOptions.Continue = overlappingIPs.Continue + } + return overlappingIPsList, nil } func (i *Client) DeleteOverlappingIP(ctx context.Context, clusterWideIP *whereaboutsv1alpha1.OverlappingRangeIPReservation) error {