Skip to content

Commit

Permalink
Remove duplicated BuildConfigFromFlags func (#2162)
Browse files Browse the repository at this point in the history
Use BuildConfigFromFlags from k8s.io/client-go/tools/clientcmd instead
of local copy.
  • Loading branch information
antoineco authored and aledbf committed Mar 1, 2018
1 parent 8ddb610 commit 01399dd
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 01399dd

Please sign in to comment.