model

package
v0.0.0-...-7600a38 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResourcesAsResourceList

func ResourcesAsResourceList(resources Resources) apiv1.ResourceList

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

func (*AggregateContainerState) AddSample

func (a *AggregateContainerState) AddSample(sample *ContainerUsageSample)

func (*AggregateContainerState) GetControlledResources

func (a *AggregateContainerState) GetControlledResources() []ResourceName

func (*AggregateContainerState) GetLastRecommendation

func (a *AggregateContainerState) GetLastRecommendation() corev1.ResourceList

func (*AggregateContainerState) GetScalingMode

func (*AggregateContainerState) GetUpdateMode

func (a *AggregateContainerState) GetUpdateMode() *vpa_types.UpdateMode

func (*AggregateContainerState) LoadFromCheckpoint

func (*AggregateContainerState) MarkNotAutoscaled

func (a *AggregateContainerState) MarkNotAutoscaled()

func (*AggregateContainerState) MergeContainerState

func (a *AggregateContainerState) MergeContainerState(other *AggregateContainerState)

func (*AggregateContainerState) NeedsRecommendation

func (a *AggregateContainerState) NeedsRecommendation() bool

func (*AggregateContainerState) SaveToCheckpoint

func (*AggregateContainerState) SubtractSample

func (a *AggregateContainerState) SubtractSample(sample *ContainerUsageSample)

func (*AggregateContainerState) UpdateFromPolicy

func (a *AggregateContainerState) UpdateFromPolicy(resourcePolicy *vpa_types.ContainerResourcePolicy)

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 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

func (*ClusterState) AddOrUpdateContainer

func (cluster *ClusterState) AddOrUpdateContainer(containerID ContainerID, request Resources) error

func (*ClusterState) AddOrUpdatePod

func (cluster *ClusterState) AddOrUpdatePod(podID PodID, newLabels labels.Set, phase apiv1.PodPhase)

func (*ClusterState) AddOrUpdateVpa

func (cluster *ClusterState) AddOrUpdateVpa(apiObject *vpa_types.VerticalPodAutoscaler, selector labels.Selector) error

func (*ClusterState) AddSample

func (cluster *ClusterState) AddSample(sample *ContainerUsageSampleWithKey) error

func (*ClusterState) DeletePod

func (cluster *ClusterState) DeletePod(podID PodID)

func (*ClusterState) DeleteVpa

func (cluster *ClusterState) DeleteVpa(vpaID VpaID) error

func (*ClusterState) GetContainer

func (cluster *ClusterState) GetContainer(containerID ContainerID) *ContainerState

func (*ClusterState) GetControllerForPodUnderVPA

func (cluster *ClusterState) GetControllerForPodUnderVPA(pod *PodState, controllerFetcher controllerfetcher.ControllerFetcher) *controllerfetcher.ControllerKeyWithAPIVersion

func (*ClusterState) GetMatchingPods

func (cluster *ClusterState) GetMatchingPods(vpa *Vpa) []PodID

func (*ClusterState) MakeAggregateStateKey

func (cluster *ClusterState) MakeAggregateStateKey(pod *PodState, containerName string) AggregateStateKey

func (*ClusterState) RateLimitedGarbageCollectAggregateCollectionStates

func (cluster *ClusterState) RateLimitedGarbageCollectAggregateCollectionStates(now time.Time, controllerFetcher controllerfetcher.ControllerFetcher)

func (*ClusterState) RecordOOM

func (cluster *ClusterState) RecordOOM(containerID ContainerID, timestamp time.Time, requestedMemory ResourceAmount) error

func (*ClusterState) RecordRecommendation

func (cluster *ClusterState) RecordRecommendation(vpa *Vpa, now time.Time) error

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

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

func (*ContainerState) AddSample

func (container *ContainerState) AddSample(sample *ContainerUsageSample) bool

func (*ContainerState) GetMaxMemoryPeak

func (container *ContainerState) GetMaxMemoryPeak() ResourceAmount

func (*ContainerState) RecordOOM

func (container *ContainerState) RecordOOM(timestamp time.Time, requestedMemory ResourceAmount) error

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.

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.

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 measurment.
	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 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.

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
	// IsV1Beta1API is set to true if VPA object has labelSelector defined as in v1beta1 api.
	IsV1Beta1API bool
	// 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

func NewVpa(id VpaID, selector labels.Selector, created time.Time) *Vpa

func (*Vpa) AggregateStateByContainerName

func (vpa *Vpa) AggregateStateByContainerName() ContainerNameToAggregateStateMap

func (*Vpa) AsStatus

func (vpa *Vpa) AsStatus() *vpa_types.VerticalPodAutoscalerStatus

func (*Vpa) DeleteAggregation

func (vpa *Vpa) DeleteAggregation(aggregationKey AggregateStateKey)

func (*Vpa) HasMatchedPods

func (vpa *Vpa) HasMatchedPods() bool

func (*Vpa) HasRecommendation

func (vpa *Vpa) HasRecommendation() bool

func (*Vpa) MergeCheckpointedState

func (vpa *Vpa) MergeCheckpointedState(aggregateContainerStateMap ContainerNameToAggregateStateMap)

func (*Vpa) SetResourcePolicy

func (vpa *Vpa) SetResourcePolicy(resourcePolicy *vpa_types.PodResourcePolicy)

func (*Vpa) SetUpdateMode

func (vpa *Vpa) SetUpdateMode(updatePolicy *vpa_types.PodUpdatePolicy)

func (*Vpa) UpdateConditions

func (vpa *Vpa) UpdateConditions(podsMatched bool)

func (*Vpa) UpdateRecommendation

func (vpa *Vpa) UpdateRecommendation(recommendation *vpa_types.RecommendedPodResources)

func (*Vpa) UseAggregationIfMatching

func (vpa *Vpa) UseAggregationIfMatching(aggregationKey AggregateStateKey, aggregation *AggregateContainerState)

func (*Vpa) UsesAggregation

func (vpa *Vpa) UsesAggregation(aggregationKey AggregateStateKey) bool

type VpaID

type VpaID struct {
	Namespace string
	VpaName   string
}

VpaID contains information needed to identify a VPA API object within a cluster.

Jump to

Keyboard shortcuts

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