Skip to content

Commit

Permalink
Use builder as suggested in review.
Browse files Browse the repository at this point in the history
  • Loading branch information
erictune committed Apr 17, 2015
1 parent 837edc6 commit e696c96
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 54 deletions.
29 changes: 10 additions & 19 deletions cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"net"
"net/http"
"net/http/pprof"
"os"
"strconv"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/nodecontroller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/servicecontroller"
Expand Down Expand Up @@ -154,28 +154,19 @@ func (s *CMServer) verifyMinionFlags() {
func (s *CMServer) Run(_ []string) error {
s.verifyMinionFlags()

if len(s.Master) == 0 && len(s.Kubeconfig) == 0 {
glog.Fatal("specify at least one of --master <master> OR --kubeconfig <kubeconfig-filename>")
if s.Kubeconfig == "" || s.Master == "" {
glog.Warningf("Neither --kubeconfig nor --master was specified. Using default API client. This might not work.")
}

var kubeconfig *client.Config = &client.Config{}
if s.Kubeconfig != "" {
var err error
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
&clientcmd.ConfigOverrides{})
kubeconfig, err = loader.ClientConfig()
if os.IsNotExist(err) {
glog.Fatalf("Could not find kubeconfig file at %s", s.Kubeconfig)
}
if err != nil {
glog.Fatalf("Error loading kubeconfig file \"%s\": %v", s.Kubeconfig, err)
}
// This creates a client, first loading any specified kubeconfig
// file, and then overriding the Master flag, if non-empty.
kubeconfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: s.Master}}).ClientConfig()
if err != nil {
return err
}

if len(s.Master) != 0 {
kubeconfig.Host = s.Master
}
kubeconfig.QPS = 20.0
kubeconfig.Burst = 30

Expand Down
31 changes: 11 additions & 20 deletions cmd/kube-proxy/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"net"
"net/http"
_ "net/http/pprof"
"os"
"strconv"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
Expand Down Expand Up @@ -109,33 +109,24 @@ func (s *ProxyServer) Run(_ []string) error {
// are registered yet.

// define api config source
var kubeconfig *client.Config = &client.Config{}
if s.Kubeconfig != "" {
var err error
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
&clientcmd.ConfigOverrides{})
kubeconfig, err = loader.ClientConfig()
if os.IsNotExist(err) {
glog.Fatalf("Could not find kubeconfig file at %s", s.Kubeconfig)
}
if err != nil {
glog.Fatalf("Error loading kubeconfig file \"%s\": %v", s.Kubeconfig, err)
}
}

if s.Master != "" {
kubeconfig.Host = s.Master
}

if s.Kubeconfig == "" || s.Master == "" {
glog.Warningf("Neither --kubeconfig nor --master was specified. Using default API client. This might not work.")
}

// This creates a client, first loading any specified kubeconfig
// file, and then overriding the Master flag, if non-empty.
kubeconfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: s.Master}}).ClientConfig()
if err != nil {
return err
}

client, err := client.New(kubeconfig)
if err != nil {
glog.Fatalf("Invalid API configuration: %v", err)
}

config.NewSourceAPI(
client.Services(api.NamespaceAll),
client.Endpoints(api.NamespaceAll),
Expand Down
25 changes: 10 additions & 15 deletions plugin/cmd/kube-scheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
Expand Down Expand Up @@ -78,23 +79,17 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) {

// Run runs the specified SchedulerServer. This should never exit.
func (s *SchedulerServer) Run(_ []string) error {
var kubeconfig *client.Config = &client.Config{}
if s.Kubeconfig != "" {
var err error
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
&clientcmd.ConfigOverrides{})
kubeconfig, err = loader.ClientConfig()
if os.IsNotExist(err) {
glog.Fatalf("Could not find kubeconfig file at %s", s.Kubeconfig)
}
if err != nil {
glog.Fatalf("Error loading kubeconfig file \"%s\": %v", s.Kubeconfig, err)
}
if s.Kubeconfig == "" || s.Master == "" {
glog.Warningf("Neither --kubeconfig nor --master was specified. Using default API client. This might not work.")
}

if s.Master != "" {
kubeconfig.Host = s.Master
// This creates a client, first loading any specified kubeconfig
// file, and then overriding the Master flag, if non-empty.
kubeconfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: s.Master}}).ClientConfig()
if err != nil {
return err
}
kubeconfig.QPS = 20.0
kubeconfig.Burst = 100
Expand Down

0 comments on commit e696c96

Please sign in to comment.