Skip to content

Commit

Permalink
Update utils.go
Browse files Browse the repository at this point in the history
Signed-off-by: Eytan Avisror <[email protected]>
  • Loading branch information
Eytan Avisror authored and Eytan Avisror committed Apr 1, 2021
1 parent b1896fb commit abae591
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions controllers/providers/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"html/template"
"os"
"os/user"
"reflect"
"strings"

Expand Down Expand Up @@ -189,11 +186,7 @@ func GetKubernetesConfig() (*rest.Config, error) {
var config *rest.Config
config, err := rest.InClusterConfig()
if err != nil {
config, err = GetKubernetesLocalConfig()
if err != nil {
return nil, err
}
return config, nil
return GetKubernetesLocalConfig()
}
return config, nil
}
Expand All @@ -212,27 +205,9 @@ func RenderCustomResource(tpl string, params interface{}) (string, error) {
}

func GetKubernetesLocalConfig() (*rest.Config, error) {
var kubePath string
if os.Getenv("KUBECONFIG") != "" {
kubePath = os.Getenv("KUBECONFIG")
} else {
usr, err := user.Current()
if err != nil {
return nil, err
}
kubePath = usr.HomeDir + "/.kube/config"
}

if kubePath == "" {
err := fmt.Errorf("failed to get kubeconfig path")
return nil, err
}

config, err := clientcmd.BuildConfigFromFlags("", kubePath)
if err != nil {
return nil, err
}
return config, nil
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
clientCfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
return clientCfg.ClientConfig()
}

func CRDExists(kubeClient dynamic.Interface, name string) bool {
Expand Down

0 comments on commit abae591

Please sign in to comment.