5 Time saving things about client-go, I didn't know!
Muaaz Saleem
Posted on January 17, 2021
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.
- k8s API is divided into apigroups! Core objects don’t (like pods), everything else is pretty much under an API Group
-
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!
- Kinds map to resources, resources map to HTTP Paths through RESTMappers, Scheme connects a kind and a Resource
- 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.
- See the package docs
- Last but not the least, there’s a fake client! You can use it to test your code!
- See example!
There are many working examples in the upsteam repo now! Check them out to learn more.
💖 💪 🙅 🚩
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
devops How we designed a DevOps Co-pilot to help DevOps and SREs reduce context switching
October 7, 2024