In a Watcher in the fabric8 Kubernetes client even

2019-07-29 05:19发布

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条回答
放荡不羁爱自由
2楼-- · 2019-07-29 06:20

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>(){...})
查看更多
登录 后发表回答