5 Time saving things about client-go, I didn't know!

muaazsaleem

Muaaz Saleem

Posted on January 17, 2021

5 Time saving things about client-go, I didn't know!

client-go is the official go client for talking to Kubernetes (k8s) APIs.

A while back, I read parts of Programming Kubernetes by Michael Hausenblas & Stefan Schimanski. I learned a whole lot about client-go that still helps me.

  1. k8s API is divided into apigroups! Core objects don’t (like pods), everything else is pretty much under an API Group
  2. k8s.io/client-go isn’t enough to talk to kubernetes API, you need k8s.io/api and k8s.io/apimachinery too
    • You have to match their versions for it to all work!
    • See the client-go versioning for simple instructions!
  3. Kinds map to resources, resources map to HTTP Paths through RESTMappers, Scheme connects a kind and a Resource
  4. Almost always use informers instead of watch to watch events, the exception is just watching events to log them, then maybe it doesn’t matter.
  5. Last but not the least, there’s a fake client! You can use it to test your code!

There are many working examples in the upsteam repo now! Check them out to learn more.

💖 💪 🙅 🚩
muaazsaleem
Muaaz Saleem

Posted on January 17, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related