Documentation ¶
Index ¶
- Constants
- Variables
- func BytesFromMemoryAmount(memoryAmount ResourceAmount) float64
- func CoresFromCPUAmount(cpuAmount ResourceAmount) float64
- func InitializeAggregationsConfig(config *AggregationsConfig)
- func QuantityFromCPUAmount(cpuAmount ResourceAmount) resource.Quantity
- func QuantityFromMemoryAmount(memoryAmount ResourceAmount) resource.Quantity
- func ResourceNamesApiToModel(resources []apiv1.ResourceName) *[]ResourceName
- func ResourcesAsResourceList(resources Resources) apiv1.ResourceList
- type AggregateContainerState
- func (a *AggregateContainerState) AddSample(sample *ContainerUsageSample)
- func (a *AggregateContainerState) GetControlledResources() []ResourceName
- func (a *AggregateContainerState) GetLastRecommendation() corev1.ResourceList
- func (a *AggregateContainerState) GetScalingMode() *vpa_types.ContainerScalingMode
- func (a *AggregateContainerState) GetUpdateMode() *vpa_types.UpdateMode
- func (a *AggregateContainerState) LoadFromCheckpoint(checkpoint *vpa_types.VerticalPodAutoscalerCheckpointStatus) error
- func (a *AggregateContainerState) MarkNotAutoscaled()
- func (a *AggregateContainerState) MergeContainerState(other *AggregateContainerState)
- func (a *AggregateContainerState) NeedsRecommendation() bool
- func (a *AggregateContainerState) SaveToCheckpoint() (*vpa_types.VerticalPodAutoscalerCheckpointStatus, error)
- func (a *AggregateContainerState) SubtractSample(sample *ContainerUsageSample)
- func (a *AggregateContainerState) UpdateFromPolicy(resourcePolicy *vpa_types.ContainerResourcePolicy)
- type AggregateStateKey
- type AggregationsConfig
- type ClusterState
- func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID, request Resources) error
- func (cluster *ClusterState) AddOrUpdatePod(podID PodID, newLabels labels.Set, phase apiv1.PodPhase)
- func (cluster *ClusterState) AddOrUpdateVpa(apiObject *vpa_types.VerticalPodAutoscaler, selector labels.Selector) error
- func (cluster *ClusterState) AddSample(sample *ContainerUsageSampleWithKey) error
- func (cluster *ClusterState) DeletePod(podID PodID)
- func (cluster *ClusterState) DeleteVpa(vpaID VpaID) error
- func (cluster *ClusterState) GetContainer(containerID ContainerID) *ContainerState
- func (cluster *ClusterState) GetControllerForPodUnderVPA(pod *PodState, controllerFetcher controllerfetcher.ControllerFetcher) *controllerfetcher.ControllerKeyWithAPIVersion
- func (cluster *ClusterState) GetControllingVPA(pod *PodState) *Vpa
- func (cluster *ClusterState) GetMatchingPods(vpa *Vpa) []PodID
- func (cluster *ClusterState) MakeAggregateStateKey(pod *PodState, containerName string) AggregateStateKey
- func (cluster *ClusterState) RateLimitedGarbageCollectAggregateCollectionStates(now time.Time, controllerFetcher controllerfetcher.ControllerFetcher)
- func (cluster *ClusterState) RecordOOM(containerID ContainerID, timestamp time.Time, requestedMemory ResourceAmount) error
- func (cluster *ClusterState) RecordRecommendation(vpa *Vpa, now time.Time) error
- func (cluster *ClusterState) StateMapSize() int
- type ContainerID
- type ContainerNameToAggregateStateMap
- type ContainerState
- type ContainerStateAggregator
- type ContainerStateAggregatorProxy
- func (p *ContainerStateAggregatorProxy) AddSample(sample *ContainerUsageSample)
- func (p *ContainerStateAggregatorProxy) GetLastRecommendation() corev1.ResourceList
- func (p *ContainerStateAggregatorProxy) GetScalingMode() *vpa_types.ContainerScalingMode
- func (p *ContainerStateAggregatorProxy) GetUpdateMode() *vpa_types.UpdateMode
- func (p *ContainerStateAggregatorProxy) NeedsRecommendation() bool
- func (p *ContainerStateAggregatorProxy) SubtractSample(sample *ContainerUsageSample)
- type ContainerUsageSample
- type ContainerUsageSampleWithKey
- type KeyError
- type PodID
- type PodState
- type ResourceAmount
- func CPUAmountFromCores(cores float64) ResourceAmount
- func MemoryAmountFromBytes(bytes float64) ResourceAmount
- func ResourceAmountMax(amount1, amount2 ResourceAmount) ResourceAmount
- func RoundResourceAmount(amount, unit ResourceAmount) ResourceAmount
- func ScaleResource(amount ResourceAmount, factor float64) ResourceAmount
- type ResourceName
- type Resources
- type Vpa
- func (vpa *Vpa) AggregateStateByContainerName() ContainerNameToAggregateStateMap
- func (vpa *Vpa) AsStatus() *vpa_types.VerticalPodAutoscalerStatus
- func (vpa *Vpa) DeleteAggregation(aggregationKey AggregateStateKey)
- func (vpa *Vpa) HasMatchedPods() bool
- func (vpa *Vpa) HasRecommendation() bool
- func (vpa *Vpa) MergeCheckpointedState(aggregateContainerStateMap ContainerNameToAggregateStateMap)
- func (vpa *Vpa) SetAPIVersion(to string)
- func (vpa *Vpa) SetResourcePolicy(resourcePolicy *vpa_types.PodResourcePolicy)
- func (vpa *Vpa) SetUpdateMode(updatePolicy *vpa_types.PodUpdatePolicy)
- func (vpa *Vpa) UpdateConditions(podsMatched bool)
- func (vpa *Vpa) UpdateRecommendation(recommendation *vpa_types.RecommendedPodResources)
- func (vpa *Vpa) UseAggregationIfMatching(aggregationKey AggregateStateKey, aggregation *AggregateContainerState)
- func (vpa *Vpa) UsesAggregation(aggregationKey AggregateStateKey) bool
- type VpaID
Constants ¶
const ( // DefaultMemoryAggregationIntervalCount is the default value for MemoryAggregationIntervalCount. DefaultMemoryAggregationIntervalCount = 8 // DefaultMemoryAggregationInterval is the default value for MemoryAggregationInterval. // which the peak memory usage is computed. DefaultMemoryAggregationInterval = time.Hour * 24 // DefaultHistogramBucketSizeGrowth is the default value for HistogramBucketSizeGrowth. DefaultHistogramBucketSizeGrowth = 0.05 // Make each bucket 5% larger than the previous one. // DefaultMemoryHistogramDecayHalfLife is the default value for MemoryHistogramDecayHalfLife. DefaultMemoryHistogramDecayHalfLife = time.Hour * 24 // DefaultCPUHistogramDecayHalfLife is the default value for CPUHistogramDecayHalfLife. // CPU usage sample to lose half of its weight. DefaultCPUHistogramDecayHalfLife = time.Hour * 24 // DefaultOOMBumpUpRatio is the default value for OOMBumpUpRatio. DefaultOOMBumpUpRatio float64 = 1.2 // Memory is increased by 20% after an OOMKill. // DefaultOOMMinBumpUp is the default value for OOMMinBumpUp. DefaultOOMMinBumpUp float64 = 100 * 1024 * 1024 // Memory is increased by at least 100MB after an OOMKill. )
const ( // RecommendationMissingMaxDuration is maximum time that we accept the recommendation can be missing. RecommendationMissingMaxDuration = 30 * time.Minute )
const ( // SupportedCheckpointVersion is the tag of the supported version of serialized checkpoints. // Version id should be incremented on every non incompatible change, i.e. if the new // version of the recommender binary can't initialize from the old checkpoint format or the // previous version of the recommender binary can't initialize from the new checkpoint format. SupportedCheckpointVersion = "v3" )
Variables ¶
var ( // DefaultControlledResources is a default value of Spec.ResourcePolicy.ContainerPolicies[].ControlledResources. DefaultControlledResources = []ResourceName{ResourceCPU, ResourceMemory} )
Functions ¶
func BytesFromMemoryAmount ¶
func BytesFromMemoryAmount(memoryAmount ResourceAmount) float64
BytesFromMemoryAmount converts ResourceAmount to number of bytes expressed as float64.
func CoresFromCPUAmount ¶
func CoresFromCPUAmount(cpuAmount ResourceAmount) float64
CoresFromCPUAmount converts ResourceAmount to number of cores expressed as float64.
func InitializeAggregationsConfig ¶
func InitializeAggregationsConfig(config *AggregationsConfig)
InitializeAggregationsConfig initializes the global aggregations configuration. Not thread-safe.
func QuantityFromCPUAmount ¶
func QuantityFromCPUAmount(cpuAmount ResourceAmount) resource.Quantity
QuantityFromCPUAmount converts CPU ResourceAmount to a resource.Quantity.
func QuantityFromMemoryAmount ¶
func QuantityFromMemoryAmount(memoryAmount ResourceAmount) resource.Quantity
QuantityFromMemoryAmount converts memory ResourceAmount to a resource.Quantity.
func ResourceNamesApiToModel ¶
func ResourceNamesApiToModel(resources []apiv1.ResourceName) *[]ResourceName
ResourceNamesApiToModel converts an array of resource names expressed in API types into model types.
func ResourcesAsResourceList ¶
func ResourcesAsResourceList(resources Resources) apiv1.ResourceList
ResourcesAsResourceList converts internal Resources representation to ResourcesList.
Types ¶
type AggregateContainerState ¶
type AggregateContainerState struct { // AggregateCPUUsage is a distribution of all CPU samples. AggregateCPUUsage util.Histogram // AggregateMemoryPeaks is a distribution of memory peaks from all containers: // each container should add one peak per memory aggregation interval (e.g. once every 24h). AggregateMemoryPeaks util.Histogram // Note: first/last sample timestamps as well as the sample count are based only on CPU samples. FirstSampleStart time.Time LastSampleStart time.Time TotalSamplesCount int CreationTime time.Time // Following fields are needed to correctly report quality metrics // for VPA. When we record a new sample in an AggregateContainerState // we want to know if it needs recommendation, if the recommendation // is present and if the automatic updates are on (are we able to // apply the recommendation to the pods). LastRecommendation corev1.ResourceList IsUnderVPA bool UpdateMode *vpa_types.UpdateMode ScalingMode *vpa_types.ContainerScalingMode ControlledResources *[]ResourceName }
AggregateContainerState holds input signals aggregated from a set of containers. It can be used as an input to compute the recommendation. The CPU and memory distributions use decaying histograms by default (see NewAggregateContainerState()). Implements ContainerStateAggregator interface.
func NewAggregateContainerState ¶
func NewAggregateContainerState() *AggregateContainerState
NewAggregateContainerState returns a new, empty AggregateContainerState.
func (*AggregateContainerState) AddSample ¶
func (a *AggregateContainerState) AddSample(sample *ContainerUsageSample)
AddSample aggregates a single usage sample.
func (*AggregateContainerState) GetControlledResources ¶
func (a *AggregateContainerState) GetControlledResources() []ResourceName
GetControlledResources returns the list of resources controlled by VPA controlling this aggregator. Returns default if not set.
func (*AggregateContainerState) GetLastRecommendation ¶
func (a *AggregateContainerState) GetLastRecommendation() corev1.ResourceList
GetLastRecommendation returns last recorded recommendation.
func (*AggregateContainerState) GetScalingMode ¶
func (a *AggregateContainerState) GetScalingMode() *vpa_types.ContainerScalingMode
GetScalingMode returns the container scaling mode of the container represented byt his aggregator, nil if aggregator is not autoscaled.
func (*AggregateContainerState) GetUpdateMode ¶
func (a *AggregateContainerState) GetUpdateMode() *vpa_types.UpdateMode
GetUpdateMode returns the update mode of VPA controlling this aggregator, nil if aggregator is not autoscaled.
func (*AggregateContainerState) LoadFromCheckpoint ¶
func (a *AggregateContainerState) LoadFromCheckpoint(checkpoint *vpa_types.VerticalPodAutoscalerCheckpointStatus) error
LoadFromCheckpoint deserializes data from VerticalPodAutoscalerCheckpointStatus into the AggregateContainerState.
func (*AggregateContainerState) MarkNotAutoscaled ¶
func (a *AggregateContainerState) MarkNotAutoscaled()
MarkNotAutoscaled registers that this container state is not controlled by a VPA object.
func (*AggregateContainerState) MergeContainerState ¶
func (a *AggregateContainerState) MergeContainerState(other *AggregateContainerState)
MergeContainerState merges two AggregateContainerStates.
func (*AggregateContainerState) NeedsRecommendation ¶
func (a *AggregateContainerState) NeedsRecommendation() bool
NeedsRecommendation returns true if the state should have recommendation calculated.
func (*AggregateContainerState) SaveToCheckpoint ¶
func (a *AggregateContainerState) SaveToCheckpoint() (*vpa_types.VerticalPodAutoscalerCheckpointStatus, error)
SaveToCheckpoint serializes AggregateContainerState as VerticalPodAutoscalerCheckpointStatus. The serialization may result in loss of precission of the histograms.
func (*AggregateContainerState) SubtractSample ¶
func (a *AggregateContainerState) SubtractSample(sample *ContainerUsageSample)
SubtractSample removes a single usage sample from an aggregation. The subtracted sample should be equal to some sample that was aggregated with AddSample() in the past. Only memory samples can be subtracted at the moment. Support for CPU could be added if necessary.
func (*AggregateContainerState) UpdateFromPolicy ¶
func (a *AggregateContainerState) UpdateFromPolicy(resourcePolicy *vpa_types.ContainerResourcePolicy)
UpdateFromPolicy updates container state scaling mode and controlled resources based on resource policy of the VPA object.
type AggregateStateKey ¶
type AggregateStateKey interface { Namespace() string ContainerName() string Labels() labels.Labels }
AggregateStateKey determines the set of containers for which the usage samples are kept aggregated in the model.
type AggregationsConfig ¶
type AggregationsConfig struct { // MemoryAggregationInterval is the length of a single interval, for // which the peak memory usage is computed. // Memory usage peaks are aggregated in multiples of this interval. In other words // there is one memory usage sample per interval (the maximum usage over that // interval). MemoryAggregationInterval time.Duration // MemoryAggregationWindowIntervalCount is the number of consecutive MemoryAggregationIntervals // which make up the MemoryAggregationWindowLength which in turn is the period for memory // usage aggregation by VPA. MemoryAggregationIntervalCount int64 // CPUHistogramOptions are options to be used by histograms that store // CPU measures expressed in cores. CPUHistogramOptions util.HistogramOptions // MemoryHistogramOptions are options to be used by histograms that // store memory measures expressed in bytes. MemoryHistogramOptions util.HistogramOptions // HistogramBucketSizeGrowth defines the growth rate of the histogram buckets. // Each bucket is wider than the previous one by this fraction. HistogramBucketSizeGrowth float64 // MemoryHistogramDecayHalfLife is the amount of time it takes a historical // memory usage sample to lose half of its weight. In other words, a fresh // usage sample is twice as 'important' as one with age equal to the half // life period. MemoryHistogramDecayHalfLife time.Duration // CPUHistogramDecayHalfLife is the amount of time it takes a historical // CPU usage sample to lose half of its weight. CPUHistogramDecayHalfLife time.Duration // OOMBumpUpRatio specifies the memory bump up ratio when OOM occurred. OOMBumpUpRatio float64 // OOMMinBumpUp specifies the minimal increase of memory when OOM occurred in bytes. OOMMinBumpUp float64 }
AggregationsConfig is used to configure aggregation behaviour.
func GetAggregationsConfig ¶
func GetAggregationsConfig() *AggregationsConfig
GetAggregationsConfig gets the aggregations config. Initializes to default values if not initialized already.
func NewAggregationsConfig ¶
func NewAggregationsConfig(memoryAggregationInterval time.Duration, memoryAggregationIntervalCount int64, memoryHistogramDecayHalfLife, cpuHistogramDecayHalfLife time.Duration, oomBumpUpRatio float64, oomMinBumpUp float64) *AggregationsConfig
NewAggregationsConfig creates a new AggregationsConfig based on the supplied parameters and default values.
func (*AggregationsConfig) GetMemoryAggregationWindowLength ¶
func (a *AggregationsConfig) GetMemoryAggregationWindowLength() time.Duration
GetMemoryAggregationWindowLength returns the total length of the memory usage history aggregated by VPA.
type ClusterState ¶
type ClusterState struct { // Pods in the cluster. Pods map[PodID]*PodState // VPA objects in the cluster. Vpas map[VpaID]*Vpa // VPA objects in the cluster that have no recommendation mapped to the first // time we've noticed the recommendation missing or last time we logged // a warning about it. EmptyVPAs map[VpaID]time.Time // Observed VPAs. Used to check if there are updates needed. ObservedVpas []*vpa_types.VerticalPodAutoscaler // contains filtered or unexported fields }
ClusterState holds all runtime information about the cluster required for the VPA operations, i.e. configuration of resources (pods, containers, VPA objects), aggregated utilization of compute resources (CPU, memory) and events (container OOMs). All input to the VPA Recommender algorithm lives in this structure.
func NewClusterState ¶
func NewClusterState(gcInterval time.Duration) *ClusterState
NewClusterState returns a new ClusterState with no pods.
func (*ClusterState) AddOrUpdateContainer ¶
func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID, request Resources) error
AddOrUpdateContainer creates a new container with the given ContainerID and adds it to the parent pod in the ClusterState object, if not yet present. Requires the pod to be added to the ClusterState first. Otherwise an error is returned.
func (*ClusterState) AddOrUpdatePod ¶
func (cluster *ClusterState) AddOrUpdatePod(podID PodID, newLabels labels.Set, phase apiv1.PodPhase)
AddOrUpdatePod updates the state of the pod with a given PodID, if it is present in the cluster object. Otherwise a new pod is created and added to the Cluster object. If the labels of the pod have changed, it updates the links between the containers and the aggregations.
func (*ClusterState) AddOrUpdateVpa ¶
func (cluster *ClusterState) AddOrUpdateVpa(apiObject *vpa_types.VerticalPodAutoscaler, selector labels.Selector) error
AddOrUpdateVpa adds a new VPA with a given ID to the ClusterState if it didn't yet exist. If the VPA already existed but had a different pod selector, the pod selector is updated. Updates the links between the VPA and all aggregations it matches.
func (*ClusterState) AddSample ¶
func (cluster *ClusterState) AddSample(sample *ContainerUsageSampleWithKey) error
AddSample adds a new usage sample to the proper container in the ClusterState object. Requires the container as well as the parent pod to be added to the ClusterState first. Otherwise an error is returned.
func (*ClusterState) DeletePod ¶
func (cluster *ClusterState) DeletePod(podID PodID)
DeletePod removes an existing pod from the cluster.
func (*ClusterState) DeleteVpa ¶
func (cluster *ClusterState) DeleteVpa(vpaID VpaID) error
DeleteVpa removes a VPA with the given ID from the ClusterState.
func (*ClusterState) GetContainer ¶
func (cluster *ClusterState) GetContainer(containerID ContainerID) *ContainerState
GetContainer returns the ContainerState object for a given ContainerID or null if it's not present in the model.
func (*ClusterState) GetControllerForPodUnderVPA ¶ added in v0.10.0
func (cluster *ClusterState) GetControllerForPodUnderVPA(pod *PodState, controllerFetcher controllerfetcher.ControllerFetcher) *controllerfetcher.ControllerKeyWithAPIVersion
GetControllerForPodUnderVPA returns controller associated with given Pod. Returns nil if Pod is not controlled by a VPA object.
func (*ClusterState) GetControllingVPA ¶ added in v0.10.0
func (cluster *ClusterState) GetControllingVPA(pod *PodState) *Vpa
GetControllingVPA returns a VPA object controlling given Pod.
func (*ClusterState) GetMatchingPods ¶
func (cluster *ClusterState) GetMatchingPods(vpa *Vpa) []PodID
GetMatchingPods returns a list of currently active pods that match the given VPA. Traverses through all pods in the cluster - use sparingly.
func (*ClusterState) MakeAggregateStateKey ¶
func (cluster *ClusterState) MakeAggregateStateKey(pod *PodState, containerName string) AggregateStateKey
MakeAggregateStateKey returns the AggregateStateKey that should be used to aggregate usage samples from a container with the given name in a given pod.
func (*ClusterState) RateLimitedGarbageCollectAggregateCollectionStates ¶ added in v0.10.0
func (cluster *ClusterState) RateLimitedGarbageCollectAggregateCollectionStates(now time.Time, controllerFetcher controllerfetcher.ControllerFetcher)
RateLimitedGarbageCollectAggregateCollectionStates removes obsolete AggregateCollectionStates from the ClusterState. It performs clean up only if more than `gcInterval` passed since the last time it performed a cleanup. AggregateCollectionState is obsolete in following situations: 1) It has no samples and there are no more contributive pods - a pod is contributive in any of following situations:
a) It is in an active state - i.e. not PodSucceeded nor PodFailed. b) Its associated controller (e.g. Deployment) still exists.
2) The last sample is too old to give meaningful recommendation (>8 days), 3) There are no samples and the aggregate state was created >8 days ago.
func (*ClusterState) RecordOOM ¶
func (cluster *ClusterState) RecordOOM(containerID ContainerID, timestamp time.Time, requestedMemory ResourceAmount) error
RecordOOM adds info regarding OOM event in the model as an artificial memory sample.
func (*ClusterState) RecordRecommendation ¶
func (cluster *ClusterState) RecordRecommendation(vpa *Vpa, now time.Time) error
RecordRecommendation marks the state of recommendation in the cluster. We keep track of empty recommendations and log information about them periodically.
func (*ClusterState) StateMapSize ¶
func (cluster *ClusterState) StateMapSize() int
StateMapSize is the number of pods being tracked by the VPA
type ContainerID ¶
type ContainerID struct { PodID // ContainerName is the name of the container, unique within a pod. ContainerName string }
ContainerID contains information needed to identify a Container within a cluster.
type ContainerNameToAggregateStateMap ¶
type ContainerNameToAggregateStateMap map[string]*AggregateContainerState
ContainerNameToAggregateStateMap maps a container name to AggregateContainerState that aggregates state of containers with that name.
func AggregateStateByContainerName ¶
func AggregateStateByContainerName(aggregateContainerStateMap aggregateContainerStatesMap) ContainerNameToAggregateStateMap
AggregateStateByContainerName takes a set of AggregateContainerStates and merge them grouping by the container name. The result is a map from the container name to the aggregation from all input containers with the given name.
type ContainerState ¶
type ContainerState struct { // Current request. Request Resources // Start of the latest CPU usage sample that was aggregated. LastCPUSampleStart time.Time // End time of the current memory aggregation interval (not inclusive). WindowEnd time.Time // contains filtered or unexported fields }
ContainerState stores information about a single container instance. Each ContainerState has a pointer to the aggregation that is used for aggregating its usage samples. It holds the recent history of CPU and memory utilization.
Note: samples are added to intervals based on their start timestamps.
func NewContainerState ¶
func NewContainerState(request Resources, aggregator ContainerStateAggregator) *ContainerState
NewContainerState returns a new ContainerState.
func (*ContainerState) AddSample ¶
func (container *ContainerState) AddSample(sample *ContainerUsageSample) bool
AddSample adds a usage sample to the given ContainerState. Requires samples for a single resource to be passed in chronological order (i.e. in order of growing MeasureStart). Invalid samples (out of order or measure out of legal range) are discarded. Returns true if the sample was aggregated, false if it was discarded. Note: usage samples don't hold their end timestamp / duration. They are implicitly assumed to be disjoint when aggregating.
func (*ContainerState) GetMaxMemoryPeak ¶
func (container *ContainerState) GetMaxMemoryPeak() ResourceAmount
GetMaxMemoryPeak returns maximum memory usage in the sample, possibly estimated from OOM
func (*ContainerState) RecordOOM ¶
func (container *ContainerState) RecordOOM(timestamp time.Time, requestedMemory ResourceAmount) error
RecordOOM adds info regarding OOM event in the model as an artificial memory sample.
type ContainerStateAggregator ¶
type ContainerStateAggregator interface { // AddSample aggregates a single usage sample. AddSample(sample *ContainerUsageSample) // SubtractSample removes a single usage sample. The subtracted sample // should be equal to some sample that was aggregated with AddSample() // in the past. SubtractSample(sample *ContainerUsageSample) // GetLastRecommendation returns last recommendation calculated for this // aggregator. GetLastRecommendation() corev1.ResourceList // NeedsRecommendation returns true if this aggregator should have // a recommendation calculated. NeedsRecommendation() bool // GetUpdateMode returns the update mode of VPA controlling this aggregator, // nil if aggregator is not autoscaled. GetUpdateMode() *vpa_types.UpdateMode }
ContainerStateAggregator is an interface for objects that consume and aggregate container usage samples.
func NewContainerStateAggregatorProxy ¶
func NewContainerStateAggregatorProxy(cluster *ClusterState, containerID ContainerID) ContainerStateAggregator
NewContainerStateAggregatorProxy creates a ContainerStateAggregatorProxy pointing to the cluster state.
type ContainerStateAggregatorProxy ¶
type ContainerStateAggregatorProxy struct {
// contains filtered or unexported fields
}
ContainerStateAggregatorProxy is a wrapper for ContainerStateAggregator that creates ContainerStateAgregator for container if it is no longer present in the cluster state.
func (*ContainerStateAggregatorProxy) AddSample ¶
func (p *ContainerStateAggregatorProxy) AddSample(sample *ContainerUsageSample)
AddSample adds a container sample to the aggregator.
func (*ContainerStateAggregatorProxy) GetLastRecommendation ¶
func (p *ContainerStateAggregatorProxy) GetLastRecommendation() corev1.ResourceList
GetLastRecommendation returns last recorded recommendation.
func (*ContainerStateAggregatorProxy) GetScalingMode ¶
func (p *ContainerStateAggregatorProxy) GetScalingMode() *vpa_types.ContainerScalingMode
GetScalingMode returns scaling mode of container represented by the aggregator.
func (*ContainerStateAggregatorProxy) GetUpdateMode ¶
func (p *ContainerStateAggregatorProxy) GetUpdateMode() *vpa_types.UpdateMode
GetUpdateMode returns update mode of VPA controlling the aggregator.
func (*ContainerStateAggregatorProxy) NeedsRecommendation ¶
func (p *ContainerStateAggregatorProxy) NeedsRecommendation() bool
NeedsRecommendation returns true if the aggregator should have recommendation calculated.
func (*ContainerStateAggregatorProxy) SubtractSample ¶
func (p *ContainerStateAggregatorProxy) SubtractSample(sample *ContainerUsageSample)
SubtractSample subtracts a container sample from the aggregator.
type ContainerUsageSample ¶
type ContainerUsageSample struct { // Start of the measurement interval. MeasureStart time.Time // Average CPU usage in cores or memory usage in bytes. Usage ResourceAmount // CPU or memory request at the time of measurement. Request ResourceAmount // Which resource is this sample for. Resource ResourceName }
ContainerUsageSample is a measure of resource usage of a container over some interval.
type ContainerUsageSampleWithKey ¶
type ContainerUsageSampleWithKey struct { ContainerUsageSample Container ContainerID }
ContainerUsageSampleWithKey holds a ContainerUsageSample together with the ID of the container it belongs to.
type KeyError ¶
type KeyError struct {
// contains filtered or unexported fields
}
KeyError is returned when the mapping key was not found.
type PodID ¶
type PodID struct { // Namespaces where the Pod is defined. Namespace string // PodName is the name of the pod unique within a namespace. PodName string }
PodID contains information needed to identify a Pod within a cluster.
type PodState ¶
type PodState struct { // Unique id of the Pod. ID PodID // Containers that belong to the Pod, keyed by the container name. Containers map[string]*ContainerState // PodPhase describing current life cycle phase of the Pod. Phase apiv1.PodPhase // contains filtered or unexported fields }
PodState holds runtime information about a single Pod.
type ResourceAmount ¶
type ResourceAmount int64
ResourceAmount represents quantity of a certain resource within a container. Note this keeps CPU in millicores (which is not a standard unit in APIs) and memory in bytes. Allowed values are in the range from 0 to MaxResourceAmount.
func CPUAmountFromCores ¶
func CPUAmountFromCores(cores float64) ResourceAmount
CPUAmountFromCores converts CPU cores to a ResourceAmount.
func MemoryAmountFromBytes ¶
func MemoryAmountFromBytes(bytes float64) ResourceAmount
MemoryAmountFromBytes converts memory bytes to a ResourceAmount.
func ResourceAmountMax ¶
func ResourceAmountMax(amount1, amount2 ResourceAmount) ResourceAmount
ResourceAmountMax returns the larger of two resource amounts.
func RoundResourceAmount ¶
func RoundResourceAmount(amount, unit ResourceAmount) ResourceAmount
RoundResourceAmount returns the given resource amount rounded down to the whole multiple of another resource amount (unit).
func ScaleResource ¶
func ScaleResource(amount ResourceAmount, factor float64) ResourceAmount
ScaleResource returns the resource amount multiplied by a given factor.
type ResourceName ¶
type ResourceName string
ResourceName represents the name of the resource monitored by recommender.
const ( // ResourceCPU represents CPU in millicores (1core = 1000millicores). ResourceCPU ResourceName = "cpu" // ResourceMemory represents memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024). ResourceMemory ResourceName = "memory" // MaxResourceAmount is the maximum allowed value of resource amount. MaxResourceAmount = ResourceAmount(1e14) )
type Resources ¶
type Resources map[ResourceName]ResourceAmount
Resources is a map from resource name to the corresponding ResourceAmount.
type Vpa ¶
type Vpa struct { ID VpaID // Labels selector that determines which Pods are controlled by this VPA // object. Can be nil, in which case no Pod is matched. PodSelector labels.Selector // Map of the object annotations (key-value pairs). Annotations vpaAnnotationsMap // Map of the status conditions (keys are condition types). Conditions vpaConditionsMap // Most recently computed recommendation. Can be nil. Recommendation *vpa_types.RecommendedPodResources // Pod Resource Policy provided in the VPA API object. Can be nil. ResourcePolicy *vpa_types.PodResourcePolicy // Initial checkpoints of AggregateContainerStates for containers. // The key is container name. ContainersInitialAggregateState ContainerNameToAggregateStateMap // UpdateMode describes how recommendations will be applied to pods UpdateMode *vpa_types.UpdateMode // Created denotes timestamp of the original VPA object creation Created time.Time // CheckpointWritten indicates when last checkpoint for the VPA object was stored. CheckpointWritten time.Time // APIVersion of the VPA object. APIVersion string // TargetRef points to the controller managing the set of pods. TargetRef *autoscaling.CrossVersionObjectReference // PodCount contains number of live Pods matching a given VPA object. PodCount int // contains filtered or unexported fields }
Vpa (Vertical Pod Autoscaler) object is responsible for vertical scaling of Pods matching a given label selector.
func NewVpa ¶
NewVpa returns a new Vpa with a given ID and pod selector. Doesn't set the links to the matched aggregations.
func (*Vpa) AggregateStateByContainerName ¶
func (vpa *Vpa) AggregateStateByContainerName() ContainerNameToAggregateStateMap
AggregateStateByContainerName returns a map from container name to the aggregated state of all containers with that name, belonging to pods matched by the VPA.
func (*Vpa) AsStatus ¶
func (vpa *Vpa) AsStatus() *vpa_types.VerticalPodAutoscalerStatus
AsStatus returns this objects equivalent of VPA Status. UpdateConditions should be called first.
func (*Vpa) DeleteAggregation ¶
func (vpa *Vpa) DeleteAggregation(aggregationKey AggregateStateKey)
DeleteAggregation deletes aggregation used by this container
func (*Vpa) HasMatchedPods ¶
HasMatchedPods returns true if there are currently active pods in the cluster matching this VPA, based on conditions. UpdateConditions should be called first.
func (*Vpa) HasRecommendation ¶
HasRecommendation returns if the VPA object contains any recommendation
func (*Vpa) MergeCheckpointedState ¶
func (vpa *Vpa) MergeCheckpointedState(aggregateContainerStateMap ContainerNameToAggregateStateMap)
MergeCheckpointedState adds checkpointed VPA aggregations to the given aggregateStateMap.
func (*Vpa) SetAPIVersion ¶ added in v1.0.0
SetAPIVersion to the version of the VPA API object. Default API Version is the API version of the VPA client. If the provided version is empty, no change is made.
func (*Vpa) SetResourcePolicy ¶
func (vpa *Vpa) SetResourcePolicy(resourcePolicy *vpa_types.PodResourcePolicy)
SetResourcePolicy updates the resource policy of the VPA and the scaling policies of aggregators under this VPA.
func (*Vpa) SetUpdateMode ¶
func (vpa *Vpa) SetUpdateMode(updatePolicy *vpa_types.PodUpdatePolicy)
SetUpdateMode updates the update mode of the VPA and aggregators under this VPA.
func (*Vpa) UpdateConditions ¶
UpdateConditions updates the conditions of VPA objects based on it's state. PodsMatched is passed to indicate if there are currently active pods in the cluster matching this VPA.
func (*Vpa) UpdateRecommendation ¶
func (vpa *Vpa) UpdateRecommendation(recommendation *vpa_types.RecommendedPodResources)
UpdateRecommendation updates the recommended resources in the VPA and its aggregations with the given recommendation.
func (*Vpa) UseAggregationIfMatching ¶
func (vpa *Vpa) UseAggregationIfMatching(aggregationKey AggregateStateKey, aggregation *AggregateContainerState)
UseAggregationIfMatching checks if the given aggregation matches (contributes to) this VPA and adds it to the set of VPA's aggregations if that is the case.
func (*Vpa) UsesAggregation ¶
func (vpa *Vpa) UsesAggregation(aggregationKey AggregateStateKey) bool
UsesAggregation returns true iff an aggregation with the given key contributes to the VPA.