<p>I want to use client-go to get resources in Kubernetes cluster. Due to a large amount of data, when I get the configmap connection is closed.</p>

<pre><code>stream error when reading response body, may be caused by closed connection. Please retry. Original error: stream error: stream ID 695; INTERNAL_ERROR
</code></pre>

<p>configmaps: </p>

<pre><code>$ kubectl -n kube-system get cm |wc -l
   35937
</code></pre>

<p>code: </p>

<pre><code>cms, err := client.CoreV1().ConfigMaps(kube-system).List(context.TODO(), v1.ListOptions{})
</code></pre>

<p>I try to use Limit parameter, I can get some data, but I don’t know how to get all.</p>

<pre><code>cms, err := client.CoreV1().ConfigMaps(kube-system).List(context.TODO(), v1.ListOptions{Limit: 1000 })
</code></pre>

<p>I'm new to Go. Any pointers as to how to go about it would be greatly appreciated.</p>

cainiaohhh
<p>The documentation for <a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#ListOptions" rel="nofollow noreferrer">v1.ListOptions</a> describes how it works:</p>

<blockquote>
  <p>limit is a maximum number of responses to return for a list call. If more items exist, the
      server will set the <code>continue</code> field on the list metadata to a value that can be used with the
      same initial query to retrieve the next set of results. </p>
</blockquote>

<p>This means that you should examine the response, save the value of the <code>continue</code> field (as well as the actual results), then reissue the same command but with <code>continue</code> set to the just seen value. Repeat until the returned <code>continue</code> field is empty (or an error occurs).</p>

<p>See the <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#retrieving-large-results-sets-in-chunks" rel="nofollow noreferrer">API concepts</a> page for details on handling chunking of large results.</p>
