Documentation ¶
Index ¶
- func QuantityAsFloat64(q resource.Quantity) float64
- type ComputeResources
- func CalculateTotalResource(nodes []*v1.Node) ComputeResources
- func CalculateTotalResourceRequest(pods []*v1.Pod) ComputeResources
- func FromResourceList(list v1.ResourceList) ComputeResources
- func TotalPodResourceLimit(podSpec *v1.PodSpec) ComputeResources
- func TotalPodResourceRequest(podSpec *v1.PodSpec) ComputeResources
- func (a ComputeResources) Add(b ComputeResources)
- func (a ComputeResources) AsFloat() ComputeResourcesFloat
- func (a ComputeResources) DeepCopy() ComputeResources
- func (a ComputeResources) Dominates(b ComputeResources) bool
- func (a ComputeResources) Equal(b ComputeResources) bool
- func (a ComputeResources) IsValid() bool
- func (a ComputeResources) IsZero() bool
- func (a ComputeResources) LimitToZero()
- func (a ComputeResources) Max(b ComputeResources)
- func (a ComputeResources) Mul(factor float64) ComputeResourcesFloat
- func (a ComputeResources) MulByResource(factors map[string]float64) ComputeResourcesFloat
- func (a ComputeResources) String() string
- func (a ComputeResources) Sub(b ComputeResources)
- type ComputeResourcesFloat
- func (a ComputeResourcesFloat) Add(b ComputeResourcesFloat)
- func (a ComputeResourcesFloat) DeepCopy() ComputeResourcesFloat
- func (a ComputeResourcesFloat) IsLessThan(b ComputeResourcesFloat) bool
- func (a ComputeResourcesFloat) IsValid() bool
- func (a ComputeResourcesFloat) LimitToZero()
- func (a ComputeResourcesFloat) LimitWith(limit ComputeResourcesFloat) ComputeResourcesFloat
- func (a ComputeResourcesFloat) Max(b ComputeResourcesFloat)
- func (a ComputeResourcesFloat) MergeWith(merged ComputeResourcesFloat) ComputeResourcesFloat
- func (a ComputeResourcesFloat) Mul(factor float64) ComputeResourcesFloat
- func (a ComputeResourcesFloat) Sub(b ComputeResourcesFloat)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QuantityAsFloat64 ¶
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 ¶
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 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 TotalPodResourceLimit ¶
func TotalPodResourceLimit(podSpec *v1.PodSpec) ComputeResources
TotalPodResourceLimit function calculates the maximum total resource (cpu, memory, etc.) limits in the pod for each resource by iterating through all containers and initContainers in the pod.
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 (a ComputeResources) Add(b ComputeResources)
func (ComputeResources) AsFloat ¶
func (a ComputeResources) AsFloat() ComputeResourcesFloat
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 ¶
func (a ComputeResources) Equal(b ComputeResources) bool
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 ¶
func (a ComputeResources) Max(b ComputeResources)
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 ¶
func (a ComputeResources) Mul(factor float64) ComputeResourcesFloat
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 ¶
func (a ComputeResources) Sub(b ComputeResources)
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).
type ComputeResourcesFloat ¶
ComputeResourcesFloat is float version of compute resource, prefer calculations with quantity where possible
func (ComputeResourcesFloat) Add ¶
func (a ComputeResourcesFloat) Add(b ComputeResourcesFloat)
func (ComputeResourcesFloat) DeepCopy ¶
func (a ComputeResourcesFloat) DeepCopy() ComputeResourcesFloat
func (ComputeResourcesFloat) IsLessThan ¶
func (a ComputeResourcesFloat) IsLessThan(b ComputeResourcesFloat) bool
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 ¶
func (a ComputeResourcesFloat) LimitWith(limit ComputeResourcesFloat) ComputeResourcesFloat
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 ¶
func (a ComputeResourcesFloat) Max(b ComputeResourcesFloat)
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 ¶
func (a ComputeResourcesFloat) MergeWith(merged ComputeResourcesFloat) ComputeResourcesFloat
MergeWith represents the merged in values take precedence and override existing values for the same key
func (ComputeResourcesFloat) Mul ¶
func (a ComputeResourcesFloat) Mul(factor float64) ComputeResourcesFloat
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 ¶
func (a ComputeResourcesFloat) Sub(b ComputeResourcesFloat)
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).