<p>I am trying to list all the nodes that are set to unscheduleable in an operator-sdk operator. Generally (pre 1.12) this means they have <code>spec.unscheduleable</code> set. So I tried this:</p>

<pre><code>nodes := &amp;corev1.NodeList{}
opts := &amp;client.ListOptions{}
if err := opts.SetFieldSelector("spec.unschedulable=true"); err != nil {
  reqLogger.Info("Failed to set field selector")
}
</code></pre>

<p>Which is erroring:</p>

<pre><code>2019-04-23T10:19:39.761-0700    ERROR   kubebuilder.controller  Reconciler error    {"controller": "node-controller", "request": "/nodename", "error": "Index with name field:spec.unschedulable does not exist"}
</code></pre>

<p>I'm confused about this because the field selector works from kubectl:</p>

<pre><code>kubectl get nodes --field-selector="spec.unschedulable=true"
</code></pre>

<p>Alongside this issue, I have noticed that after v1.12, the spec.unscheduleable field has been <a href="https://github.com/kubernetes/kubernetes/issues/69010" rel="nofollow noreferrer">deprecated</a> in favour of TaintNodeByCondition. This further complicates things, because now I really don't think I can use the fieldselector anyone, because I don't believe (unless I'm mistaken?) that you can use fieldselector with the taints anyway.</p>

<p>So, my question is - how can I list all of the tainted/unscheduleable nodes in my cluster efficiently, specifically when using the operator-sdk</p>

<p>UPDATE:</p>

<p>I have managed to solve the fieldselector problem by using a v1meta.ListOptions call, like so:</p>

<pre><code>nodes := &amp;corev1.NodeList{}
opts := &amp;client.ListOptions{
Raw: &amp;metav1.ListOptions{
  FieldSelector: "spec.unschedulable=true",
  },
}
</code></pre>

<p>However, I still don't know how to do this with taints, so I've edited the question and will leave it open</p>

jaxxstorm
<p>I'm using client-go APIs and I've also struggled with this issue, so I did a workaround which I'm not sure whether this is the best option or not. Nevertheless, will share my code.</p>
<p>It starts with gettings all the nodes then filtering the ones that do not have taints.</p>
<pre><code>func GetNodes(withoutTaints bool, clientset kubernetes.Interface, ctx 
*context.Context, options *metav1.ListOptions) *v1.NodeList {
    nodes, err := clientset.CoreV1().Nodes().List(*ctx, *options)
    if err != nil {
        panic(err)
    }
    if withoutTaints {
        nodesWithoutTaints := v1.NodeList{}
        for _, node := range nodes.Items {
            if len(node.Spec.Taints) == 0 {
                nodesWithoutTaints.Items = append(nodesWithoutTaints.Items, node)
            }
        }
        return &amp;nodesWithoutTaints
    }
    return nodes
}
</code></pre>
