通过 .spec.selector.matchLabels 键使用 apimachinery 列出部署

pka*_*mol 6 go kubernetes client-go

我想根据现场找到的键值对列出我的部署.spec.selector.matchLabels

使用普通格式执行此操作labels很容易,但我找不到一种方法来匹配/获取满足key=value下一节中存在的某个条件的部署

spec:
  [...]
  selector:
    matchLabels:
      app: myapp
      process: web
      release: myrelease
Run Code Online (Sandbox Code Playgroud)

似乎不能使用ListOptions

bla*_*een 4

不支持:

您必须在客户端进行过滤:

    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")
        }
    }
Run Code Online (Sandbox Code Playgroud)