如何使用带有匹配标签和匹配表达式的 client-go 列出自定义资源

问题描述

我有一个自定义资源,它有一个选择器,如下所示。我想检索与 matchexpressions 或 matchlabels 中的任何条件匹配的所有网络。

  networkSelector:
    matchExpressions:
    - key: web
      operator: In
      values:
      - dev
      - infra
    matchLabels:
      net: db
      infra-net: infra

我在下面尝试为 matchLabels 获取匹配网络,但无法弄清楚如何为 matchExpressions 执行此操作。可以通过selector一起完成吗?

r is of type networkReconciler and 
type networkReconciler struct {
    client.Client
    Log            logr.Logger
    ResourceScheme *runtime.Scheme
    CtrlOptions    controller.Options
}


opts := client.MatchingLabels(obj.Spect.networkSelector.MatchLabels) 
r.List(ctx,netwList,opts)

感谢您对此的任何帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...