mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-24 19:12:02 +00:00
Adding a 'PastEventf' method to EventRecorder interface. This will be
useful for recording the timestamp of events that happened in the past.
This commit is contained in:
parent
2f68cddbd2
commit
820d0f3e83
@ -61,6 +61,9 @@ type EventRecorder interface {
|
||||
|
||||
// Eventf is just like Event, but with Sprintf for the message field.
|
||||
Eventf(object runtime.Object, reason, messageFmt string, args ...interface{})
|
||||
|
||||
// PastEventf is just like Eventf, but with an option to specify the event's 'timestamp' field.
|
||||
PastEventf(object runtime.Object, timestamp util.Time, reason, messageFmt string, args ...interface{})
|
||||
}
|
||||
|
||||
// EventBroadcaster knows how to receive events and send them to any EventSink, watcher, or log.
|
||||
@ -234,7 +237,7 @@ type recorderImpl struct {
|
||||
*watch.Broadcaster
|
||||
}
|
||||
|
||||
func (recorder *recorderImpl) Event(object runtime.Object, reason, message string) {
|
||||
func (recorder *recorderImpl) generateEvent(object runtime.Object, timestamp util.Time, reason, message string) {
|
||||
ref, err := api.GetReference(object)
|
||||
if err != nil {
|
||||
glog.Errorf("Could not construct reference to: '%#v' due to: '%v'. Will not report event: '%v' '%v'", object, err, reason, message)
|
||||
@ -247,10 +250,18 @@ func (recorder *recorderImpl) Event(object runtime.Object, reason, message strin
|
||||
recorder.Action(watch.Added, event)
|
||||
}
|
||||
|
||||
func (recorder *recorderImpl) Event(object runtime.Object, reason, message string) {
|
||||
recorder.generateEvent(object, util.Now(), reason, message)
|
||||
}
|
||||
|
||||
func (recorder *recorderImpl) Eventf(object runtime.Object, reason, messageFmt string, args ...interface{}) {
|
||||
recorder.Event(object, reason, fmt.Sprintf(messageFmt, args...))
|
||||
}
|
||||
|
||||
func (recorder *recorderImpl) PastEventf(object runtime.Object, timestamp util.Time, reason, messageFmt string, args ...interface{}) {
|
||||
recorder.generateEvent(object, timestamp, reason, fmt.Sprintf(messageFmt, args...))
|
||||
}
|
||||
|
||||
func makeEvent(ref *api.ObjectReference, reason, message string) *api.Event {
|
||||
t := util.Now()
|
||||
return &api.Event{
|
||||
|
@ -18,6 +18,7 @@ package record
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
// FakeRecorder is used as a fake during tests.
|
||||
@ -26,3 +27,6 @@ type FakeRecorder struct{}
|
||||
func (f *FakeRecorder) Event(object runtime.Object, reason, message string) {}
|
||||
|
||||
func (f *FakeRecorder) Eventf(object runtime.Object, reason, messageFmt string, args ...interface{}) {}
|
||||
|
||||
func (f *FakeRecorder) PastEventf(object runtime.Object, timestamp util.Time, reason, messageFmt string, args ...interface{}) {
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import (
|
||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
"github.com/golang/groupcache/lru"
|
||||
)
|
||||
|
@ -53,7 +53,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user