-
Notifications
You must be signed in to change notification settings - Fork 2
08 K8s TDD
How to follow a TDD flow while developing Kubernetes native
components?
To simplify this topic, we will be focusing on controllers
given its popularity
- Golang environment and IDE
- Install kubebuilder
One of the hardest problems that need to be tackled when dealing with unit tests is how to solve the problem generated by external dependencies such as database, apis, etc. In the Kubernetes community and official repos we can see very different approaches
Kubebuilder | sample-controller | |
---|---|---|
approach | Integration | Mock |
code | https://github.com/kubernetes-sigs/kubebuilder | https://github.com/kubernetes/sample-controller |
Client-go and generated code already tackles the mock problem offering its code signature using interfaces
, a implementation, and a mock/fake
We deal with this in detail here
Bundling all external dependencies together, kubebuilder uses the host operating system to start ephemeral instances of the kube-apiserver
, etcd
, etc. to simplify writing and maintaining unit tests. Check this page for a detailed exploration
Given that kubernetes clients are retrieved from cascading functions, it would take a lot of preparation in order to prepare on client call. Still, gomock
comes handy when implementing mocks for internal interfaces and other external services.
Maybe someone could create a package to simplify bundling and preparing mocks for client-go interfaces?