blob: 6a30e6774db51f053f5add78027982bfcf30288c [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
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 // selector is the string-encoded form of a standard kubernetes label selector for the given metric
128 // When set, it is passed as an additional parameter to the metrics server for more specific metrics scoping
129 // When unset, just the metricName will be used to gather metrics.
130 // +optional
131 Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,4,name=selector"`
132 // averageValue is the target value of the average of the
133 // metric across all relevant pods (as a quantity)
134 // +optional
135 AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,5,name=averageValue"`
136}
137
138// PodsMetricSource indicates how to scale on a metric describing each pod in
139// the current scale target (for example, transactions-processed-per-second).
140// The values will be averaged together before being compared to the target
141// value.
142type PodsMetricSource struct {
143 // metricName is the name of the metric in question
144 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
145 // targetAverageValue is the target value of the average of the
146 // metric across all relevant pods (as a quantity)
147 TargetAverageValue resource.Quantity `json:"targetAverageValue" protobuf:"bytes,2,name=targetAverageValue"`
148
149 // selector is the string-encoded form of a standard kubernetes label selector for the given metric
150 // When set, it is passed as an additional parameter to the metrics server for more specific metrics scoping
151 // When unset, just the metricName will be used to gather metrics.
152 // +optional
153 Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,3,name=selector"`
154}
155
156// ResourceMetricSource indicates how to scale on a resource metric known to
157// Kubernetes, as specified in requests and limits, describing each pod in the
158// current scale target (e.g. CPU or memory). The values will be averaged
159// together before being compared to the target. Such metrics are built in to
160// Kubernetes, and have special scaling options on top of those available to
161// normal per-pod metrics using the "pods" source. Only one "target" type
162// should be set.
163type ResourceMetricSource struct {
164 // name is the name of the resource in question.
165 Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"`
166 // targetAverageUtilization is the target value of the average of the
167 // resource metric across all relevant pods, represented as a percentage of
168 // the requested value of the resource for the pods.
169 // +optional
170 TargetAverageUtilization *int32 `json:"targetAverageUtilization,omitempty" protobuf:"varint,2,opt,name=targetAverageUtilization"`
171 // targetAverageValue is the target value of the average of the
172 // resource metric across all relevant pods, as a raw value (instead of as
173 // a percentage of the request), similar to the "pods" metric source type.
174 // +optional
175 TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,3,opt,name=targetAverageValue"`
176}
177
178// ExternalMetricSource indicates how to scale on a metric not associated with
179// any Kubernetes object (for example length of queue in cloud
180// messaging service, or QPS from loadbalancer running outside of cluster).
181// Exactly one "target" type should be set.
182type ExternalMetricSource struct {
183 // metricName is the name of the metric in question.
184 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
185 // metricSelector is used to identify a specific time series
186 // within a given metric.
187 // +optional
188 MetricSelector *metav1.LabelSelector `json:"metricSelector,omitempty" protobuf:"bytes,2,opt,name=metricSelector"`
189 // targetValue is the target value of the metric (as a quantity).
190 // Mutually exclusive with TargetAverageValue.
191 // +optional
192 TargetValue *resource.Quantity `json:"targetValue,omitempty" protobuf:"bytes,3,opt,name=targetValue"`
193 // targetAverageValue is the target per-pod value of global metric (as a quantity).
194 // Mutually exclusive with TargetValue.
195 // +optional
196 TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,4,opt,name=targetAverageValue"`
197}
198
199// HorizontalPodAutoscalerStatus describes the current status of a horizontal pod autoscaler.
200type HorizontalPodAutoscalerStatus struct {
201 // observedGeneration is the most recent generation observed by this autoscaler.
202 // +optional
203 ObservedGeneration *int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"`
204
205 // lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods,
206 // used by the autoscaler to control how often the number of pods is changed.
207 // +optional
208 LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty" protobuf:"bytes,2,opt,name=lastScaleTime"`
209
210 // currentReplicas is current number of replicas of pods managed by this autoscaler,
211 // as last seen by the autoscaler.
212 CurrentReplicas int32 `json:"currentReplicas" protobuf:"varint,3,opt,name=currentReplicas"`
213
214 // desiredReplicas is the desired number of replicas of pods managed by this autoscaler,
215 // as last calculated by the autoscaler.
216 DesiredReplicas int32 `json:"desiredReplicas" protobuf:"varint,4,opt,name=desiredReplicas"`
217
218 // currentMetrics is the last read state of the metrics used by this autoscaler.
219 // +optional
220 CurrentMetrics []MetricStatus `json:"currentMetrics" protobuf:"bytes,5,rep,name=currentMetrics"`
221
222 // conditions is the set of conditions required for this autoscaler to scale its target,
223 // and indicates whether or not those conditions are met.
224 Conditions []HorizontalPodAutoscalerCondition `json:"conditions" protobuf:"bytes,6,rep,name=conditions"`
225}
226
227// HorizontalPodAutoscalerConditionType are the valid conditions of
228// a HorizontalPodAutoscaler.
229type HorizontalPodAutoscalerConditionType string
230
231var (
232 // ScalingActive indicates that the HPA controller is able to scale if necessary:
233 // it's correctly configured, can fetch the desired metrics, and isn't disabled.
234 ScalingActive HorizontalPodAutoscalerConditionType = "ScalingActive"
235 // AbleToScale indicates a lack of transient issues which prevent scaling from occurring,
236 // such as being in a backoff window, or being unable to access/update the target scale.
237 AbleToScale HorizontalPodAutoscalerConditionType = "AbleToScale"
238 // ScalingLimited indicates that the calculated scale based on metrics would be above or
239 // below the range for the HPA, and has thus been capped.
240 ScalingLimited HorizontalPodAutoscalerConditionType = "ScalingLimited"
241)
242
243// HorizontalPodAutoscalerCondition describes the state of
244// a HorizontalPodAutoscaler at a certain point.
245type HorizontalPodAutoscalerCondition struct {
246 // type describes the current condition
247 Type HorizontalPodAutoscalerConditionType `json:"type" protobuf:"bytes,1,name=type"`
248 // status is the status of the condition (True, False, Unknown)
249 Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,name=status"`
250 // lastTransitionTime is the last time the condition transitioned from
251 // one status to another
252 // +optional
253 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
254 // reason is the reason for the condition's last transition.
255 // +optional
256 Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
257 // message is a human-readable explanation containing details about
258 // the transition
259 // +optional
260 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
261}
262
263// MetricStatus describes the last-read state of a single metric.
264type MetricStatus struct {
265 // type is the type of metric source. It will be one of "Object",
266 // "Pods" or "Resource", each corresponds to a matching field in the object.
267 Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"`
268
269 // object refers to a metric describing a single kubernetes object
270 // (for example, hits-per-second on an Ingress object).
271 // +optional
272 Object *ObjectMetricStatus `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"`
273 // pods refers to a metric describing each pod in the current scale target
274 // (for example, transactions-processed-per-second). The values will be
275 // averaged together before being compared to the target value.
276 // +optional
277 Pods *PodsMetricStatus `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"`
278 // resource refers to a resource metric (such as those specified in
279 // requests and limits) known to Kubernetes describing each pod in the
280 // current scale target (e.g. CPU or memory). Such metrics are built in to
281 // Kubernetes, and have special scaling options on top of those available
282 // to normal per-pod metrics using the "pods" source.
283 // +optional
284 Resource *ResourceMetricStatus `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"`
285 // external refers to a global metric that is not associated
286 // with any Kubernetes object. It allows autoscaling based on information
287 // coming from components running outside of cluster
288 // (for example length of queue in cloud messaging service, or
289 // QPS from loadbalancer running outside of cluster).
290 // +optional
291 External *ExternalMetricStatus `json:"external,omitempty" protobuf:"bytes,5,opt,name=external"`
292}
293
294// ObjectMetricStatus indicates the current value of a metric describing a
295// kubernetes object (for example, hits-per-second on an Ingress object).
296type ObjectMetricStatus struct {
297 // target is the described Kubernetes object.
298 Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"`
299
300 // metricName is the name of the metric in question.
301 MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"`
302 // currentValue is the current value of the metric (as a quantity).
303 CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"`
304
305 // selector is the string-encoded form of a standard kubernetes label selector for the given metric
306 // When set in the ObjectMetricSource, it is passed as an additional parameter to the metrics server for more specific metrics scoping.
307 // When unset, just the metricName will be used to gather metrics.
308 // +optional
309 Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,4,name=selector"`
310 // averageValue is the current value of the average of the
311 // metric across all relevant pods (as a quantity)
312 // +optional
313 AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,5,name=averageValue"`
314}
315
316// PodsMetricStatus indicates the current value of a metric describing each pod in
317// the current scale target (for example, transactions-processed-per-second).
318type PodsMetricStatus struct {
319 // metricName is the name of the metric in question
320 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
321 // currentAverageValue is the current value of the average of the
322 // metric across all relevant pods (as a quantity)
323 CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,2,name=currentAverageValue"`
324
325 // selector is the string-encoded form of a standard kubernetes label selector for the given metric
326 // When set in the PodsMetricSource, it is passed as an additional parameter to the metrics server for more specific metrics scoping.
327 // When unset, just the metricName will be used to gather metrics.
328 // +optional
329 Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,3,name=selector"`
330}
331
332// ResourceMetricStatus indicates the current value of a resource metric known to
333// Kubernetes, as specified in requests and limits, describing each pod in the
334// current scale target (e.g. CPU or memory). Such metrics are built in to
335// Kubernetes, and have special scaling options on top of those available to
336// normal per-pod metrics using the "pods" source.
337type ResourceMetricStatus struct {
338 // name is the name of the resource in question.
339 Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"`
340 // currentAverageUtilization is the current value of the average of the
341 // resource metric across all relevant pods, represented as a percentage of
342 // the requested value of the resource for the pods. It will only be
343 // present if `targetAverageValue` was set in the corresponding metric
344 // specification.
345 // +optional
346 CurrentAverageUtilization *int32 `json:"currentAverageUtilization,omitempty" protobuf:"bytes,2,opt,name=currentAverageUtilization"`
347 // currentAverageValue is the current value of the average of the
348 // resource metric across all relevant pods, as a raw value (instead of as
349 // a percentage of the request), similar to the "pods" metric source type.
350 // It will always be set, regardless of the corresponding metric specification.
351 CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,3,name=currentAverageValue"`
352}
353
354// ExternalMetricStatus indicates the current value of a global metric
355// not associated with any Kubernetes object.
356type ExternalMetricStatus struct {
357 // metricName is the name of a metric used for autoscaling in
358 // metric system.
359 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
360 // metricSelector is used to identify a specific time series
361 // within a given metric.
362 // +optional
363 MetricSelector *metav1.LabelSelector `json:"metricSelector,omitempty" protobuf:"bytes,2,opt,name=metricSelector"`
364 // currentValue is the current value of the metric (as a quantity)
365 CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"`
366 // currentAverageValue is the current value of metric averaged over autoscaled pods.
367 // +optional
368 CurrentAverageValue *resource.Quantity `json:"currentAverageValue,omitempty" protobuf:"bytes,4,opt,name=currentAverageValue"`
369}
370
371// +genclient
372// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
373
374// HorizontalPodAutoscaler is the configuration for a horizontal pod
375// autoscaler, which automatically manages the replica count of any resource
376// implementing the scale subresource based on the metrics specified.
377type HorizontalPodAutoscaler struct {
378 metav1.TypeMeta `json:",inline"`
379 // metadata is the standard object metadata.
380 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
381 // +optional
382 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
383
384 // spec is the specification for the behaviour of the autoscaler.
385 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
386 // +optional
387 Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
388
389 // status is the current information about the autoscaler.
390 // +optional
391 Status HorizontalPodAutoscalerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
392}
393
394// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
395
396// HorizontalPodAutoscaler is a list of horizontal pod autoscaler objects.
397type HorizontalPodAutoscalerList struct {
398 metav1.TypeMeta `json:",inline"`
399 // metadata is the standard list metadata.
400 // +optional
401 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
402
403 // items is the list of horizontal pod autoscaler objects.
404 Items []HorizontalPodAutoscaler `json:"items" protobuf:"bytes,2,rep,name=items"`
405}