recorder

package
v0.2.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package recorder defines interfaces for working with Kubernetes event recorders.

You can use these to emit Kubernetes events associated with a particular Kubernetes object.

Example (Event)
package main

import (
	corev1 "k8s.io/api/core/v1"

	"sigs.k8s.io/controller-runtime/pkg/recorder"
)

var (
	recorderProvider recorder.Provider
	somePod          *corev1.Pod
)

func main() {
	// recorderProvider is a recorder.Provider
	recorder := recorderProvider.GetEventRecorderFor("my-controller")

	// emit an event with a fixed message
	recorder.Event(somePod, corev1.EventTypeWarning,
		"WrongTrousers", "It's the wrong trousers, Gromit!")
}
Output:

Example (Eventf)
package main

import (
	corev1 "k8s.io/api/core/v1"

	"sigs.k8s.io/controller-runtime/pkg/recorder"
)

var (
	recorderProvider recorder.Provider
	somePod          *corev1.Pod
)

func main() {
	// recorderProvider is a recorder.Provider
	recorder := recorderProvider.GetEventRecorderFor("my-controller")

	// emit an event with a variable message
	mildCheese := "Wensleydale"
	recorder.Eventf(somePod, corev1.EventTypeNormal,
		"DislikesCheese", "Not even %s?", mildCheese)
}
Output:

Example (PastEventf)
package main

import (
	"time"

	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

	"sigs.k8s.io/controller-runtime/pkg/recorder"
)

var (
	recorderProvider recorder.Provider
	somePod          *corev1.Pod
)

func main() {
	// recorderProvider is a recorder.Provider
	recorder := recorderProvider.GetEventRecorderFor("my-controller")

	// emit a backdated event (potentially with variable message)
	recorder.PastEventf(somePod, metav1.Time{Time: time.Now().Add(-5 * time.Minute)},
		corev1.EventTypeWarning, "ForgottenCrackers",
		"Crackers, Gromit!  We forgot the crackers!")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	// NewRecorder returns an EventRecorder with given name.
	GetEventRecorderFor(name string) record.EventRecorder
}

Provider knows how to generate new event recorders with given name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL