k8s.io/client-go@v0.22.2/tools/events/interfaces.go (about)

     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  	eventsv1 "k8s.io/api/events/v1"
    21  	"k8s.io/apimachinery/pkg/runtime"
    22  	"k8s.io/client-go/tools/record"
    23  )
    24  
    25  // EventRecorder knows how to record events on behalf of an EventSource.
    26  type EventRecorder interface {
    27  	// Eventf constructs an event from the given information and puts it in the queue for sending.
    28  	// 'regarding' is the object this event is about. Event will make a reference-- or you may also
    29  	// pass a reference to the object directly.
    30  	// 'related' is the secondary object for more complex actions. E.g. when regarding object triggers
    31  	// a creation or deletion of related object.
    32  	// 'type' of this event, and can be one of Normal, Warning. New types could be added in future
    33  	// 'reason' is the reason this event is generated. 'reason' should be short and unique; it
    34  	// should be in UpperCamelCase format (starting with a capital letter). "reason" will be used
    35  	// to automate handling of events, so imagine people writing switch statements to handle them.
    36  	// You want to make that easy.
    37  	// 'action' explains what happened with regarding/what action did the ReportingController
    38  	// (ReportingController is a type of a Controller reporting an Event, e.g. k8s.io/node-controller, k8s.io/kubelet.)
    39  	// take in regarding's name; it should be in UpperCamelCase format (starting with a capital letter).
    40  	// 'note' is intended to be human readable.
    41  	Eventf(regarding runtime.Object, related runtime.Object, eventtype, reason, action, note string, args ...interface{})
    42  }
    43  
    44  // EventBroadcaster knows how to receive events and send them to any EventSink, watcher, or log.
    45  type EventBroadcaster interface {
    46  	// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
    47  	StartRecordingToSink(stopCh <-chan struct{})
    48  
    49  	// NewRecorder returns an EventRecorder that can be used to send events to this EventBroadcaster
    50  	// with the event source set to the given event source.
    51  	NewRecorder(scheme *runtime.Scheme, reportingController string) EventRecorder
    52  
    53  	// StartEventWatcher enables you to watch for emitted events without usage
    54  	// of StartRecordingToSink. This lets you also process events in a custom way (e.g. in tests).
    55  	// NOTE: events received on your eventHandler should be copied before being used.
    56  	// TODO: figure out if this can be removed.
    57  	StartEventWatcher(eventHandler func(event runtime.Object)) func()
    58  
    59  	// Shutdown shuts down the broadcaster
    60  	Shutdown()
    61  }
    62  
    63  // EventSink knows how to store events (client-go implements it.)
    64  // EventSink must respect the namespace that will be embedded in 'event'.
    65  // It is assumed that EventSink will return the same sorts of errors as
    66  // client-go's REST client.
    67  type EventSink interface {
    68  	Create(event *eventsv1.Event) (*eventsv1.Event, error)
    69  	Update(event *eventsv1.Event) (*eventsv1.Event, error)
    70  	Patch(oldEvent *eventsv1.Event, data []byte) (*eventsv1.Event, error)
    71  }
    72  
    73  // EventBroadcasterAdapter is a auxiliary interface to simplify migration to
    74  // the new events API. It is a wrapper around new and legacy broadcasters
    75  // that smartly chooses which one to use.
    76  //
    77  // Deprecated: This interface will be removed once migration is completed.
    78  type EventBroadcasterAdapter interface {
    79  	// StartRecordingToSink starts sending events received from the specified eventBroadcaster.
    80  	StartRecordingToSink(stopCh <-chan struct{})
    81  
    82  	// NewRecorder creates a new Event Recorder with specified name.
    83  	NewRecorder(name string) EventRecorder
    84  
    85  	// DeprecatedNewLegacyRecorder creates a legacy Event Recorder with specific name.
    86  	DeprecatedNewLegacyRecorder(name string) record.EventRecorder
    87  
    88  	// Shutdown shuts down the broadcaster.
    89  	Shutdown()
    90  }