Skip to content

Commit 1618a98

Browse files
authored
Merge pull request #42 from qmhu/evpa
Effective VPA api
2 parents 6ba7098 + 8e21f07 commit 1618a98

File tree

17 files changed

+1612
-2
lines changed

17 files changed

+1612
-2
lines changed

artifacts/deploy/autoscaling.crane.io_effectiveverticalpodautoscalers.yaml

Lines changed: 473 additions & 0 deletions
Large diffs are not rendered by default.

autoscaling/v1alpha1/types.go renamed to autoscaling/v1alpha1/ehpa_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,4 @@ type SubstituteList struct {
199199

200200
Items []Substitute `json:"items"`
201201
}
202+

autoscaling/v1alpha1/evpa_types.go

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
package v1alpha1
2+
3+
import (
4+
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
5+
v1 "k8s.io/api/core/v1"
6+
"k8s.io/apimachinery/pkg/api/resource"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
vpatypes "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
9+
)
10+
11+
type EffectiveVerticalPodAutoscalerSpec struct {
12+
13+
// TargetRef points to the controller managing the set of pods for the
14+
// autoscaler to control - e.g. Deployment, StatefulSet. VerticalPodAutoscaler
15+
// can be targeted at controller implementing scale subresource (the pod set is
16+
// retrieved from the controller's ScaleStatus) or some well known controllers
17+
// (e.g. for DaemonSet the pod set is read from the controller's spec).
18+
// If VerticalPodAutoscaler cannot use specified target it will report
19+
// ConfigUnsupported condition.
20+
// Note that VerticalPodAutoscaler does not require full implementation
21+
// of scale subresource - it will not use it to modify the replica count.
22+
// The only thing retrieved is a label selector matching pods grouped by
23+
// the target resource.
24+
TargetRef *autoscalingv2.CrossVersionObjectReference `json:"targetRef"`
25+
26+
// Describes the rules on how changes are applied to the pods.
27+
// If not specified, all fields in the `PodUpdatePolicy` are set to their
28+
// default values.
29+
// +optional
30+
UpdatePolicy *vpatypes.PodUpdatePolicy `json:"updatePolicy,omitempty"`
31+
32+
// Controls how the autoscaler computes recommended resources.
33+
// The resource policy may be used to set constraints on the recommendations
34+
// for individual containers. If not specified, the autoscaler computes recommended
35+
// resources for all containers in the pod, without additional constraints.
36+
// +optional
37+
ResourcePolicy *PodResourcePolicy `json:"resourcePolicy,omitempty"`
38+
39+
// ResourceEstimators Contains the specifications for estimators.
40+
// +optional
41+
ResourceEstimators []ResourceEstimator `json:"resourceEstimators,omitempty"`
42+
}
43+
44+
// PodResourcePolicy controls how autoscaler computes the recommended resources
45+
// for containers belonging to the pod. There can be at most one entry for every
46+
// named container and optionally a single wildcard entry with `containerName` = '*',
47+
// which handles all containers that don't have individual policies.
48+
type PodResourcePolicy struct {
49+
// Per-container resource policies.
50+
// +optional
51+
// +patchMergeKey=containerName
52+
// +patchStrategy=merge
53+
ContainerPolicies []ContainerResourcePolicy `json:"containerPolicies,omitempty" patchStrategy:"merge" patchMergeKey:"containerName"`
54+
}
55+
56+
// ContainerResourcePolicy controls how autoscaler computes the recommended
57+
// resources for a specific container.
58+
type ContainerResourcePolicy struct {
59+
// Name of the container or DefaultContainerResourcePolicy, in which
60+
// case the policy is used by the containers that don't have their own
61+
// policy specified.
62+
ContainerName string `json:"containerName,omitempty"`
63+
// ScaleUpPolicy define the policy when scale up containers resources.
64+
// +optional
65+
ScaleUpPolicy *ContainerScalingPolicy `json:"scaleUpPolicy,omitempty"`
66+
// ScaleDownPolicy define the policy when scale down containers resources.
67+
// +optional
68+
ScaleDownPolicy *ContainerScalingPolicy `json:"scaleDownPolicy,omitempty"`
69+
// Specifies the minimal amount of resources that will be recommended
70+
// for the container. The default is no minimum.
71+
// +optional
72+
MinAllowed v1.ResourceList `json:"minAllowed,omitempty"`
73+
// Specifies the maximum amount of resources that will be recommended
74+
// for the container. The default is no maximum.
75+
// +optional
76+
MaxAllowed v1.ResourceList `json:"maxAllowed,omitempty"`
77+
78+
// Specifies the type of recommendations that will be computed
79+
// (and possibly applied) by VPA.
80+
// If not specified, the default of [ResourceCPU, ResourceMemory] will be used.
81+
ControlledResources *[]ResourceName `json:"controlledResources,omitempty" patchStrategy:"merge"`
82+
83+
// Specifies which resource values should be controlled.
84+
// The default is "RequestsAndLimits".
85+
// +optional
86+
ControlledValues *vpatypes.ContainerControlledValues `json:"controlledValues,omitempty"`
87+
}
88+
89+
// ContainerScalingPolicy define effective policy for vertical scaling in certain direction: Up or Down
90+
type ContainerScalingPolicy struct {
91+
// ScaleMode controls Whether autoscaler is enabled for the container.
92+
// The default is "Auto".
93+
// +kubebuilder:validation:Type=string
94+
// +kubebuilder:validation:Enum=Auto;Off
95+
// +kubebuilder:default=Auto
96+
ScaleMode *vpatypes.ContainerScalingMode `json:"mode,omitempty"`
97+
98+
// MetricThresholds defines resource usages thresholds for vertical scaling.
99+
// Only if actual usage is reached to threshold, autoscaling estimator will be triggered.
100+
MetricThresholds *ResourceMetricList `json:"metricThresholds,omitempty"`
101+
102+
// StabilizationWindowSeconds is the number of seconds for which past vertical scaling
103+
// considered while scaling up or scaling down.
104+
// +optional
105+
// +kubebuilder:validation:Type=integer
106+
// +kubebuilder:default=3600
107+
StabilizationWindowSeconds *int32 `json:"stabilizationWindowSeconds,omitempty"`
108+
}
109+
110+
type ResourceName string
111+
112+
type ResourceMetricList map[ResourceName]ResourceMetric
113+
114+
type ResourceMetric struct {
115+
// averageValue is the target value of the average of the
116+
// metric across all relevant pods (as a quantity)
117+
// +optional
118+
AverageValue *resource.Quantity `json:"averageValue,omitempty"`
119+
}
120+
121+
// ResourceEstimator defines the spec for resource estimator
122+
type ResourceEstimator struct {
123+
// Type defines the type for this estimator.
124+
// +optional
125+
Type string `json:"type,omitempty"`
126+
127+
// Priority defines the priority for this estimator.
128+
// +optional
129+
Priority int `json:"priority,omitempty"`
130+
131+
// Config contains key value pairs for this estimator
132+
// for example, we can define configs like:
133+
// key1: value1
134+
// key2: value2
135+
// these configs will pass into estimators when execute scaling
136+
// +optional
137+
Config map[string]string `json:"config,omitempty"`
138+
}
139+
140+
// EffectiveVerticalPodAutoscalerStatus describes the runtime state of the autoscaler.
141+
type EffectiveVerticalPodAutoscalerStatus struct {
142+
// CurrentEstimators is the last state of the estimators used by this autoscaler
143+
CurrentEstimators []ResourceEstimatorStatus `json:"currentEstimators,omitempty"`
144+
145+
// The most recently computed amount of resources recommended by the
146+
// autoscaler for the controlled pods.
147+
// +optional
148+
Recommendation *vpatypes.RecommendedPodResources `json:"recommendation,omitempty"`
149+
150+
// Conditions is the set of conditions required for this autoscaler to scale its target,
151+
// and indicates whether or not those conditions are met.
152+
// +optional
153+
// +patchMergeKey=type
154+
// +patchStrategy=merge
155+
Conditions []vpatypes.VerticalPodAutoscalerCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
156+
}
157+
158+
// ResourceEstimatorStatus contains state for resource estimator
159+
type ResourceEstimatorStatus struct {
160+
// Type defines the type for this estimator.
161+
// +optional
162+
Type string `json:"type,omitempty"`
163+
164+
// LastUpdateTime is the last time the status updated.
165+
// +optional
166+
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
167+
168+
// The most recently computed amount of resources recommended by the
169+
// estimator for the controlled pods.
170+
// +optional
171+
Recommendation *vpatypes.RecommendedPodResources `json:"recommendation,omitempty"`
172+
}
173+
174+
// +genclient
175+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
176+
// +kubebuilder:object:root=true
177+
// +kubebuilder:subresource:status
178+
// +kubebuilder:resource:shortName=evpa
179+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created."
180+
181+
// EffectiveVerticalPodAutoscaler is the Schema for the effectiveverticalpodautoscaler API
182+
type EffectiveVerticalPodAutoscaler struct {
183+
metav1.TypeMeta `json:",inline"`
184+
metav1.ObjectMeta `json:"metadata,omitempty"`
185+
186+
// +optional
187+
Spec EffectiveVerticalPodAutoscalerSpec `json:"spec"`
188+
189+
// +optional
190+
Status EffectiveVerticalPodAutoscalerStatus `json:"status,omitempty"`
191+
}
192+
193+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
194+
// +kubebuilder:object:root=true
195+
196+
// EffectiveVerticalPodAutoscalerList contains a list of EffectiveVerticalPodAutoscaler
197+
type EffectiveVerticalPodAutoscalerList struct {
198+
metav1.TypeMeta `json:",inline"`
199+
metav1.ListMeta `json:"metadata"`
200+
201+
Items []EffectiveVerticalPodAutoscaler `json:"items"`
202+
}

autoscaling/v1alpha1/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4444
&EffectiveHorizontalPodAutoscalerList{},
4545
&Substitute{},
4646
&SubstituteList{},
47+
&EffectiveVerticalPodAutoscaler{},
48+
&EffectiveVerticalPodAutoscalerList{},
4749
)
4850
// AddToGroupVersion allows the serialization of client types like ListOptions.
4951
v1.AddToGroupVersion(scheme, SchemeGroupVersion)

0 commit comments

Comments
 (0)