resource

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuantityAsFloat64

func QuantityAsFloat64(q resource.Quantity) float64

QuantityAsFloat64 returns a float64 representation of a quantity. We need our own function because q.AsApproximateFloat64 sometimes returns surprising results. For example, resource.MustParse("5188205838208Ki").AsApproximateFloat64() returns 0.004291583283300088, whereas this function returns 5.312722778324993e+15.

Types

type ComputeResources

type ComputeResources map[string]resource.Quantity

func CalculateTotalResource

func CalculateTotalResource(nodes []*v1.Node) ComputeResources

CalculateTotalResource computes the combined total quantity of each resource (cpu, memory, etc) available for scheduling in the slice of nodes supplied as argument in the function.

func CalculateTotalResourceRequest

func CalculateTotalResourceRequest(pods []*v1.Pod) ComputeResources

CalculateTotalResourceRequest computes the combined total quantity of each resource (cpu, memory, etc) requested by each pod in the slice of pods supplied as argument in the function.

func FromProtoMap added in v0.8.7

func FromProtoMap(m map[string]*resource.Quantity) ComputeResources

func FromResourceList

func FromResourceList(list v1.ResourceList) ComputeResources

FromResourceList function takes a map with keys of type ResourceName and values of type "resource.Quantity" as defined in the K8s API.

It converts the keys to strings and creates a new map with the same keys, but with deep copies of the values. The resulting map is of type map[string]resource.Quantity.

func TotalPodResourceRequest

func TotalPodResourceRequest(podSpec *v1.PodSpec) ComputeResources

TotalPodResourceRequest represents the resource request for a given pod is the maximum of:

  • sum of all containers
  • any individual init container

This is because:

  • containers run in parallel (so need to sum resources)
  • init containers run sequentially (so only their individual resource need be considered)

So pod resource usage is the max for each resource type (cpu/memory etc.) that could be used at any given time

func (ComputeResources) Add

func (ComputeResources) AsFloat

AsFloat function, converts ComputeResources to ComputeResourcesFloat.

func (ComputeResources) DeepCopy

func (a ComputeResources) DeepCopy() ComputeResources

func (ComputeResources) Dominates

func (a ComputeResources) Dominates(b ComputeResources) bool

Dominates function compares two ComputeResources maps, a and b, to determine whether "a" is sufficient to meet or exceed the resource quantity of b if it does then "true" is returned if not "false" is returned.

func (ComputeResources) Equal

Equal function compares a and b, returns false:

  • if both are nil.
  • if they have different lengths
  • if a key exists in "a" but does not exist in "b" or vice versa.

func (ComputeResources) IsValid

func (a ComputeResources) IsValid() bool

IsValid function checks if all the values in "a" is greater than or equal to zero. It returns true if all values are valid i.e. all values are greater than or equal to zero, and false if any of the values are negative

func (ComputeResources) IsZero added in v0.3.50

func (a ComputeResources) IsZero() bool

IsZero function checks if every value in "a" is zero. If any value is not zero it returns false, if all are zero, it returns true.

func (ComputeResources) LimitToZero added in v0.3.50

func (a ComputeResources) LimitToZero()

LimitToZero function limits each value in "a" to a minimum value of zero. In the case any value in "a" has a value less than zero, it is replaced with a value of zero.

func (ComputeResources) Max

Max function checks if the key in the ComputeResources Map supplied as an argument, b exists and has a value greater than the already existing value mapped to the key in ComputeResources Map supplied as the method's target, "a", if so, the value of the key is replaced by b's value. If the key does not exist in "a", it is created and made to have a DeepCopy value of its value in b.

func (ComputeResources) Mul

The Mul function takes a ComputeResources object called "a" and multiplies each value in it with a given "factor". It then stores the result of each computation in a new ComputeResourcesFloat object, where each key in "a" maps to its corresponding value converted to a float64 type and multiplied by "factor"

func (ComputeResources) MulByResource

func (a ComputeResources) MulByResource(factors map[string]float64) ComputeResourcesFloat

MulByResource function takes a ComputeResources object called "a" and a map of factors, where each key in the factors map corresponds to a key in "a". It multiplies each value in "a" by its corresponding factor from the map, or by 1 if the factor does not exist in the map. The computed values are stored in a new ComputeResourcesFloat object, which is returned by the function. The purpose of this function is to scale the values in a ComputeResources object by the factors specified in the input map.

func (ComputeResources) String

func (a ComputeResources) String() string

String function handles the string representation of ComputeResources i.e. how the output of the struct is represented when functions like fmt.Print() is called on it.

func (ComputeResources) Sub

The Sub function subtracts the values in "a" from the values in "b". In the case a value exists in "b" but not in "a", the negative of the value is mapped to its key in "a". The Sub function can be visually represented as (a - b).

func (ComputeResources) ToProtoMap added in v0.8.7

func (a ComputeResources) ToProtoMap() map[string]*resource.Quantity

type ComputeResourcesFloat

type ComputeResourcesFloat map[string]float64

ComputeResourcesFloat is float version of compute resource, prefer calculations with quantity where possible

func (ComputeResourcesFloat) Add

func (ComputeResourcesFloat) DeepCopy

func (ComputeResourcesFloat) IsLessThan

IsLessThan function checks if any value a contains any negative value after carrying out a subtraction operation of a - b using the "Sub" method. If there are any negative value in "a" after this operation, then "a" is less than "b", a boolean value, "true" is returned, otherwise the boolean value, "false" is returned.

func (ComputeResourcesFloat) IsValid

func (a ComputeResourcesFloat) IsValid() bool

IsValid function checks if all the values in "a" is greater than or equal to zero. It returns true if all values are valid i.e. all values are greater than or equal to zero, and false if any of the values are negative

func (ComputeResourcesFloat) LimitToZero

func (a ComputeResourcesFloat) LimitToZero()

LimitToZero function limits each value in "a" to a minimum value of zero. In the case any value in "a" has a value less than zero, it is replaced with a value of zero.

func (ComputeResourcesFloat) LimitWith

LimitWith function limits the values of "a" to the corresponding values in the limit object. It creates a new ComputeResourcesFloat object with the same keys as the original "a" object, but with values limited by the corresponding values in the limit object using the math.Min() function. If any value in the "a" map is greater than its corresponding value in the limit map, then that value in "a" is replaced with the corresponding value from the limit map. This means that the limit map acts as a maximum limit on the values in the "a" map.

func (ComputeResourcesFloat) Max

The Max function maps every key in "a" with its maximum when compared with its value and its corresponding value in "b".

func (ComputeResourcesFloat) MergeWith

MergeWith represents the merged in values take precedence and override existing values for the same key

func (ComputeResourcesFloat) Mul

The Mul function takes a ComputeResources object called "a" and multiplies each value in it with a given "factor". It then stores the result of each computation in a new ComputeResourcesFloat object, where each key in "a" maps to its corresponding value multiplied by "factor"

func (ComputeResourcesFloat) Sub

The Sub function subtracts the values in "a" from the values in "b". In the case a value exists in "b" but not in "a", the negative of the value is mapped to its key in "a". The Sub function can be visually represented as (a - b).

Jump to

Keyboard shortcuts

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