Skip to content

Commit 8ae6aa2

Browse files
fasaxck8s-publishing-bot
authored andcommitted
client-go: Clear the ResourceVersionMatch on paged list calls
API server rejects continuations with ResourceVersionMatch set. Kubernetes-commit: cc6c36f286d59187902b0f9b6e15f80b824acc7c
1 parent 72a8f74 commit 8ae6aa2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tools/pager/pager.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runti
7878
options.Limit = p.PageSize
7979
}
8080
requestedResourceVersion := options.ResourceVersion
81+
requestedResourceVersionMatch := options.ResourceVersionMatch
8182
var list *metainternalversion.List
8283
paginatedResult := false
8384

@@ -102,6 +103,7 @@ func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runti
102103
options.Limit = 0
103104
options.Continue = ""
104105
options.ResourceVersion = requestedResourceVersion
106+
options.ResourceVersionMatch = requestedResourceVersionMatch
105107
result, err := p.PageFn(ctx, options)
106108
return result, paginatedResult, err
107109
}
@@ -135,10 +137,11 @@ func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runti
135137

136138
// set the next loop up
137139
options.Continue = m.GetContinue()
138-
// Clear the ResourceVersion on the subsequent List calls to avoid the
140+
// Clear the ResourceVersion(Match) on the subsequent List calls to avoid the
139141
// `specifying resource version is not allowed when using continue` error.
140142
// See https://github.com/kubernetes/kubernetes/issues/85221#issuecomment-553748143.
141143
options.ResourceVersion = ""
144+
options.ResourceVersionMatch = ""
142145
// At this point, result is already paginated.
143146
paginatedResult = true
144147
}

tools/pager/pager_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (p *testPager) PagedList(ctx context.Context, options metav1.ListOptions) (
7676
p.t.Errorf("invariant violated, specifying resource version (%s) is not allowed when using continue (%s).", options.ResourceVersion, options.Continue)
7777
return nil, fmt.Errorf("invariant violated")
7878
}
79+
if options.Continue != "" && options.ResourceVersionMatch != "" {
80+
p.t.Errorf("invariant violated, specifying resource version match type (%s) is not allowed when using continue (%s).", options.ResourceVersionMatch, options.Continue)
81+
return nil, fmt.Errorf("invariant violated")
82+
}
7983
var list metainternalversion.List
8084
total := options.Limit
8185
if total == 0 {
@@ -201,6 +205,13 @@ func TestListPager_List(t *testing.T) {
201205
want: list(11, "rv:20"),
202206
wantPaged: true,
203207
},
208+
{
209+
name: "two pages with resourceVersion and resourceVersionMatch",
210+
fields: fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 11, rv: "rv:20"}).PagedList},
211+
args: args{options: metav1.ListOptions{ResourceVersion: "rv:10", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan}},
212+
want: list(11, "rv:20"),
213+
wantPaged: true,
214+
},
204215
}
205216
for _, tt := range tests {
206217
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)