| 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 internal is needed to break an import cycle: record.EventRecorderAdapter |
| 18 |
// needs this interface definition to implement it, but event.NewEventBroadcasterAdapter |
| 19 |
// needs record.NewBroadcaster. Therefore this interface cannot be in event/interfaces.go. |
| 20 |
package internal |
| 21 |
|
| 22 |
import ( |
| 23 |
"k8s.io/apimachinery/pkg/runtime" |
| 24 |
"k8s.io/klog/v2" |
| 25 |
) |
| 26 |
|
| 27 |
// EventRecorder knows how to record events on behalf of an EventSource. |
| 28 |
type EventRecorder interface { |
| 29 |
// Eventf constructs an event from the given information and puts it in the queue for sending. |
| 30 |
// 'regarding' is the object this event is about. Event will make a reference-- or you may also |
| 31 |
// pass a reference to the object directly. |
| 32 |
// 'related' is the secondary object for more complex actions. E.g. when regarding object triggers |
| 33 |
// a creation or deletion of related object. |
| 34 |
// 'type' of this event, and can be one of Normal, Warning. New types could be added in future |
| 35 |
// 'reason' is the reason this event is generated. 'reason' should be short and unique; it |
| 36 |
// should be in UpperCamelCase format (starting with a capital letter). "reason" will be used |
| 37 |
// to automate handling of events, so imagine people writing switch statements to handle them. |
| 38 |
// You want to make that easy. |
| 39 |
// 'action' explains what happened with regarding/what action did the ReportingController |
| 40 |
// (ReportingController is a type of a Controller reporting an Event, e.g. k8s.io/node-controller, k8s.io/kubelet.) |
| 41 |
// take in regarding's name; it should be in UpperCamelCase format (starting with a capital letter). |
| 42 |
// 'note' is intended to be human readable. |
| 43 |
Eventf(regarding runtime.Object, related runtime.Object, eventtype, reason, action, note string, args ...interface{}) |
| 44 |
} |
| 45 |
|
| 46 |
// EventRecorderLogger extends EventRecorder such that a logger can |
| 47 |
// be set for methods in EventRecorder. Normally, those methods |
| 48 |
// uses the global default logger to record errors and debug messages. |
| 49 |
// If that is not desired, use WithLogger to provide a logger instance. |
| 50 |
type EventRecorderLogger interface { |
| 51 |
EventRecorder |
| 52 |
|
| 53 |
// WithLogger replaces the context used for logging. This is a cheap call |
| 54 |
// and meant to be used for contextual logging: |
| 55 |
// recorder := ... |
| 56 |
// logger := klog.FromContext(ctx) |
| 57 |
// recorder.WithLogger(logger).Eventf(...) |
| 58 |
WithLogger(logger klog.Logger) EventRecorderLogger |
| 59 |
} |