Use Clientset interface instead of type for Fission/kubernetes clients (#2416)

Using interface makes it easy to create a fake client and unit test
a specific portion of the code. We should be able to more write unit
test and increase coverage of code with this change.

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2022-04-21 16:49:52 +05:30
committed by GitHub
parent 3bdbeb6c87
commit 2a43213387
39 changed files with 123 additions and 129 deletions
+4 -4
View File
@@ -51,7 +51,7 @@ func panicIf(err error) {
}
// return the number of pods in the given namespace matching the given labels
func countPods(kubeClient *kubernetes.Clientset, ns string, labelz map[string]string) int {
func countPods(kubeClient kubernetes.Interface, ns string, labelz map[string]string) int {
pods, err := kubeClient.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set(labelz).AsSelector().String(),
})
@@ -61,7 +61,7 @@ func countPods(kubeClient *kubernetes.Clientset, ns string, labelz map[string]st
return len(pods.Items)
}
func createTestNamespace(kubeClient *kubernetes.Clientset, ns string) {
func createTestNamespace(kubeClient kubernetes.Interface, ns string) {
_, err := kubeClient.CoreV1().Namespaces().Create(context.TODO(), &apiv1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: ns,
@@ -74,7 +74,7 @@ func createTestNamespace(kubeClient *kubernetes.Clientset, ns string) {
}
// create a nodeport service
func createSvc(kubeClient *kubernetes.Clientset, ns string, name string, targetPort int, nodePort int32, labels map[string]string) *apiv1.Service {
func createSvc(kubeClient kubernetes.Interface, ns string, name string, targetPort int, nodePort int32, labels map[string]string) *apiv1.Service {
svc, err := kubeClient.CoreV1().Services(ns).Create(context.TODO(), &apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -148,7 +148,7 @@ func TestExecutor(t *testing.T) {
log.Panicf("failed to ensure crds: %v", err)
}
err = fissionClient.WaitForCRDs()
err = crd.WaitForCRDs(fissionClient)
if err != nil {
log.Panicf("failed to wait crds: %v", err)
}