<p>I'm working on a custom controller for a custom resource using kubebuilder (version 1.0.8). I have a scenario where I need to get a list of all the instances of my custom resource so I can sync up with an external database.</p>

<p>All the examples I've seen for kubernetes controllers use either client-go or just call the api server directly over http. However, kubebuilder has also given me this client.Client object to get and list resources. So I'm trying to use that.</p>

<p>After creating a client instance by using the passed in Manager instance (i.e. do <code>mgr.GetClient()</code>), I then tried to write some code to get the list of all the Environment resources I created.</p>

<pre><code>func syncClusterWithDatabase(c client.Client, db *dynamodb.DynamoDB) {
    // Sync environments
    // Step 1 - read all the environments the cluster knows about
    clusterEnvironments := &amp;cdsv1alpha1.EnvironmentList{}

    c.List(context.Background(), /* what do I put here? */, clusterEnvironments)
}
</code></pre>

<p>The example in the documentation for the List method shows:</p>

<pre><code>c.List(context.Background, &amp;result);
</code></pre>

<p>which doesn't even compile.</p>

<p>I saw a few method in the client package to limit the search to particular labels, or for a specific field with a specific value, but nothing to limit the result to a specific resource kind.</p>

<p>Is there a way to do this via the <code>Client</code> object? Should I do something else entirely?</p>

Chris Tavares
<p>According to the latest documentation, the List method is defined as follows,</p>
<pre><code>List(ctx context.Context, list ObjectList, opts ...ListOption) error
</code></pre>
<p>If the <code>List</code> method you are calling has the same definition as above, your code should compile. As it has variadic options to set the namespace and field match, the mandatory arguments are <code>Context</code> and <code>objectList</code>.</p>
<p>Ref: <a href="https://book.kubebuilder.io/cronjob-tutorial/controller-implementation.html#2-list-all-active-jobs-and-update-the-status" rel="nofollow noreferrer">KubeBuilder Book</a></p>
