From 01399dd62570bd101b51a9d132f47069d7df97c6 Mon Sep 17 00:00:00 2001 From: Antoine Cotten Date: Thu, 1 Mar 2018 14:27:53 +0100 Subject: [PATCH] Remove duplicated BuildConfigFromFlags func (#2162) Use BuildConfigFromFlags from k8s.io/client-go/tools/clientcmd instead of local copy. --- cmd/nginx/main.go | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/cmd/nginx/main.go b/cmd/nginx/main.go index fa60e17578..9ff541348b 100644 --- a/cmd/nginx/main.go +++ b/cmd/nginx/main.go @@ -36,9 +36,7 @@ import ( discovery "k8s.io/apimachinery/pkg/version" "k8s.io/apiserver/pkg/server/healthz" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "k8s.io/ingress-nginx/internal/file" "k8s.io/ingress-nginx/internal/ingress/controller" @@ -171,7 +169,7 @@ func handleSigterm(ngx *controller.NGINXController, exit exiter) { // apiserverHost param is in the format of protocol://address:port/pathPrefix, e.g.http://localhost:8001. // kubeConfig location of kubeconfig file func createApiserverClient(apiserverHost string, kubeConfig string) (*kubernetes.Clientset, error) { - cfg, err := buildConfigFromFlags(apiserverHost, kubeConfig) + cfg, err := clientcmd.BuildConfigFromFlags(apiserverHost, kubeConfig) if err != nil { return nil, err } @@ -241,27 +239,6 @@ const ( fakeCertificate = "default-fake-certificate" ) -// buildConfigFromFlags builds REST config based on master URL and kubeconfig path. -// If both of them are empty then in cluster config is used. -func buildConfigFromFlags(masterURL, kubeconfigPath string) (*rest.Config, error) { - if kubeconfigPath == "" && masterURL == "" { - kubeconfig, err := rest.InClusterConfig() - if err != nil { - return nil, err - } - - return kubeconfig, nil - } - - return clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath}, - &clientcmd.ConfigOverrides{ - ClusterInfo: clientcmdapi.Cluster{ - Server: masterURL, - }, - }).ClientConfig() -} - /** * Handles fatal init error that prevents server from doing any work. Prints verbose error * message and quits the server.