mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Factor to function.
This commit is contained in:
parent
6430250ce8
commit
c770e70495
@ -110,6 +110,27 @@ func getHostname() string {
|
|||||||
return strings.TrimSpace(string(hostname))
|
return strings.TrimSpace(string(hostname))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getApiserverClient() (*client.Client, error) {
|
||||||
|
authInfo, err := clientauth.LoadFromFile(*authPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
clientConfig, err := authInfo.MergeWithConfig(client.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// TODO: adapt Kube client to support LB over several servers
|
||||||
|
if len(apiServerList) > 1 {
|
||||||
|
glog.Infof("Mulitple api servers specified. Picking first one")
|
||||||
|
}
|
||||||
|
clientConfig.Host = apiServerList[0]
|
||||||
|
if c, err := client.New(&clientConfig); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
util.InitLogs()
|
util.InitLogs()
|
||||||
@ -132,37 +153,17 @@ func main() {
|
|||||||
etcd.SetLogger(util.NewLogger("etcd "))
|
etcd.SetLogger(util.NewLogger("etcd "))
|
||||||
|
|
||||||
// Make an API client if possible.
|
// Make an API client if possible.
|
||||||
var apiClient *client.Client = nil
|
|
||||||
if len(apiServerList) < 1 {
|
if len(apiServerList) < 1 {
|
||||||
glog.Info("No api servers specified.")
|
glog.Info("No api servers specified.")
|
||||||
} else {
|
} else {
|
||||||
authInfo, err := clientauth.LoadFromFile(*authPath)
|
if apiClient, err := getApiserverClient(); err != nil {
|
||||||
if err != nil {
|
glog.Errorf("Unable to make apiserver client: %v", err)
|
||||||
glog.Warningf("Not able to load auth config file: %v", err)
|
|
||||||
} else {
|
} else {
|
||||||
clientConfig, err := authInfo.MergeWithConfig(client.Config{})
|
|
||||||
if err != nil {
|
|
||||||
glog.Warningf("Not able to make client config: %v", err)
|
|
||||||
} else {
|
|
||||||
// TODO: adapt Kube client to support LB over several servers.
|
|
||||||
if len(apiServerList) > 1 {
|
|
||||||
glog.Infof("Mulitple api servers specified. Picking first one")
|
|
||||||
}
|
|
||||||
clientConfig.Host = apiServerList[0]
|
|
||||||
if c, err := client.New(&clientConfig); err != nil {
|
|
||||||
glog.Warningf("No API client configured: %v", err)
|
|
||||||
} else {
|
|
||||||
apiClient = c
|
|
||||||
glog.Infof("API Client created.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Send events to APIserver if there is a client.
|
// Send events to APIserver if there is a client.
|
||||||
if apiClient != nil {
|
|
||||||
glog.Infof("Sending events to APIserver.")
|
glog.Infof("Sending events to APIserver.")
|
||||||
record.StartRecording(apiClient.Events(""), "kubelet")
|
record.StartRecording(apiClient.Events(""), "kubelet")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Log the events locally too.
|
// Log the events locally too.
|
||||||
record.StartLogging(glog.Infof)
|
record.StartLogging(glog.Infof)
|
||||||
|
Loading…
Reference in New Issue
Block a user