mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2024-12-22 19:16:06 +00:00
22 lines
917 B
Go
22 lines
917 B
Go
|
package recorder
|
||
|
|
||
|
import (
|
||
|
"github.com/sirupsen/logrus"
|
||
|
clientv1 "k8s.io/api/core/v1"
|
||
|
clientset "k8s.io/client-go/kubernetes"
|
||
|
"k8s.io/client-go/kubernetes/fake"
|
||
|
"k8s.io/client-go/kubernetes/scheme"
|
||
|
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||
|
kube_record "k8s.io/client-go/tools/record"
|
||
|
)
|
||
|
|
||
|
// CreateEventRecorder creates an event recorder to send custom events to Kubernetes to be recorded for targeted Kubernetes objects
|
||
|
func CreateEventRecorder(kubeClient clientset.Interface) kube_record.EventRecorder {
|
||
|
eventBroadcaster := kube_record.NewBroadcaster()
|
||
|
eventBroadcaster.StartLogging(logrus.Infof)
|
||
|
if _, isfake := kubeClient.(*fake.Clientset); !isfake {
|
||
|
eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(kubeClient.CoreV1().RESTClient()).Events("")})
|
||
|
}
|
||
|
return eventBroadcaster.NewRecorder(scheme.Scheme, clientv1.EventSource{Component: "kube-metrics-adapter"})
|
||
|
}
|