...

Package util

import "framework/util"
Overview
Index

Overview ▾

Constants

const (
    // The state key for storing a NodeEligibilityStats object.
    NodeEligibilityStatsInfoStateKey = "polaris-internal.node-eligibility-stats"
)
const (
    // StopwatchStateKey can be used as a key in the scheduler's state data for storing a single Stopwatch.
    StopwatchStateKey = "polaris-internal.stopwatch"
)

func ParseYamlFile

func ParseYamlFile(path string, dest interface{}) error

Loads and parses the YAML file in the specified path and stores the result into the dest object.

The dest object must not be nil. Returns nil on success or an error, if any occurs.

func SetupSignalHandlingContext

func SetupSignalHandlingContext() context.Context

Creates a Context that gets cancelled upon an interrupt or TERM signal. If the signal is received a second time, the program will be exited immediately.

type NodeEligibilityStats

Information about sampled and eligible node counts.

type NodeEligibilityStats struct {
    // The total number of nodes that were sampled.
    SampledNodesCount int

    // The number of nodes that are eligible to host a pod after the Filter stage in the decision pipeline.
    EligibleNodesCount int
}

type Random

A random number generator interface, for easily switching between multiple random number generator implementations. Implementations of this interface are generally NOT thread-safe.

type Random interface {
    // Generates a random integer in the interval [0, max)
    Int(max int) int
}

func NewCryptoRandom

func NewCryptoRandom() Random

Creates an instance of a Random implementation using the crypto/rand package.

func NewDefaultRandom

func NewDefaultRandom() Random

Creates an instance of the default Random implementation.

func NewMathRandom

func NewMathRandom() Random

Creates an instance of a Random implementation using the math/rand package, seeded using rand.Int63().

type Resources

Represents a set of resources requested or consumed by a Pod.

type Resources struct {
    MilliCPU          int64                       `json:"milliCpu" yaml:"milliCpu"`
    MemoryBytes       int64                       `json:"memoryBytes" yaml:"memoryBytes"`
    EphemeralStorage  int64                       `json:"ephemeralStorage" yaml:"ephemeralStorage"`
    ExtendedResources map[core.ResourceName]int64 `json:"extendedResources" yaml:"extendedResources"`
}

func CalculateNodeAvailableResources

func CalculateNodeAvailableResources(node *core.Node, assignedPods []core.Pod) *Resources

Calculates a node's available resources, i.e., its total resource - resources used by already assigned pods.

func CalculateTotalPodResources

func CalculateTotalPodResources(pod *core.Pod) *Resources

Calculates the total resource limits across all of the specified pod's containers.

func NewResources

func NewResources() *Resources

Creates a new, empty Resources object.

func NewResourcesFromList

func NewResourcesFromList(rl core.ResourceList) *Resources

Creates a Resources object and initializes it with the specified ResourceList.

func (*Resources) Add

func (r *Resources) Add(other *Resources)

Adds the values in the specified Resources object to this Resources object.

func (*Resources) AddResourceList

func (r *Resources) AddResourceList(rl core.ResourceList)

Adds the specified ResourceList to this Resources object.

func (*Resources) DeepCopy

func (r *Resources) DeepCopy() *Resources

Creates a deep copy of this Resources object.

func (*Resources) Equals

func (r *Resources) Equals(other *Resources) bool

Returns true if the values in this object are the same as in the other resources object.

func (*Resources) LessThanOrEqual

func (r *Resources) LessThanOrEqual(other *Resources) bool

Returns true if all resource numbers expressed by this object are less than or equal to the ones expressed in the other object.

func (*Resources) Subtract

func (r *Resources) Subtract(other *Resources)

Subtracts the values in the specified Resources object from this Resources object.

func (*Resources) SubtractResourceList

func (r *Resources) SubtractResourceList(rl core.ResourceList)

Subtracts the specified ResourceList from this Resources object.

type Stopwatch

Stopwatch can be used to measure the time between two instants.

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

func NewStopwatch

func NewStopwatch() *Stopwatch

NewStopwatch creates a new Stopwatch.

func (*Stopwatch) Duration

func (me *Stopwatch) Duration() time.Duration

Duration returns the duration of the time that was measured by this Stopwatch.

func (*Stopwatch) IsStarted

func (me *Stopwatch) IsStarted() bool

IsStarted returns true if the stopwatch has been started.

Note that this is not reset after the stopwatch is stopped. A stopped stopwatch has both IsStarted() and IsStopped() return true.

func (*Stopwatch) IsStopped

func (me *Stopwatch) IsStopped() bool

IsStopped returns true if the stopwatch has already been stopped.

func (*Stopwatch) Start

func (me *Stopwatch) Start()

Start sets the current time as the start time of the Stopwatch.

func (*Stopwatch) StartAt

func (me *Stopwatch) StartAt(startTime time.Time)

StartAt sets the specified time as the start time of the Stopwatch.

func (*Stopwatch) StartTime

func (me *Stopwatch) StartTime() time.Time

Returns the start time of this stopwatch. Note that this value only makes sense, if the stopwatch has been started.

func (*Stopwatch) Stop

func (me *Stopwatch) Stop()

Stop sets the current time as the stop time of the Stopwatch.

It is explicitly supported to stop a stopwatch multiple times and read the duration after every stoppage to get multiple time readings.

func (*Stopwatch) StopTime

func (me *Stopwatch) StopTime() time.Time

Returns the stop time of this stopwatch. Note that this value only makes sense, if the stopwatch has been stopped.