From c3ce052cc56bc1fbbcee4bd582548d52b6a152fe Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 7 Sep 2018 11:08:12 +0000 Subject: [PATCH] Refactor: use Kubernetes.Interface instead of *Clientset So we can call with a mock for testing --- prog/kube-utils/annotations.go | 4 ++-- prog/kube-utils/main.go | 2 +- prog/kube-utils/nodestatus.go | 2 +- prog/kube-utils/peerlist.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/prog/kube-utils/annotations.go b/prog/kube-utils/annotations.go index b9a6b633..1b079365 100644 --- a/prog/kube-utils/annotations.go +++ b/prog/kube-utils/annotations.go @@ -26,11 +26,11 @@ type configMapAnnotations struct { cm *v1.ConfigMap } -func newConfigMapAnnotations(ns string, configMapName string, clientset *kubernetes.Clientset) *configMapAnnotations { +func newConfigMapAnnotations(ns string, configMapName string, c kubernetes.Interface) *configMapAnnotations { return &configMapAnnotations{ Namespace: ns, ConfigMapName: configMapName, - Client: clientset.CoreV1(), + Client: c.CoreV1(), } } diff --git a/prog/kube-utils/main.go b/prog/kube-utils/main.go index 9535bb91..cc8018f5 100644 --- a/prog/kube-utils/main.go +++ b/prog/kube-utils/main.go @@ -25,7 +25,7 @@ type nodeInfo struct { } // return the IP addresses of all nodes in the cluster -func getKubePeers(c *kubernetes.Clientset, includeWithNoIPAddr bool) ([]nodeInfo, error) { +func getKubePeers(c kubernetes.Interface, includeWithNoIPAddr bool) ([]nodeInfo, error) { nodeList, err := c.CoreV1().Nodes().List(api.ListOptions{}) if err != nil { return nil, err diff --git a/prog/kube-utils/nodestatus.go b/prog/kube-utils/nodestatus.go index 0df3a30f..be787c34 100644 --- a/prog/kube-utils/nodestatus.go +++ b/prog/kube-utils/nodestatus.go @@ -10,7 +10,7 @@ import ( ) // based on k8s.io/kubernetes/pkg/controller/nodeipam/ipam/adapter.go -func setNodeNetworkUnavailableFalse(c *kubernetes.Clientset, nodeName string) error { +func setNodeNetworkUnavailableFalse(c kubernetes.Interface, nodeName string) error { condition := v1.NodeCondition{ Type: v1.NodeNetworkUnavailable, Status: v1.ConditionFalse, diff --git a/prog/kube-utils/peerlist.go b/prog/kube-utils/peerlist.go index 1b426bb3..2573d5a5 100644 --- a/prog/kube-utils/peerlist.go +++ b/prog/kube-utils/peerlist.go @@ -71,7 +71,7 @@ func (cml *configMapAnnotations) UpdatePeerList(list peerList) error { } // update the list of all peers that have gone through this code path -func addMyselfToPeerList(cml *configMapAnnotations, c *kubernetes.Clientset, peerName, name string) (*peerList, error) { +func addMyselfToPeerList(cml *configMapAnnotations, c kubernetes.Interface, peerName, name string) (*peerList, error) { var list *peerList err := cml.LoopUpdate(func() error { var err error @@ -91,7 +91,7 @@ func addMyselfToPeerList(cml *configMapAnnotations, c *kubernetes.Clientset, pee return list, err } -func checkIamInPeerList(cml *configMapAnnotations, c *kubernetes.Clientset, peerName string) (bool, error) { +func checkIamInPeerList(cml *configMapAnnotations, c kubernetes.Interface, peerName string) (bool, error) { if err := cml.Init(); err != nil { return false, err }