I want to list my deployments based on a key value pair found in the .spec.selector.matchLabels
field.
Doing so using the plain labels
is easy, but I could not find a way to match / fetch the deployment that satisfies the condition that a certain key=value
is present in the following section
spec:
[...]
selector:
matchLabels:
app: myapp
process: web
release: myrelease
Does not seem this can be done using the ListOptions
It is not supported:
You have to filter on the client side:
depl, err := clientset.AppsV1().Deployments("some_namespace").List(context.Background(), metav1.ListOptions{})
if err != nil {
panic(err.Error())
}
for _, item := range depl.Items {
if item.Spec.Selector.MatchLabels["app"] == "myapp" {
fmt.Println("found it")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With