2021-08-09 07:19:24 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
2023-12-20 12:23:59 +00:00
|
|
|
"context"
|
|
|
|
|
2021-08-09 07:19:24 +00:00
|
|
|
eventsv1 "k8s.io/api/events/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2023-12-20 12:23:59 +00:00
|
|
|
internalevents "k8s.io/client-go/tools/internal/events"
|
2021-08-09 07:19:24 +00:00
|
|
|
"k8s.io/client-go/tools/record"
|
2021-12-08 13:50:47 +00:00
|
|
|
"k8s.io/klog/v2"
|
2021-08-09 07:19:24 +00:00
|
|
|
)
|
|
|
|
|
2023-12-20 12:23:59 +00:00
|
|
|
type EventRecorder = internalevents.EventRecorder
|
|
|
|
type EventRecorderLogger = internalevents.EventRecorderLogger
|
2021-08-09 07:19:24 +00:00
|
|
|
|
|
|
|
// EventBroadcaster knows how to receive events and send them to any EventSink, watcher, or log.
|
|
|
|
type EventBroadcaster interface {
|
|
|
|
// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
|
2023-12-20 12:23:59 +00:00
|
|
|
// Deprecated: use StartRecordingToSinkWithContext instead.
|
2021-08-09 07:19:24 +00:00
|
|
|
StartRecordingToSink(stopCh <-chan struct{})
|
|
|
|
|
2023-12-20 12:23:59 +00:00
|
|
|
// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
|
|
|
|
StartRecordingToSinkWithContext(ctx context.Context) error
|
|
|
|
|
2021-08-09 07:19:24 +00:00
|
|
|
// NewRecorder returns an EventRecorder that can be used to send events to this EventBroadcaster
|
|
|
|
// with the event source set to the given event source.
|
2023-12-20 12:23:59 +00:00
|
|
|
NewRecorder(scheme *runtime.Scheme, reportingController string) EventRecorderLogger
|
2021-08-09 07:19:24 +00:00
|
|
|
|
|
|
|
// StartEventWatcher enables you to watch for emitted events without usage
|
|
|
|
// of StartRecordingToSink. This lets you also process events in a custom way (e.g. in tests).
|
|
|
|
// NOTE: events received on your eventHandler should be copied before being used.
|
|
|
|
// TODO: figure out if this can be removed.
|
2023-02-01 17:06:36 +00:00
|
|
|
StartEventWatcher(eventHandler func(event runtime.Object)) (func(), error)
|
2021-08-09 07:19:24 +00:00
|
|
|
|
2021-12-08 13:50:47 +00:00
|
|
|
// StartStructuredLogging starts sending events received from this EventBroadcaster to the structured
|
|
|
|
// logging function. The return value can be ignored or used to stop recording, if desired.
|
2023-12-20 12:23:59 +00:00
|
|
|
// Deprecated: use StartLogging instead.
|
2021-12-08 13:50:47 +00:00
|
|
|
StartStructuredLogging(verbosity klog.Level) func()
|
|
|
|
|
2023-12-20 12:23:59 +00:00
|
|
|
// StartLogging starts sending events received from this EventBroadcaster to the structured logger.
|
|
|
|
// To adjust verbosity, use the logger's V method (i.e. pass `logger.V(3)` instead of `logger`).
|
|
|
|
// The returned function can be ignored or used to stop recording, if desired.
|
|
|
|
StartLogging(logger klog.Logger) (func(), error)
|
|
|
|
|
2021-08-09 07:19:24 +00:00
|
|
|
// Shutdown shuts down the broadcaster
|
|
|
|
Shutdown()
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventSink knows how to store events (client-go implements it.)
|
|
|
|
// EventSink must respect the namespace that will be embedded in 'event'.
|
|
|
|
// It is assumed that EventSink will return the same sorts of errors as
|
|
|
|
// client-go's REST client.
|
|
|
|
type EventSink interface {
|
2023-12-20 12:23:59 +00:00
|
|
|
Create(ctx context.Context, event *eventsv1.Event) (*eventsv1.Event, error)
|
|
|
|
Update(ctx context.Context, event *eventsv1.Event) (*eventsv1.Event, error)
|
|
|
|
Patch(ctx context.Context, oldEvent *eventsv1.Event, data []byte) (*eventsv1.Event, error)
|
2021-08-09 07:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EventBroadcasterAdapter is a auxiliary interface to simplify migration to
|
|
|
|
// the new events API. It is a wrapper around new and legacy broadcasters
|
|
|
|
// that smartly chooses which one to use.
|
|
|
|
//
|
|
|
|
// Deprecated: This interface will be removed once migration is completed.
|
|
|
|
type EventBroadcasterAdapter interface {
|
|
|
|
// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
|
|
|
|
StartRecordingToSink(stopCh <-chan struct{})
|
|
|
|
|
|
|
|
// NewRecorder creates a new Event Recorder with specified name.
|
2023-12-20 12:23:59 +00:00
|
|
|
NewRecorder(name string) EventRecorderLogger
|
2021-08-09 07:19:24 +00:00
|
|
|
|
|
|
|
// DeprecatedNewLegacyRecorder creates a legacy Event Recorder with specific name.
|
2023-12-20 12:23:59 +00:00
|
|
|
DeprecatedNewLegacyRecorder(name string) record.EventRecorderLogger
|
2021-08-09 07:19:24 +00:00
|
|
|
|
|
|
|
// Shutdown shuts down the broadcaster.
|
|
|
|
Shutdown()
|
|
|
|
}
|