Merge pull request #18 from reactiveops/jg/fix-tests

move clientset init to where it is used
This commit is contained in:
Jess G
2019-02-01 14:46:32 -08:00
committed by GitHub
4 changed files with 8 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ jobs:
- run: go get -u github.com/golang/lint/golint
- run: go list ./... | grep -v vendor | xargs golint
- run: go list ./... | grep -v vendor | xargs go vet
- run: go test ./pkg/... -coverprofile cover.out
- run: go test ./pkg/... -v -coverprofile cover.out
build:
docker:

View File

@@ -31,7 +31,8 @@ func Render(w http.ResponseWriter, r *http.Request, c conf.Configuration) {
func RenderJSON(w http.ResponseWriter, r *http.Request, c conf.Configuration) {
results := []validator.Results{}
pods, err := kube.CoreV1API.Pods("").List(metav1.ListOptions{})
var clientset = kube.CreateClientset()
pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{})
if err != nil {
http.Error(w, "Error Fetching Pods", 500)
return
@@ -47,7 +48,8 @@ func RenderJSON(w http.ResponseWriter, r *http.Request, c conf.Configuration) {
}
func getDashboardData(c conf.Configuration) (DashboardData, error) {
deploys, err := kube.AppsV1API.Deployments("").List(metav1.ListOptions{})
var clientset = kube.CreateClientset()
deploys, err := clientset.AppsV1().Deployments("").List(metav1.ListOptions{})
if err != nil {
return DashboardData{}, err
}

View File

@@ -8,7 +8,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
func createClientset() *kubernetes.Clientset {
func CreateClientset() *kubernetes.Clientset {
kubeConf := config.GetConfigOrDie()
clientset, err := kubernetes.NewForConfig(kubeConf)
@@ -17,11 +17,3 @@ func createClientset() *kubernetes.Clientset {
}
return clientset
}
var clientset = createClientset()
// CoreV1API exports the v1 Core API client.
var CoreV1API = clientset.CoreV1()
// AppsV1API exports the v1 Apps API client.
var AppsV1API = clientset.AppsV1()

View File

@@ -18,7 +18,8 @@ func PingHandler(w http.ResponseWriter, r *http.Request) {
// DeployHandler creates a handler for to validate the current deploy workloads.
func DeployHandler(w http.ResponseWriter, r *http.Request, c conf.Configuration) {
var results []Results
deploys, err := kube.AppsV1API.Deployments("").List(metav1.ListOptions{})
clientset := kube.CreateClientset()
deploys, err := clientset.AppsV1().Deployments("").List(metav1.ListOptions{})
if err != nil {
fmt.Fprintf(w, err.Error())
return