mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Merge pull request #2270 from erictune/kubelet_publish_events
Kubelet publishes events
This commit is contained in:
commit
4681918888
@ -32,7 +32,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
||||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||||
@ -70,11 +72,14 @@ var (
|
|||||||
enableDebuggingHandlers = flag.Bool("enable_debugging_handlers", true, "Enables server endpoints for log collection and local running of containers and commands")
|
enableDebuggingHandlers = flag.Bool("enable_debugging_handlers", true, "Enables server endpoints for log collection and local running of containers and commands")
|
||||||
minimumGCAge = flag.Duration("minimum_container_ttl_duration", 0, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
|
minimumGCAge = flag.Duration("minimum_container_ttl_duration", 0, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
|
||||||
maxContainerCount = flag.Int("maximum_dead_containers_per_container", 5, "Maximum number of old instances of a container to retain per container. Each container takes up some disk space. Default: 5.")
|
maxContainerCount = flag.Int("maximum_dead_containers_per_container", 5, "Maximum number of old instances of a container to retain per container. Each container takes up some disk space. Default: 5.")
|
||||||
|
authPath = flag.String("auth_path", "", "Path to .kubernetes_auth file, specifying how to authenticate to API server.")
|
||||||
|
apiServerList util.StringList
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Var(&etcdServerList, "etcd_servers", "List of etcd servers to watch (http://ip:port), comma separated. Mutually exclusive with -etcd_config")
|
flag.Var(&etcdServerList, "etcd_servers", "List of etcd servers to watch (http://ip:port), comma separated. Mutually exclusive with -etcd_config")
|
||||||
flag.Var(&address, "address", "The IP address for the info server to serve on (set to 0.0.0.0 for all interfaces)")
|
flag.Var(&address, "address", "The IP address for the info server to serve on (set to 0.0.0.0 for all interfaces)")
|
||||||
|
flag.Var(&apiServerList, "api_servers", "List of Kubernetes API servers to publish events to. (ip:port), comma separated.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDockerEndpoint() string {
|
func getDockerEndpoint() string {
|
||||||
@ -105,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()
|
||||||
@ -126,6 +152,19 @@ func main() {
|
|||||||
|
|
||||||
etcd.SetLogger(util.NewLogger("etcd "))
|
etcd.SetLogger(util.NewLogger("etcd "))
|
||||||
|
|
||||||
|
// Make an API client if possible.
|
||||||
|
if len(apiServerList) < 1 {
|
||||||
|
glog.Info("No api servers specified.")
|
||||||
|
} else {
|
||||||
|
if apiClient, err := getApiserverClient(); err != nil {
|
||||||
|
glog.Errorf("Unable to make apiserver client: %v", err)
|
||||||
|
} else {
|
||||||
|
// Send events to APIserver if there is a client.
|
||||||
|
glog.Infof("Sending events to APIserver.")
|
||||||
|
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