k8s-api icon indicating copy to clipboard operation
k8s-api copied to clipboard

Watch Support

Open deas opened this issue 4 years ago • 6 comments

Been playing with k8s-api for a while and I really like it.

However, I need watch support. Saw the docstring mentioning https://github.com/kubernetes/kubernetes/issues/50857. Watch is the gateway to operators, and I am wondering how to get support in.

I also like http-kit in general but it appears to lack maintenance and it also appears to require some patching to get watch working. The next issue I encountered was lack of tls support with Java 11 in the stable version. Not super important at the moment but I'd expect graal support to be a problem as well.

Don't get me wrong: I am not saying we should be departing from http-kit immediately. I'd be fine using something else to watch for now. However, I'd also be willing to help getting support into k8s-api. ;)

Do you have any long term vision with regards to the http library/libraries to use in k8s-api?

deas avatar Apr 13 '20 07:04 deas

Played a little more. :)

https://github.com/martinklepsch/clj-http-lite works with watch:

    (let [res (http-light/get "http://127.0.0.1:8001/api/v1/namespaces/default/pods?watch=true"
                             {:as :stream})
          rdr (-> (:body res) (InputStreamReader. "UTF8") BufferedReader.)
          items (parsed-seq rdr)]
      (doseq [item items] (println item)))

Swapping clj-http for clj-http-lite in martian does not appear to be difficult either. Not saying things will be working though. Will give it a try ;)

Happy easter!

deas avatar Apr 13 '20 08:04 deas

Hey! Thanks for the report :) Yeah, this is very annoying in fact.. the problem is that the Kubernetes API doesn't follow HTTP 1.1 spec on chunked responses. So it's not http-kit limitation actually 😞 .

I'm considering following martian approach to decouple from http implementation.. but I'm not sure yet.

RafaeLeal avatar Apr 24 '20 13:04 RafaeLeal

I got watch and client pluggability working in k8s-api. When using watch, the client gets a (blocking) sequence of maps. This works with clj-http-lite and iirc also with clj-http. It does not yet work with httpkit, but there are no regressions in the httpkit implementation either.

At the moment, the k8s-api detects the client implementation from the environment (for compatibility). Not sure if this is what we want or whether we want to set it explicitly. There are also other areas which do not yet look clean to me. Would be great if you could check so the changes get into your master branch.

Feel free to check: https://github.com/deas/k8s-api/commits/pluggable-client

BTW: I landed a commit adding clj-http-lite in martian master. ;)

deas avatar Apr 24 '20 14:04 deas

Any news on this? I'm in need of the watch functionality as well.

edit: I embraced java interop and went with https://github.com/fabric8io/kubernetes-client for the --watch functionality

Dangercoder avatar Dec 16 '20 19:12 Dangercoder

Glad to see someone working on this! I did an experiment using the watch k8s API from clojure a while back. It is 3+ years old and it might not be relevant. I mention it anyway in case it is of some use/interest.

https://github.com/blak3mill3r/keenest-rube/blob/master/src/rube/request.clj#L61 I used aleph.http for the chunked response parsing and wound up with a core.async channel of EDN from k8s.

blak3mill3r avatar Mar 06 '21 01:03 blak3mill3r

nice to see this is being worked on any reason the work in @deas branch cant be implemented watch would be really nice to see.

olymk2 avatar Jun 23 '21 09:06 olymk2