I want to fetch the list (if any) of kubernetes
nodes that do not contain a label.
I have managed to do the opposite using client-go
labelSelector := metav1.LabelSelector{
MatchLabels: map[string]string{
"somelabel": "somevalue",
},
}
labelMap, err := metav1.LabelSelectorAsMap(&labelSelector)
if err != nil {
return false, errors.Wrap(err, "error converting node label selector to map")
}
nodeListOptions := metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(labelMap).String(),
}
nodes, err := clientset.CoreV1().Nodes().List(nodeListOptions)
if err != nil {
return false, errors.Wrap(err, "error getting node list")
}
What I want to achieve is to convert the following kubectl
invocation
kubectl get ns --selector='!label_name'
into client-go
code.
Is this feasible?