Documentation ¶
Index ¶
- Variables
- type BasicContainerSpec
- type BasicPodSpec
- type ClusterState
- func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID) error
- func (cluster *ClusterState) AddOrUpdatePod(podID PodID, newLabels labels.Set)
- func (cluster *ClusterState) AddOrUpdateVpa(vpaID VpaID, podSelectorStr string) error
- func (cluster *ClusterState) AddSample(sample *ContainerUsageSampleWithKey) error
- func (cluster *ClusterState) DeletePod(podID PodID) error
- func (cluster *ClusterState) DeleteVpa(vpaID VpaID) error
- type ContainerID
- type ContainerMetricsSnapshot
- type ContainerState
- type ContainerUsageSample
- type ContainerUsageSampleWithKey
- type KeyError
- type MetricName
- type PodID
- type PodState
- type ResourceAmount
- type Vpa
- type VpaID
Constants ¶
This section is empty.
Variables ¶
var ( // MemoryAggregationWindowLength is the length of the memory usage history // aggregated by VPA, which is 8 days. MemoryAggregationWindowLength = time.Hour * 8 * 24 // MemoryAggregationInterval is the length of a single interval, for // which the peak memory usage is computed. // Memory usage peaks are aggregated in daily intervals. In other words // there is one memory usage sample per day (the maximum usage over that // day). // Note: AggregationWindowLength must be integrally divisible by this value. MemoryAggregationInterval = time.Hour * 24 )
Functions ¶
This section is empty.
Types ¶
type BasicContainerSpec ¶
type BasicContainerSpec struct { // ID identifies the container within a cluster. ID ContainerID // Name of the image running within the container. Image string // Currently requested resources for this container. Request map[MetricName]ResourceAmount }
BasicContainerSpec contains basic information defining a container.
type BasicPodSpec ¶
type BasicPodSpec struct { // ID identifies a pod within a cluster. ID PodID // Labels of the pod. It is used to match pods with certain VPA opjects. PodLabels map[string]string // List of containers within this pod. Containers []BasicContainerSpec }
BasicPodSpec contains basic information defining a pod and its containers.
type ClusterState ¶
type ClusterState struct { // Pods in the cluster. Pods map[PodID]*PodState // VPA objects in the cluster. Vpas map[VpaID]*Vpa }
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. TODO(kgrygiel): Limit the ClusterState object to a single namespace.
func NewClusterState ¶
func NewClusterState() *ClusterState
NewClusterState returns a new ClusterState with no pods.
func (*ClusterState) AddOrUpdateContainer ¶
func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID) 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)
AddOrUpdatePod udpates 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 pod and the matching Vpa.
func (*ClusterState) AddOrUpdateVpa ¶
func (cluster *ClusterState) AddOrUpdateVpa(vpaID VpaID, podSelectorStr string) 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 pods 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) error
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.
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 ContainerMetricsSnapshot ¶
type ContainerMetricsSnapshot struct { // ID identifies a specific container those metrics are coming from. ID ContainerID // End time of the measurement interval. SnapshotTime time.Time // Duration of the measurement interval, which is [SnapshotTime - SnapshotWindow, SnapshotTime]. SnapshotWindow time.Duration // Actual usage of the resources over the measurement interval. Usage map[MetricName]ResourceAmount }
ContainerMetricsSnapshot contains information about usage of certain container within defined time window.
type ContainerState ¶
type ContainerState struct {
// contains filtered or unexported fields
}
ContainerState stores information about a single container instance. It holds the recent history of CPU and memory utilization.
- CPU is stored in form of a distribution (histogram). Currently we're using fixed weight samples in the CPU histogram (i.e. old and fresh samples are equally important). Old samples are never deleted. TODO: Add exponential decaying of weights over time to address this.
- Memory is stored for the period of length MemoryAggregationWindowLength in the form of usage peaks, one value per MemoryAggregationInterval. For example if window legth is one week and aggregation interval is one day it will store 7 peaks, one per day, for the last week. Note: samples are added to intervals based on their start timestamps.
func NewContainerState ¶
func NewContainerState() *ContainerState
NewContainerState returns a new, empty ContainerState.
func (*ContainerState) AddSample ¶
func (container *ContainerState) AddSample(sample *ContainerUsageSample) bool
AddSample adds a usage sample to the given ContainerState. Requires samples 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.
type ContainerUsageSample ¶
type ContainerUsageSample struct {
// contains filtered or unexported fields
}
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 MetricName ¶
type MetricName string
MetricName represents the name of the resource monitored by recommender.
const ( // ResourceCPU represents CPU in millicores (1core = 1000millicores). ResourceCPU MetricName = "cpu" // ResourceMemory represents memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024). ResourceMemory MetricName = "memory" )
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 // Set of labels attached to the Pod. Labels labels.Set // Containers that belong to the Pod, keyed by the container name. Containers map[string]*ContainerState // VPA managing this pod (can be nil). Vpa *Vpa // All VPA objects that match this Pod. While it is incorrect to let // multiple VPA objects match the same pod, the model has no means to // prevent such situation. In such case the pod is controlled by one of the // matching VPAs. MatchingVpas map[VpaID]*Vpa }
PodState holds runtime information about a single Pod.
type ResourceAmount ¶
type ResourceAmount int
ResourceAmount represents quantity of a certain resource within a container.
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 // Original (string) representation of the PodSelector. PodSelectorStr string // Pods controlled by this VPA object. Pods map[PodID]*PodState }
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 pods.
func (*Vpa) MatchesPod ¶
MatchesPod returns true iff a given pod is matched by the Vpa pod selector.
func (*Vpa) SetPodSelectorStr ¶
SetPodSelectorStr sets the pod selector of the VPA to the given value, passed in the text format (see apimachinery/pkg/labels for the syntax). It returns an error if the string cannot be parsed. Doesn't update the links to the matched pods.
func (*Vpa) UpdatePodLink ¶
UpdatePodLink marks the Pod as controlled or not-controlled by the VPA depending on whether the pod labels match the Vpa pod selector. If multiple VPAs match the same Pod, only one of them will effectively control the Pod.