In a Watcher in the fabric8 Kubernetes client events() API, what resources can I watch?

天大地大妈咪最大 提交于 2019-12-11 06:02:09

问题


I am exploring the (undocumented?) events() API in Fabric8's Kubernetes client project.

Specifically, I see that I can do something like the following:

client.events().inAnyNamespace().watch(new Watcher<Something>() {
    @Override
    public final void eventReceived(final Action action, final Something something) {

    }

    @Override
    public final void onClose(final KubernetesClientException kubernetesClientException) {
      if (kubernetesClientException != null) {
        // log? throw?
      }
    }
});

What are the permitted values of something and Something for something useful to happen? I'm assuming they are supposed to be things like Pods, Services, etc. but I'm not sure.

Watcher's sole type parameter is declared as <T>, so it would appear I could create a new Watcher<Integer>, but I'm willing to bet money that will never be called. This suggests that there is actually a bound in practice on <T>, but I don't know what it is, or why it would have been omitted if so.

If I had to guess, I'd guess from the parameter name, resource, that it would be something like T extendsResource<?, ?> but again, that's only a guess.

Thanks for any pointers, particularly to other documentation I'm sure I've missed.

Update #1: From banging around in the source code, I can see that the only place that a Watcher.Action's eventReceived() method is called forces the payload to be considered to be a HasMetadata object. Maybe that's my answer?


回答1:


You can watch a particular pod or particular job for example. The T type in that case is Pod or Job respectively. Try

kube.extensions().jobs().createNew()...done().watch(new Watcher<Job>(){...})


来源:https://stackoverflow.com/questions/43598572/in-a-watcher-in-the-fabric8-kubernetes-client-events-api-what-resources-can-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!