timewindow

package
v1.85.3 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0, BSD-2-Clause, MIT, + 1 more Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AlwaysTimeWindow = NewMaintenanceTimeWindow(NewMaintenanceTime(0, 0, 0), NewMaintenanceTime(23, 59, 59))

AlwaysTimeWindow is a MaintenanceTimeWindow that contains all durations.

View Source
var RandomFunc = rand.Int63nRange

RandomFunc is a function that computes a random number.

Functions

func DetermineSchedule added in v1.62.0

func DetermineSchedule(
	scheduleFormat string,
	begin, end string,
	uid types.UID,
	creationTimestamp metav1.Time,
	mutate MutateScheduleFunc,
) (
	string,
	error,
)

DetermineSchedule determines a schedule based on the provided format and the creation timestamp. If both the begin and end of a maintenance time window are provided and different from the 'always time window' then the provided mutation function is applied.

func RandomizeWithinFirstHourOfTimeWindow added in v1.62.0

func RandomizeWithinFirstHourOfTimeWindow(scheduleFormat string, window MaintenanceTimeWindow, uid types.UID) string

RandomizeWithinFirstHourOfTimeWindow computes a random time (based on the provided UID) within the first hour of the provided time window. It adds a 15 minutes time buffer before the start.

func RandomizeWithinTimeWindow added in v1.62.0

func RandomizeWithinTimeWindow(scheduleFormat string, window MaintenanceTimeWindow, uid types.UID) string

RandomizeWithinTimeWindow computes a random time (based on the provided UID) within the provided time window.

Types

type MaintenanceTime

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

MaintenanceTime is a structure holding a maintenance time.

func NewMaintenanceTime

func NewMaintenanceTime(hour, minute, second int) *MaintenanceTime

NewMaintenanceTime returns a maintenance time structure based on the given hour, minute, and second.

func ParseMaintenanceTime

func ParseMaintenanceTime(value string) (*MaintenanceTime, error)

ParseMaintenanceTime parses the given value and returns it as MaintenanceTime object. In case the parsing fails, an error is returned. The time object is converted to UTC zone.

func (*MaintenanceTime) Add

func (m *MaintenanceTime) Add(hour, minute, second int) *MaintenanceTime

Add adds hour, minute and second to <m> and returns a new maintenance time.

func (*MaintenanceTime) Compare

func (m *MaintenanceTime) Compare(other *MaintenanceTime) int

Compare compares the two times <m> and <other>. It returns * i < 0 if <m> is before other * i = 0 if <m> is equal other * i > 0 if <m> is after other

func (*MaintenanceTime) Formatted

func (m *MaintenanceTime) Formatted() string

Formatted formats the maintenance time object to the maintenance time format.

func (*MaintenanceTime) Hour

func (m *MaintenanceTime) Hour() int

Hour returns the hour of the maintenance time.

func (*MaintenanceTime) Minute

func (m *MaintenanceTime) Minute() int

Minute returns the minute of the maintenance time.

func (*MaintenanceTime) Second

func (m *MaintenanceTime) Second() int

Second returns the second of the maintenance time.

func (*MaintenanceTime) String

func (m *MaintenanceTime) String() string

String returns the string representation of the maintenance time.

type MaintenanceTimeWindow

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

MaintenanceTimeWindow contains the beginning and the end of a time window in which maintenance operations can be performed.

func NewMaintenanceTimeWindow

func NewMaintenanceTimeWindow(begin, end *MaintenanceTime) *MaintenanceTimeWindow

NewMaintenanceTimeWindow takes a begin and an end of a time window and returns a pointer to a MaintenanceTimeWindow structure.

func ParseMaintenanceTimeWindow

func ParseMaintenanceTimeWindow(begin, end string) (*MaintenanceTimeWindow, error)

ParseMaintenanceTimeWindow takes a begin and an end of a time window in the maintenance format and returns a pointer to a MaintenanceTimeWindow structure.

func RandomMaintenanceTimeWindow

func RandomMaintenanceTimeWindow() *MaintenanceTimeWindow

RandomMaintenanceTimeWindow computes a random time window and returns both in the format HHMMSS+ZONE.

func (*MaintenanceTimeWindow) Begin

Begin returns the begin of the time window.

func (*MaintenanceTimeWindow) Contains

func (m *MaintenanceTimeWindow) Contains(tTime time.Time) bool

Contains returns true in case the given time is within the time window.

func (*MaintenanceTimeWindow) Duration

func (m *MaintenanceTimeWindow) Duration() time.Duration

Duration returns the duration of the maintenance time window.

func (*MaintenanceTimeWindow) End

End returns the end of the time window.

func (*MaintenanceTimeWindow) Equal

Equal returns true if the time windows are the same.

func (*MaintenanceTimeWindow) RandomDurationUntilNext

func (m *MaintenanceTimeWindow) RandomDurationUntilNext(from time.Time, shiftBeginToFromIfContained bool) time.Duration

RandomDurationUntilNext computes the duration until a random time within the time window for the next maintenance execution. The <from> parameter is the time from which the calculation for the next maintenance time window shall be performed (typically: time.Now()). The <shiftBeginToFromIfContained> parameter controls whether the beginning of the maintenance time window should be changed to <from> if <from> is already inside the maintenance time window (otherwise, it has no effect). As a consequence, this will return a random duration from <from> until the end of the maintenance time window which is shorter than 24h.

func (*MaintenanceTimeWindow) String

func (m *MaintenanceTimeWindow) String() string

String returns the string representation of the time window.

func (*MaintenanceTimeWindow) WithBegin

WithBegin returns a new maintenance time window with the given <begin> (ending will be kept).

func (*MaintenanceTimeWindow) WithEnd

WithEnd returns a new maintenance time window with the given <end> (beginning will be kept).

type MutateScheduleFunc added in v1.62.0

type MutateScheduleFunc func(string, MaintenanceTimeWindow, types.UID) string

MutateScheduleFunc is a function for mutating the schedule based on the maintenance time window and UID.

Jump to

Keyboard shortcuts

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