mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 03:33:26 +00:00
controller, scheduler, proxy use kubeconfig
--master option still supported. --kubeconfig option added to kube-proxy, kube-scheduler, and kube-controller-manager binaries. Kube-proxy now always makes some kind of API source, since that is its only kind of config. Warn if it is using a default client, which probably won't work. Uses the clientcmd builder.
This commit is contained in:
@@ -29,6 +29,8 @@ import (
|
||||
"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"
|
||||
@@ -47,7 +49,6 @@ import (
|
||||
type CMServer struct {
|
||||
Port int
|
||||
Address util.IP
|
||||
ClientConfig client.Config
|
||||
CloudProvider string
|
||||
CloudConfigFile string
|
||||
MinionRegexp string
|
||||
@@ -72,6 +73,9 @@ type CMServer struct {
|
||||
|
||||
ClusterName string
|
||||
EnableProfiling bool
|
||||
|
||||
Master string
|
||||
Kubeconfig string
|
||||
}
|
||||
|
||||
// NewCMServer creates a new CMServer with a default config.
|
||||
@@ -96,9 +100,6 @@ func NewCMServer() *CMServer {
|
||||
func (s *CMServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.IntVar(&s.Port, "port", s.Port, "The port that the controller-manager's http service runs on")
|
||||
fs.Var(&s.Address, "address", "The IP address to serve on (set to 0.0.0.0 for all interfaces)")
|
||||
s.ClientConfig.QPS = 20.0
|
||||
s.ClientConfig.Burst = 30
|
||||
client.BindClientConfigFlags(fs, &s.ClientConfig)
|
||||
fs.StringVar(&s.CloudProvider, "cloud_provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
|
||||
fs.StringVar(&s.CloudConfigFile, "cloud_config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||
fs.StringVar(&s.MinionRegexp, "minion_regexp", s.MinionRegexp, "If non empty, and --cloud_provider is specified, a regular expression for matching minion VMs.")
|
||||
@@ -130,6 +131,8 @@ func (s *CMServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.Var(resource.NewQuantityFlagValue(&s.NodeMemory), "node_memory", "The amount of memory (in bytes) provisioned on each node")
|
||||
fs.StringVar(&s.ClusterName, "cluster_name", s.ClusterName, "The instance prefix for the cluster")
|
||||
fs.BoolVar(&s.EnableProfiling, "profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
|
||||
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
|
||||
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
|
||||
}
|
||||
|
||||
func (s *CMServer) verifyMinionFlags() {
|
||||
@@ -151,11 +154,23 @@ func (s *CMServer) verifyMinionFlags() {
|
||||
func (s *CMServer) Run(_ []string) error {
|
||||
s.verifyMinionFlags()
|
||||
|
||||
if len(s.ClientConfig.Host) == 0 {
|
||||
glog.Fatal("usage: controller-manager --master <master>")
|
||||
if s.Kubeconfig == "" && s.Master == "" {
|
||||
glog.Warningf("Neither --kubeconfig nor --master was specified. Using default API client. This might not work.")
|
||||
}
|
||||
|
||||
kubeClient, err := client.New(&s.ClientConfig)
|
||||
// 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 = 30
|
||||
|
||||
kubeClient, err := client.New(kubeconfig)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid API configuration: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user