...

Source file src/k8s.io/client-go/tools/events/interfaces.go

Documentation: k8s.io/client-go/tools/events

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package events
    18  
    19  import (
    20  	"context"
    21  
    22  	eventsv1 "k8s.io/api/events/v1"
    23  	"k8s.io/apimachinery/pkg/runtime"
    24  	internalevents "k8s.io/client-go/tools/internal/events"
    25  	"k8s.io/client-go/tools/record"
    26  	"k8s.io/klog/v2"
    27  )
    28  
    29  type EventRecorder = internalevents.EventRecorder
    30  type EventRecorderLogger = internalevents.EventRecorderLogger
    31  
    32  // EventBroadcaster knows how to receive events and send them to any EventSink, watcher, or log.
    33  type EventBroadcaster interface {
    34  	// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
    35  	// Deprecated: use StartRecordingToSinkWithContext instead.
    36  	StartRecordingToSink(stopCh <-chan struct{})
    37  
    38  	// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
    39  	StartRecordingToSinkWithContext(ctx context.Context) error
    40  
    41  	// NewRecorder returns an EventRecorder that can be used to send events to this EventBroadcaster
    42  	// with the event source set to the given event source.
    43  	NewRecorder(scheme *runtime.Scheme, reportingController string) EventRecorderLogger
    44  
    45  	// StartEventWatcher enables you to watch for emitted events without usage
    46  	// of StartRecordingToSink. This lets you also process events in a custom way (e.g. in tests).
    47  	// NOTE: events received on your eventHandler should be copied before being used.
    48  	// TODO: figure out if this can be removed.
    49  	StartEventWatcher(eventHandler func(event runtime.Object)) (func(), error)
    50  
    51  	// StartStructuredLogging starts sending events received from this EventBroadcaster to the structured
    52  	// logging function. The return value can be ignored or used to stop recording, if desired.
    53  	// Deprecated: use StartLogging instead.
    54  	StartStructuredLogging(verbosity klog.Level) func()
    55  
    56  	// StartLogging starts sending events received from this EventBroadcaster to the structured logger.
    57  	// To adjust verbosity, use the logger's V method (i.e. pass `logger.V(3)` instead of `logger`).
    58  	// The returned function can be ignored or used to stop recording, if desired.
    59  	StartLogging(logger klog.Logger) (func(), error)
    60  
    61  	// Shutdown shuts down the broadcaster
    62  	Shutdown()
    63  }
    64  
    65  // EventSink knows how to store events (client-go implements it.)
    66  // EventSink must respect the namespace that will be embedded in 'event'.
    67  // It is assumed that EventSink will return the same sorts of errors as
    68  // client-go's REST client.
    69  type EventSink interface {
    70  	Create(ctx context.Context, event *eventsv1.Event) (*eventsv1.Event, error)
    71  	Update(ctx context.Context, event *eventsv1.Event) (*eventsv1.Event, error)
    72  	Patch(ctx context.Context, oldEvent *eventsv1.Event, data []byte) (*eventsv1.Event, error)
    73  }
    74  
    75  // EventBroadcasterAdapter is a auxiliary interface to simplify migration to
    76  // the new events API. It is a wrapper around new and legacy broadcasters
    77  // that smartly chooses which one to use.
    78  //
    79  // Deprecated: This interface will be removed once migration is completed.
    80  type EventBroadcasterAdapter interface {
    81  	// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
    82  	StartRecordingToSink(stopCh <-chan struct{})
    83  
    84  	// NewRecorder creates a new Event Recorder with specified name.
    85  	NewRecorder(name string) EventRecorderLogger
    86  
    87  	// DeprecatedNewLegacyRecorder creates a legacy Event Recorder with specific name.
    88  	DeprecatedNewLegacyRecorder(name string) record.EventRecorderLogger
    89  
    90  	// Shutdown shuts down the broadcaster.
    91  	Shutdown()
    92  }
    93  

View as plain text