英文:
How to filter events from fabric8 sharedIndexInformer by labels?
问题
我使用 fabric8 kubernetes client v6.8.0,并初始化一个用于 CRD 的 sharedIndexInformer,如下所示:
SharedIndexInformer<MyResource> informer =
sharedInformerFactory.sharedIndexInformerFor(MyResource.class, 30 * 1000L);
informer.addEventHandler(myEventHandler);
我只想接收具有特定标签的资源的事件。
在客户端的早期版本中,这似乎很简单,因为标签选择是sharedIndexInformerFor
的一个参数之一。
SharedIndexInformer<MyResource> informer =
sharedInformerFactory.sharedIndexInformerFor(
MyResource.class,
myLabelSelector,
30 * 1000L);
如何在 v6.8.0+ 中实现这一点?
英文:
I am on fabric8 kubernetes client v6.8.0 and initializing a sharedIndexInformer for a CRD like this:
SharedIndexInformer<MyResource> informer =
sharedInformerFactory.sharedIndexInformerFor(MyResource.class, 30 * 1000L);
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
.
SharedIndexInformer<MyResource> informer =
sharedInformerFactory.sharedIndexInformerFor(
MyResource.class,
myLabelSelector,
30 * 1000L);
How to achieve this in v6.8.0+?
答案1
得分: 1
要更精细地控制信息筛选,您可以使用Resource DSL上可用的inform()
方法:
SharedIndexInformer<MyResource> informer = client.resources(MyResource.class)
.inNamespace("default")
.withLabel("app", "test-operator")
.inform(myEventHandler, 30 * 1000L);
英文:
For more fine grained control over informers filtering, you can use the inform()
method available on Resource DSL:
SharedIndexInformer<MyResource> informer = client.resources(MyResource.class)
.inNamespace("default")
.withLabel("app", "test-operator")
.inform(myEventHandler, 30 * 1000L);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论