events

package
v0.0.0-...-1670326 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventJobStarted     NormalEvent = "JobStarted"
	EventJobStopped     NormalEvent = "JobStopped"
	EventJobRestarted   NormalEvent = "JobRestarted"
	EventJobSuspended   NormalEvent = "JobSuspended"
	EventJobUnsuspended NormalEvent = "JobUnsuspended"

	// All warning events must start with 'Failed'
	FailedToReconcile              WarningEvent = "FailedToReconcile"
	FailedToListJobs               WarningEvent = "FailedToListJobs"
	FailedToListJobsForPeriod      WarningEvent = "FailedToListJobsForPeriod"
	FailedToUpdateStatus           WarningEvent = "FailedToUpdateStatus"
	FailedToCalculateSchedule      WarningEvent = "FailedToCalculateSchedule"
	FailedToCalculateDesiredStatus WarningEvent = "FailedToCalculateDesiredStatus"
	FailedToTemplateJob            WarningEvent = "FailedToTemplateJob"
	FailedToCreateJob              WarningEvent = "FailedToCreateJob"
	FailedToDeleteJob              WarningEvent = "FailedToDeleteJob"
	FailedToSuspendJob             WarningEvent = "FailedToSuspendJob"
	FailedToUnsuspendJob           WarningEvent = "FailedToUnsuspendJob"
)
View Source
const HistoryEntriesToKeep = 16

Variables

View Source
var NowFunc func() *time.Time

Func to get now. Extracted as a variable so we can override it in tests

Functions

func IsWarningEvent

func IsWarningEvent(event string) bool

func NewJobFailedAction

func NewJobFailedAction(event WarningEvent, err error, jobName string) *batch.ControlledJobActionHistoryEntry

func NewJobStartedAction

func NewJobStartedAction(jobName string) *batch.ControlledJobActionHistoryEntry

func NewJobStoppedAction

func NewJobStoppedAction(jobName string) *batch.ControlledJobActionHistoryEntry

func NewJobSuspendedAction

func NewJobSuspendedAction(jobName string) *batch.ControlledJobActionHistoryEntry

func NewJobUnsuspendedAction

func NewJobUnsuspendedAction(jobName string) *batch.ControlledJobActionHistoryEntry

func WrapError

func WrapError(err error, event WarningEvent, message string) error

Types

type ErrorWithEvent

type ErrorWithEvent struct {
	// contains filtered or unexported fields
}

func (*ErrorWithEvent) Error

func (e *ErrorWithEvent) Error() string

func (*ErrorWithEvent) Event

func (e *ErrorWithEvent) Event() WarningEvent

type EventRecorder

type EventRecorder = record.EventRecorder

Make a shadow of the record.EventRecorder type so we can mock it

type EventRecorderMock

type EventRecorderMock struct {
	// AnnotatedEventfFunc mocks the AnnotatedEventf method.
	AnnotatedEventfFunc func(object runtime.Object, annotations map[string]string, eventtype string, reason string, messageFmt string, args ...interface{})

	// EventFunc mocks the Event method.
	EventFunc func(object runtime.Object, eventtype string, reason string, message string)

	// EventfFunc mocks the Eventf method.
	EventfFunc func(object runtime.Object, eventtype string, reason string, messageFmt string, args ...interface{})
	// contains filtered or unexported fields
}

EventRecorderMock is a mock implementation of EventRecorder.

func TestSomethingThatUsesEventRecorder(t *testing.T) {

	// make and configure a mocked EventRecorder
	mockedEventRecorder := &EventRecorderMock{
		AnnotatedEventfFunc: func(object runtime.Object, annotations map[string]string, eventtype string, reason string, messageFmt string, args ...interface{})  {
			panic("mock out the AnnotatedEventf method")
		},
		EventFunc: func(object runtime.Object, eventtype string, reason string, message string)  {
			panic("mock out the Event method")
		},
		EventfFunc: func(object runtime.Object, eventtype string, reason string, messageFmt string, args ...interface{})  {
			panic("mock out the Eventf method")
		},
	}

	// use mockedEventRecorder in code that requires EventRecorder
	// and then make assertions.

}

func (*EventRecorderMock) AnnotatedEventf

func (mock *EventRecorderMock) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype string, reason string, messageFmt string, args ...interface{})

AnnotatedEventf calls AnnotatedEventfFunc.

func (*EventRecorderMock) AnnotatedEventfCalls

func (mock *EventRecorderMock) AnnotatedEventfCalls() []struct {
	Object      runtime.Object
	Annotations map[string]string
	Eventtype   string
	Reason      string
	MessageFmt  string
	Args        []interface{}
}

AnnotatedEventfCalls gets all the calls that were made to AnnotatedEventf. Check the length with:

len(mockedEventRecorder.AnnotatedEventfCalls())

func (*EventRecorderMock) Event

func (mock *EventRecorderMock) Event(object runtime.Object, eventtype string, reason string, message string)

Event calls EventFunc.

func (*EventRecorderMock) EventCalls

func (mock *EventRecorderMock) EventCalls() []struct {
	Object    runtime.Object
	Eventtype string
	Reason    string
	Message   string
}

EventCalls gets all the calls that were made to Event. Check the length with:

len(mockedEventRecorder.EventCalls())

func (*EventRecorderMock) Eventf

func (mock *EventRecorderMock) Eventf(object runtime.Object, eventtype string, reason string, messageFmt string, args ...interface{})

Eventf calls EventfFunc.

func (*EventRecorderMock) EventfCalls

func (mock *EventRecorderMock) EventfCalls() []struct {
	Object     runtime.Object
	Eventtype  string
	Reason     string
	MessageFmt string
	Args       []interface{}
}

EventfCalls gets all the calls that were made to Eventf. Check the length with:

len(mockedEventRecorder.EventfCalls())

type Handler

type Handler interface {
	RecordEvent(ctx context.Context, controlledJob *batch.ControlledJob, action *batch.ControlledJobActionHistoryEntry)
}

Handler abstracts the handling of controller events

func NewHandler

func NewHandler(recorder record.EventRecorder) Handler

type HandlerMock

type HandlerMock struct {
	// RecordEventFunc mocks the RecordEvent method.
	RecordEventFunc func(ctx context.Context, controlledJob *batch.ControlledJob, action *batch.ControlledJobActionHistoryEntry)
	// contains filtered or unexported fields
}

HandlerMock is a mock implementation of Handler.

func TestSomethingThatUsesHandler(t *testing.T) {

	// make and configure a mocked Handler
	mockedHandler := &HandlerMock{
		RecordEventFunc: func(ctx context.Context, controlledJob *batch.ControlledJob, action *batch.ControlledJobActionHistoryEntry)  {
			panic("mock out the RecordEvent method")
		},
	}

	// use mockedHandler in code that requires Handler
	// and then make assertions.

}

func (*HandlerMock) RecordEvent

func (mock *HandlerMock) RecordEvent(ctx context.Context, controlledJob *batch.ControlledJob, action *batch.ControlledJobActionHistoryEntry)

RecordEvent calls RecordEventFunc.

func (*HandlerMock) RecordEventCalls

func (mock *HandlerMock) RecordEventCalls() []struct {
	Ctx           context.Context
	ControlledJob *batch.ControlledJob
	Action        *batch.ControlledJobActionHistoryEntry
}

RecordEventCalls gets all the calls that were made to RecordEvent. Check the length with:

len(mockedHandler.RecordEventCalls())

type NormalEvent

type NormalEvent string

type WarningEvent

type WarningEvent string

Jump to

Keyboard shortcuts

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