mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #107311 from fasaxc/fix-resource-ver-match
client-go: Clear the ResourceVersionMatch on paged list calls
This commit is contained in:
		@@ -78,6 +78,7 @@ func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runti
 | 
			
		||||
		options.Limit = p.PageSize
 | 
			
		||||
	}
 | 
			
		||||
	requestedResourceVersion := options.ResourceVersion
 | 
			
		||||
	requestedResourceVersionMatch := options.ResourceVersionMatch
 | 
			
		||||
	var list *metainternalversion.List
 | 
			
		||||
	paginatedResult := false
 | 
			
		||||
 | 
			
		||||
@@ -102,6 +103,7 @@ func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runti
 | 
			
		||||
			options.Limit = 0
 | 
			
		||||
			options.Continue = ""
 | 
			
		||||
			options.ResourceVersion = requestedResourceVersion
 | 
			
		||||
			options.ResourceVersionMatch = requestedResourceVersionMatch
 | 
			
		||||
			result, err := p.PageFn(ctx, options)
 | 
			
		||||
			return result, paginatedResult, err
 | 
			
		||||
		}
 | 
			
		||||
@@ -135,10 +137,11 @@ func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runti
 | 
			
		||||
 | 
			
		||||
		// set the next loop up
 | 
			
		||||
		options.Continue = m.GetContinue()
 | 
			
		||||
		// Clear the ResourceVersion on the subsequent List calls to avoid the
 | 
			
		||||
		// Clear the ResourceVersion(Match) on the subsequent List calls to avoid the
 | 
			
		||||
		// `specifying resource version is not allowed when using continue` error.
 | 
			
		||||
		// See https://github.com/kubernetes/kubernetes/issues/85221#issuecomment-553748143.
 | 
			
		||||
		options.ResourceVersion = ""
 | 
			
		||||
		options.ResourceVersionMatch = ""
 | 
			
		||||
		// At this point, result is already paginated.
 | 
			
		||||
		paginatedResult = true
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -76,6 +76,10 @@ func (p *testPager) PagedList(ctx context.Context, options metav1.ListOptions) (
 | 
			
		||||
		p.t.Errorf("invariant violated, specifying resource version (%s) is not allowed when using continue (%s).", options.ResourceVersion, options.Continue)
 | 
			
		||||
		return nil, fmt.Errorf("invariant violated")
 | 
			
		||||
	}
 | 
			
		||||
	if options.Continue != "" && options.ResourceVersionMatch != "" {
 | 
			
		||||
		p.t.Errorf("invariant violated, specifying resource version match type (%s) is not allowed when using continue (%s).", options.ResourceVersionMatch, options.Continue)
 | 
			
		||||
		return nil, fmt.Errorf("invariant violated")
 | 
			
		||||
	}
 | 
			
		||||
	var list metainternalversion.List
 | 
			
		||||
	total := options.Limit
 | 
			
		||||
	if total == 0 {
 | 
			
		||||
@@ -201,6 +205,13 @@ func TestListPager_List(t *testing.T) {
 | 
			
		||||
			want:      list(11, "rv:20"),
 | 
			
		||||
			wantPaged: true,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name:      "two pages with resourceVersion and resourceVersionMatch",
 | 
			
		||||
			fields:    fields{PageSize: 10, PageFn: (&testPager{t: t, expectPage: 10, remaining: 11, rv: "rv:20"}).PagedList},
 | 
			
		||||
			args:      args{options: metav1.ListOptions{ResourceVersion: "rv:10", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan}},
 | 
			
		||||
			want:      list(11, "rv:20"),
 | 
			
		||||
			wantPaged: true,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	for _, tt := range tests {
 | 
			
		||||
		t.Run(tt.name, func(t *testing.T) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user