英文:
List deployments using apimachinery by the .spec.selector.matchLabels key
问题
我想根据在.spec.selector.matchLabels
字段中找到的键值对列出我的部署。
使用普通的labels
来做这个很容易,但我找不到一种方法来匹配/获取满足以下条件的部署:在以下部分中存在某个特定的key=value
spec:
[...]
selector:
matchLabels:
app: myapp
process: web
release: myrelease
似乎不能使用ListOptions
来实现这一点。
英文:
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
答案1
得分: 4
不支持的内容:
- https://github.com/kubernetes/client-go/issues/713#issuecomment-557540936
- 和 https://github.com/kubernetes/kubernetes/issues/53459
你需要在客户端进行过滤:
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("找到了")
}
}
英文:
It is not supported:
- https://github.com/kubernetes/client-go/issues/713#issuecomment-557540936
- and https://github.com/kubernetes/kubernetes/issues/53459
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")
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论