blob: f842cc342da22a6afb0685b2cca41d6709f78370 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v2beta1
18
19import (
20 "k8s.io/api/core/v1"
21 "k8s.io/apimachinery/pkg/api/resource"
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23)
24
25// CrossVersionObjectReference contains enough information to let you identify the referred resource.
26type CrossVersionObjectReference struct {
27 // Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds"
28 Kind string `json:"kind" protobuf:"bytes,1,opt,name=kind"`
29 // Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
30 Name string `json:"name" protobuf:"bytes,2,opt,name=name"`
31 // API version of the referent
32 // +optional
33 APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,3,opt,name=apiVersion"`
34}
35
36// HorizontalPodAutoscalerSpec describes the desired functionality of the HorizontalPodAutoscaler.
37type HorizontalPodAutoscalerSpec struct {
38 // scaleTargetRef points to the target resource to scale, and is used to the pods for which metrics
39 // should be collected, as well as to actually change the replica count.
40 ScaleTargetRef CrossVersionObjectReference `json:"scaleTargetRef" protobuf:"bytes,1,opt,name=scaleTargetRef"`
41 // minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down.
42 // It defaults to 1 pod.
43 // +optional
44 MinReplicas *int32 `json:"minReplicas,omitempty" protobuf:"varint,2,opt,name=minReplicas"`
45 // maxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up.
46 // It cannot be less that minReplicas.
47 MaxReplicas int32 `json:"maxReplicas" protobuf:"varint,3,opt,name=maxReplicas"`
48 // metrics contains the specifications for which to use to calculate the
49 // desired replica count (the maximum replica count across all metrics will
50 // be used). The desired replica count is calculated multiplying the
51 // ratio between the target value and the current value by the current
52 // number of pods. Ergo, metrics used must decrease as the pod count is
53 // increased, and vice-versa. See the individual metric source types for
54 // more information about how each type of metric must respond.
55 // +optional
56 Metrics []MetricSpec `json:"metrics,omitempty" protobuf:"bytes,4,rep,name=metrics"`
57}
58
59// MetricSourceType indicates the type of metric.
60type MetricSourceType string
61
62var (
63 // ObjectMetricSourceType is a metric describing a kubernetes object
64 // (for example, hits-per-second on an Ingress object).
65 ObjectMetricSourceType MetricSourceType = "Object"
66 // PodsMetricSourceType is a metric describing each pod in the current scale
67 // target (for example, transactions-processed-per-second). The values
68 // will be averaged together before being compared to the target value.
69 PodsMetricSourceType MetricSourceType = "Pods"
70 // ResourceMetricSourceType is a resource metric known to Kubernetes, as
71 // specified in requests and limits, describing each pod in the current
72 // scale target (e.g. CPU or memory). Such metrics are built in to
73 // Kubernetes, and have special scaling options on top of those available
74 // to normal per-pod metrics (the "pods" source).
75 ResourceMetricSourceType MetricSourceType = "Resource"
76 // ExternalMetricSourceType is a global metric that is not associated
77 // with any Kubernetes object. It allows autoscaling based on information
78 // coming from components running outside of cluster
79 // (for example length of queue in cloud messaging service, or
80 // QPS from loadbalancer running outside of cluster).
81 ExternalMetricSourceType MetricSourceType = "External"
82)
83
84// MetricSpec specifies how to scale based on a single metric
85// (only `type` and one other matching field should be set at once).
86type MetricSpec struct {
87 // type is the type of metric source. It should be one of "Object",
88 // "Pods" or "Resource", each mapping to a matching field in the object.
89 Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"`
90
91 // object refers to a metric describing a single kubernetes object
92 // (for example, hits-per-second on an Ingress object).
93 // +optional
94 Object *ObjectMetricSource `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"`
95 // pods refers to a metric describing each pod in the current scale target
96 // (for example, transactions-processed-per-second). The values will be
97 // averaged together before being compared to the target value.
98 // +optional
99 Pods *PodsMetricSource `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"`
100 // resource refers to a resource metric (such as those specified in
101 // requests and limits) known to Kubernetes describing each pod in the
102 // current scale target (e.g. CPU or memory). Such metrics are built in to
103 // Kubernetes, and have special scaling options on top of those available
104 // to normal per-pod metrics using the "pods" source.
105 // +optional
106 Resource *ResourceMetricSource `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"`
107 // external refers to a global metric that is not associated
108 // with any Kubernetes object. It allows autoscaling based on information
109 // coming from components running outside of cluster
110 // (for example length of queue in cloud messaging service, or
111 // QPS from loadbalancer running outside of cluster).
112 // +optional
113 External *ExternalMetricSource `json:"external,omitempty" protobuf:"bytes,5,opt,name=external"`
114}
115
116// ObjectMetricSource indicates how to scale on a metric describing a
117// kubernetes object (for example, hits-per-second on an Ingress object).
118type ObjectMetricSource struct {
119 // target is the described Kubernetes object.
120 Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"`
121
122 // metricName is the name of the metric in question.
123 MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"`
124 // targetValue is the target value of the metric (as a quantity).
125 TargetValue resource.Quantity `json:"targetValue" protobuf:"bytes,3,name=targetValue"`
126}
127
128// PodsMetricSource indicates how to scale on a metric describing each pod in
129// the current scale target (for example, transactions-processed-per-second).
130// The values will be averaged together before being compared to the target
131// value.
132type PodsMetricSource struct {
133 // metricName is the name of the metric in question
134 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
135 // targetAverageValue is the target value of the average of the
136 // metric across all relevant pods (as a quantity)
137 TargetAverageValue resource.Quantity `json:"targetAverageValue" protobuf:"bytes,2,name=targetAverageValue"`
138}
139
140// ResourceMetricSource indicates how to scale on a resource metric known to
141// Kubernetes, as specified in requests and limits, describing each pod in the
142// current scale target (e.g. CPU or memory). The values will be averaged
143// together before being compared to the target. Such metrics are built in to
144// Kubernetes, and have special scaling options on top of those available to
145// normal per-pod metrics using the "pods" source. Only one "target" type
146// should be set.
147type ResourceMetricSource struct {
148 // name is the name of the resource in question.
149 Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"`
150 // targetAverageUtilization is the target value of the average of the
151 // resource metric across all relevant pods, represented as a percentage of
152 // the requested value of the resource for the pods.
153 // +optional
154 TargetAverageUtilization *int32 `json:"targetAverageUtilization,omitempty" protobuf:"varint,2,opt,name=targetAverageUtilization"`
155 // targetAverageValue is the target value of the average of the
156 // resource metric across all relevant pods, as a raw value (instead of as
157 // a percentage of the request), similar to the "pods" metric source type.
158 // +optional
159 TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,3,opt,name=targetAverageValue"`
160}
161
162// ExternalMetricSource indicates how to scale on a metric not associated with
163// any Kubernetes object (for example length of queue in cloud
164// messaging service, or QPS from loadbalancer running outside of cluster).
165// Exactly one "target" type should be set.
166type ExternalMetricSource struct {
167 // metricName is the name of the metric in question.
168 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
169 // metricSelector is used to identify a specific time series
170 // within a given metric.
171 // +optional
172 MetricSelector *metav1.LabelSelector `json:"metricSelector,omitempty" protobuf:"bytes,2,opt,name=metricSelector"`
173 // targetValue is the target value of the metric (as a quantity).
174 // Mutually exclusive with TargetAverageValue.
175 // +optional
176 TargetValue *resource.Quantity `json:"targetValue,omitempty" protobuf:"bytes,3,opt,name=targetValue"`
177 // targetAverageValue is the target per-pod value of global metric (as a quantity).
178 // Mutually exclusive with TargetValue.
179 // +optional
180 TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,4,opt,name=targetAverageValue"`
181}
182
183// HorizontalPodAutoscalerStatus describes the current status of a horizontal pod autoscaler.
184type HorizontalPodAutoscalerStatus struct {
185 // observedGeneration is the most recent generation observed by this autoscaler.
186 // +optional
187 ObservedGeneration *int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"`
188
189 // lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods,
190 // used by the autoscaler to control how often the number of pods is changed.
191 // +optional
192 LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty" protobuf:"bytes,2,opt,name=lastScaleTime"`
193
194 // currentReplicas is current number of replicas of pods managed by this autoscaler,
195 // as last seen by the autoscaler.
196 CurrentReplicas int32 `json:"currentReplicas" protobuf:"varint,3,opt,name=currentReplicas"`
197
198 // desiredReplicas is the desired number of replicas of pods managed by this autoscaler,
199 // as last calculated by the autoscaler.
200 DesiredReplicas int32 `json:"desiredReplicas" protobuf:"varint,4,opt,name=desiredReplicas"`
201
202 // currentMetrics is the last read state of the metrics used by this autoscaler.
203 CurrentMetrics []MetricStatus `json:"currentMetrics" protobuf:"bytes,5,rep,name=currentMetrics"`
204
205 // conditions is the set of conditions required for this autoscaler to scale its target,
206 // and indicates whether or not those conditions are met.
207 Conditions []HorizontalPodAutoscalerCondition `json:"conditions" protobuf:"bytes,6,rep,name=conditions"`
208}
209
210// HorizontalPodAutoscalerConditionType are the valid conditions of
211// a HorizontalPodAutoscaler.
212type HorizontalPodAutoscalerConditionType string
213
214var (
215 // ScalingActive indicates that the HPA controller is able to scale if necessary:
216 // it's correctly configured, can fetch the desired metrics, and isn't disabled.
217 ScalingActive HorizontalPodAutoscalerConditionType = "ScalingActive"
218 // AbleToScale indicates a lack of transient issues which prevent scaling from occurring,
219 // such as being in a backoff window, or being unable to access/update the target scale.
220 AbleToScale HorizontalPodAutoscalerConditionType = "AbleToScale"
221 // ScalingLimited indicates that the calculated scale based on metrics would be above or
222 // below the range for the HPA, and has thus been capped.
223 ScalingLimited HorizontalPodAutoscalerConditionType = "ScalingLimited"
224)
225
226// HorizontalPodAutoscalerCondition describes the state of
227// a HorizontalPodAutoscaler at a certain point.
228type HorizontalPodAutoscalerCondition struct {
229 // type describes the current condition
230 Type HorizontalPodAutoscalerConditionType `json:"type" protobuf:"bytes,1,name=type"`
231 // status is the status of the condition (True, False, Unknown)
232 Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,name=status"`
233 // lastTransitionTime is the last time the condition transitioned from
234 // one status to another
235 // +optional
236 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
237 // reason is the reason for the condition's last transition.
238 // +optional
239 Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
240 // message is a human-readable explanation containing details about
241 // the transition
242 // +optional
243 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
244}
245
246// MetricStatus describes the last-read state of a single metric.
247type MetricStatus struct {
248 // type is the type of metric source. It will be one of "Object",
249 // "Pods" or "Resource", each corresponds to a matching field in the object.
250 Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"`
251
252 // object refers to a metric describing a single kubernetes object
253 // (for example, hits-per-second on an Ingress object).
254 // +optional
255 Object *ObjectMetricStatus `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"`
256 // pods refers to a metric describing each pod in the current scale target
257 // (for example, transactions-processed-per-second). The values will be
258 // averaged together before being compared to the target value.
259 // +optional
260 Pods *PodsMetricStatus `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"`
261 // resource refers to a resource metric (such as those specified in
262 // requests and limits) known to Kubernetes describing each pod in the
263 // current scale target (e.g. CPU or memory). Such metrics are built in to
264 // Kubernetes, and have special scaling options on top of those available
265 // to normal per-pod metrics using the "pods" source.
266 // +optional
267 Resource *ResourceMetricStatus `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"`
268 // external refers to a global metric that is not associated
269 // with any Kubernetes object. It allows autoscaling based on information
270 // coming from components running outside of cluster
271 // (for example length of queue in cloud messaging service, or
272 // QPS from loadbalancer running outside of cluster).
273 // +optional
274 External *ExternalMetricStatus `json:"external,omitempty" protobuf:"bytes,5,opt,name=external"`
275}
276
277// ObjectMetricStatus indicates the current value of a metric describing a
278// kubernetes object (for example, hits-per-second on an Ingress object).
279type ObjectMetricStatus struct {
280 // target is the described Kubernetes object.
281 Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"`
282
283 // metricName is the name of the metric in question.
284 MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"`
285 // currentValue is the current value of the metric (as a quantity).
286 CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"`
287}
288
289// PodsMetricStatus indicates the current value of a metric describing each pod in
290// the current scale target (for example, transactions-processed-per-second).
291type PodsMetricStatus struct {
292 // metricName is the name of the metric in question
293 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
294 // currentAverageValue is the current value of the average of the
295 // metric across all relevant pods (as a quantity)
296 CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,2,name=currentAverageValue"`
297}
298
299// ResourceMetricStatus indicates the current value of a resource metric known to
300// Kubernetes, as specified in requests and limits, describing each pod in the
301// current scale target (e.g. CPU or memory). Such metrics are built in to
302// Kubernetes, and have special scaling options on top of those available to
303// normal per-pod metrics using the "pods" source.
304type ResourceMetricStatus struct {
305 // name is the name of the resource in question.
306 Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"`
307 // currentAverageUtilization is the current value of the average of the
308 // resource metric across all relevant pods, represented as a percentage of
309 // the requested value of the resource for the pods. It will only be
310 // present if `targetAverageValue` was set in the corresponding metric
311 // specification.
312 // +optional
313 CurrentAverageUtilization *int32 `json:"currentAverageUtilization,omitempty" protobuf:"bytes,2,opt,name=currentAverageUtilization"`
314 // currentAverageValue is the current value of the average of the
315 // resource metric across all relevant pods, as a raw value (instead of as
316 // a percentage of the request), similar to the "pods" metric source type.
317 // It will always be set, regardless of the corresponding metric specification.
318 CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,3,name=currentAverageValue"`
319}
320
321// ExternalMetricStatus indicates the current value of a global metric
322// not associated with any Kubernetes object.
323type ExternalMetricStatus struct {
324 // metricName is the name of a metric used for autoscaling in
325 // metric system.
326 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
327 // metricSelector is used to identify a specific time series
328 // within a given metric.
329 // +optional
330 MetricSelector *metav1.LabelSelector `json:"metricSelector,omitempty" protobuf:"bytes,2,opt,name=metricSelector"`
331 // currentValue is the current value of the metric (as a quantity)
332 CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"`
333 // currentAverageValue is the current value of metric averaged over autoscaled pods.
334 // +optional
335 CurrentAverageValue *resource.Quantity `json:"currentAverageValue,omitempty" protobuf:"bytes,4,opt,name=currentAverageValue"`
336}
337
338// +genclient
339// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
340
341// HorizontalPodAutoscaler is the configuration for a horizontal pod
342// autoscaler, which automatically manages the replica count of any resource
343// implementing the scale subresource based on the metrics specified.
344type HorizontalPodAutoscaler struct {
345 metav1.TypeMeta `json:",inline"`
346 // metadata is the standard object metadata.
347 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
348 // +optional
349 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
350
351 // spec is the specification for the behaviour of the autoscaler.
352 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
353 // +optional
354 Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
355
356 // status is the current information about the autoscaler.
357 // +optional
358 Status HorizontalPodAutoscalerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
359}
360
361// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
362
363// HorizontalPodAutoscaler is a list of horizontal pod autoscaler objects.
364type HorizontalPodAutoscalerList struct {
365 metav1.TypeMeta `json:",inline"`
366 // metadata is the standard list metadata.
367 // +optional
368 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
369
370 // items is the list of horizontal pod autoscaler objects.
371 Items []HorizontalPodAutoscaler `json:"items" protobuf:"bytes,2,rep,name=items"`
372}