如何通过标签从fabric8 sharedIndexInformer中过滤事件?

huangapple go评论97阅读模式
英文:

How to filter events from fabric8 sharedIndexInformer by labels?

问题

我使用 fabric8 kubernetes client v6.8.0,并初始化一个用于 CRD 的 sharedIndexInformer,如下所示:

  1. SharedIndexInformer<MyResource> informer =
  2. sharedInformerFactory.sharedIndexInformerFor(MyResource.class, 30 * 1000L);
  3. informer.addEventHandler(myEventHandler);

我只想接收具有特定标签的资源的事件。

在客户端的早期版本中,这似乎很简单,因为标签选择是sharedIndexInformerFor的一个参数之一。

  1. SharedIndexInformer<MyResource> informer =
  2. sharedInformerFactory.sharedIndexInformerFor(
  3. MyResource.class,
  4. myLabelSelector,
  5. 30 * 1000L);

如何在 v6.8.0+ 中实现这一点?

英文:

I am on fabric8 kubernetes client v6.8.0 and initializing a sharedIndexInformer for a CRD like this:

  1. SharedIndexInformer&lt;MyResource&gt; informer =
  2. sharedInformerFactory.sharedIndexInformerFor(MyResource.class, 30 * 1000L);
  3. informer.addEventHandler(myEventHandler);

I only want to receive events from resources with certain labels.

This seemed straightforward in earlier version of the client, with label selection being one of the arguments in sharedIndexInformerFor.

  1. SharedIndexInformer&lt;MyResource&gt; informer =
  2. sharedInformerFactory.sharedIndexInformerFor(
  3. MyResource.class,
  4. myLabelSelector,
  5. 30 * 1000L);

How to achieve this in v6.8.0+?

答案1

得分: 1

要更精细地控制信息筛选,您可以使用Resource DSL上可用的inform()方法:

  1. SharedIndexInformer<MyResource> informer = client.resources(MyResource.class)
  2. .inNamespace("default")
  3. .withLabel("app", "test-operator")
  4. .inform(myEventHandler, 30 * 1000L);
英文:

For more fine grained control over informers filtering, you can use the inform() method available on Resource DSL:

  1. SharedIndexInformer&lt;MyResource&gt; informer = client.resources(MyResource.class)
  2. .inNamespace(&quot;default&quot;)
  3. .withLabel(&quot;app&quot;, &quot;test-operator&quot;)
  4. .inform(myEventHandler, 30 * 1000L);

huangapple
  • 本文由 发表于 2023年7月31日 21:12:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76803983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定