I want to execute equivalent of
kubectl get all -l app=myapp -n mynamespace
or
kubectl label all -l version=1.2.0,app=myapp track=stable --overwrite
using client-go
I looked at dynamic package, but it seems like it needs GroupVersionResource
, which is different for, say, Service objects and Deployment objects. Also when I pass schema.GroupVersionResource{Group: "apps", Version: "v1"}
it doesn't find anything, when I pass schema.GroupVersionResource{Version: "v1"}
it finds only namespace object and also doesn't looks for labels, though I provided label options:
resource := schema.GroupVersionResource{Version: "v1"}
listOptions := metav1.ListOptions{LabelSelector: fmt.Sprintf("app=%s", AppName), FieldSelector: ""}
res, listErr := dynamicClient.Resource(resource).Namespace("myapps").List(listOptions)
I also looked at runtime package, but didn't find anything useful. I took a look at how kubectl
implement this, bit haven't figured it out yet, too many levels of abstractions.