Code refactoring for bpa operator
[icn.git] / cmd / bpa-operator / vendor / k8s.io / api / autoscaling / v1 / types.go
1 /*
2 Copyright 2016 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package v1
18
19 import (
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.
26 type 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 // specification of a horizontal pod autoscaler.
37 type HorizontalPodAutoscalerSpec struct {
38         // reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption
39         // and will set the desired number of pods by using its Scale subresource.
40         ScaleTargetRef CrossVersionObjectReference `json:"scaleTargetRef" protobuf:"bytes,1,opt,name=scaleTargetRef"`
41         // lower limit for the number of pods that can be set by the autoscaler, default 1.
42         // +optional
43         MinReplicas *int32 `json:"minReplicas,omitempty" protobuf:"varint,2,opt,name=minReplicas"`
44         // upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.
45         MaxReplicas int32 `json:"maxReplicas" protobuf:"varint,3,opt,name=maxReplicas"`
46         // target average CPU utilization (represented as a percentage of requested CPU) over all the pods;
47         // if not specified the default autoscaling policy will be used.
48         // +optional
49         TargetCPUUtilizationPercentage *int32 `json:"targetCPUUtilizationPercentage,omitempty" protobuf:"varint,4,opt,name=targetCPUUtilizationPercentage"`
50 }
51
52 // current status of a horizontal pod autoscaler
53 type HorizontalPodAutoscalerStatus struct {
54         // most recent generation observed by this autoscaler.
55         // +optional
56         ObservedGeneration *int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"`
57
58         // last time the HorizontalPodAutoscaler scaled the number of pods;
59         // used by the autoscaler to control how often the number of pods is changed.
60         // +optional
61         LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty" protobuf:"bytes,2,opt,name=lastScaleTime"`
62
63         // current number of replicas of pods managed by this autoscaler.
64         CurrentReplicas int32 `json:"currentReplicas" protobuf:"varint,3,opt,name=currentReplicas"`
65
66         // desired number of replicas of pods managed by this autoscaler.
67         DesiredReplicas int32 `json:"desiredReplicas" protobuf:"varint,4,opt,name=desiredReplicas"`
68
69         // current average CPU utilization over all pods, represented as a percentage of requested CPU,
70         // e.g. 70 means that an average pod is using now 70% of its requested CPU.
71         // +optional
72         CurrentCPUUtilizationPercentage *int32 `json:"currentCPUUtilizationPercentage,omitempty" protobuf:"varint,5,opt,name=currentCPUUtilizationPercentage"`
73 }
74
75 // +genclient
76 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
77
78 // configuration of a horizontal pod autoscaler.
79 type HorizontalPodAutoscaler struct {
80         metav1.TypeMeta `json:",inline"`
81         // Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
82         // +optional
83         metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
84
85         // behaviour of autoscaler. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
86         // +optional
87         Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
88
89         // current information about the autoscaler.
90         // +optional
91         Status HorizontalPodAutoscalerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
92 }
93
94 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
95
96 // list of horizontal pod autoscaler objects.
97 type HorizontalPodAutoscalerList struct {
98         metav1.TypeMeta `json:",inline"`
99         // Standard list metadata.
100         // +optional
101         metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
102
103         // list of horizontal pod autoscaler objects.
104         Items []HorizontalPodAutoscaler `json:"items" protobuf:"bytes,2,rep,name=items"`
105 }
106
107 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
108
109 // Scale represents a scaling request for a resource.
110 type Scale struct {
111         metav1.TypeMeta `json:",inline"`
112         // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
113         // +optional
114         metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
115
116         // defines the behavior of the scale. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
117         // +optional
118         Spec ScaleSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
119
120         // current status of the scale. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status. Read-only.
121         // +optional
122         Status ScaleStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
123 }
124
125 // ScaleSpec describes the attributes of a scale subresource.
126 type ScaleSpec struct {
127         // desired number of instances for the scaled object.
128         // +optional
129         Replicas int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
130 }
131
132 // ScaleStatus represents the current status of a scale subresource.
133 type ScaleStatus struct {
134         // actual number of observed instances of the scaled object.
135         Replicas int32 `json:"replicas" protobuf:"varint,1,opt,name=replicas"`
136
137         // label query over pods that should match the replicas count. This is same
138         // as the label selector but in the string format to avoid introspection
139         // by clients. The string will be in the same format as the query-param syntax.
140         // More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors
141         // +optional
142         Selector string `json:"selector,omitempty" protobuf:"bytes,2,opt,name=selector"`
143 }
144
145 // the types below are used in the alpha metrics annotation
146
147 // MetricSourceType indicates the type of metric.
148 type MetricSourceType string
149
150 var (
151         // ObjectMetricSourceType is a metric describing a kubernetes object
152         // (for example, hits-per-second on an Ingress object).
153         ObjectMetricSourceType MetricSourceType = "Object"
154         // PodsMetricSourceType is a metric describing each pod in the current scale
155         // target (for example, transactions-processed-per-second).  The values
156         // will be averaged together before being compared to the target value.
157         PodsMetricSourceType MetricSourceType = "Pods"
158         // ResourceMetricSourceType is a resource metric known to Kubernetes, as
159         // specified in requests and limits, describing each pod in the current
160         // scale target (e.g. CPU or memory).  Such metrics are built in to
161         // Kubernetes, and have special scaling options on top of those available
162         // to normal per-pod metrics (the "pods" source).
163         ResourceMetricSourceType MetricSourceType = "Resource"
164         // ExternalMetricSourceType is a global metric that is not associated
165         // with any Kubernetes object. It allows autoscaling based on information
166         // coming from components running outside of cluster
167         // (for example length of queue in cloud messaging service, or
168         // QPS from loadbalancer running outside of cluster).
169         ExternalMetricSourceType MetricSourceType = "External"
170 )
171
172 // MetricSpec specifies how to scale based on a single metric
173 // (only `type` and one other matching field should be set at once).
174 type MetricSpec struct {
175         // type is the type of metric source.  It should be one of "Object",
176         // "Pods" or "Resource", each mapping to a matching field in the object.
177         Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"`
178
179         // object refers to a metric describing a single kubernetes object
180         // (for example, hits-per-second on an Ingress object).
181         // +optional
182         Object *ObjectMetricSource `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"`
183         // pods refers to a metric describing each pod in the current scale target
184         // (for example, transactions-processed-per-second).  The values will be
185         // averaged together before being compared to the target value.
186         // +optional
187         Pods *PodsMetricSource `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"`
188         // resource refers to a resource metric (such as those specified in
189         // requests and limits) known to Kubernetes describing each pod in the
190         // current scale target (e.g. CPU or memory). Such metrics are built in to
191         // Kubernetes, and have special scaling options on top of those available
192         // to normal per-pod metrics using the "pods" source.
193         // +optional
194         Resource *ResourceMetricSource `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"`
195         // external refers to a global metric that is not associated
196         // with any Kubernetes object. It allows autoscaling based on information
197         // coming from components running outside of cluster
198         // (for example length of queue in cloud messaging service, or
199         // QPS from loadbalancer running outside of cluster).
200         // +optional
201         External *ExternalMetricSource `json:"external,omitempty" protobuf:"bytes,5,opt,name=external"`
202 }
203
204 // ObjectMetricSource indicates how to scale on a metric describing a
205 // kubernetes object (for example, hits-per-second on an Ingress object).
206 type ObjectMetricSource struct {
207         // target is the described Kubernetes object.
208         Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"`
209
210         // metricName is the name of the metric in question.
211         MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"`
212         // targetValue is the target value of the metric (as a quantity).
213         TargetValue resource.Quantity `json:"targetValue" protobuf:"bytes,3,name=targetValue"`
214
215         // selector is the string-encoded form of a standard kubernetes label selector for the given metric.
216         // When set, it is passed as an additional parameter to the metrics server for more specific metrics scoping
217         // When unset, just the metricName will be used to gather metrics.
218         // +optional
219         Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,4,name=selector"`
220         // averageValue is the target value of the average of the
221         // metric across all relevant pods (as a quantity)
222         // +optional
223         AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,5,name=averageValue"`
224 }
225
226 // PodsMetricSource indicates how to scale on a metric describing each pod in
227 // the current scale target (for example, transactions-processed-per-second).
228 // The values will be averaged together before being compared to the target
229 // value.
230 type PodsMetricSource struct {
231         // metricName is the name of the metric in question
232         MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
233         // targetAverageValue is the target value of the average of the
234         // metric across all relevant pods (as a quantity)
235         TargetAverageValue resource.Quantity `json:"targetAverageValue" protobuf:"bytes,2,name=targetAverageValue"`
236
237         // selector is the string-encoded form of a standard kubernetes label selector for the given metric
238         // When set, it is passed as an additional parameter to the metrics server for more specific metrics scoping
239         // When unset, just the metricName will be used to gather metrics.
240         // +optional
241         Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,3,name=selector"`
242 }
243
244 // ResourceMetricSource indicates how to scale on a resource metric known to
245 // Kubernetes, as specified in requests and limits, describing each pod in the
246 // current scale target (e.g. CPU or memory).  The values will be averaged
247 // together before being compared to the target.  Such metrics are built in to
248 // Kubernetes, and have special scaling options on top of those available to
249 // normal per-pod metrics using the "pods" source.  Only one "target" type
250 // should be set.
251 type ResourceMetricSource struct {
252         // name is the name of the resource in question.
253         Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"`
254         // targetAverageUtilization is the target value of the average of the
255         // resource metric across all relevant pods, represented as a percentage of
256         // the requested value of the resource for the pods.
257         // +optional
258         TargetAverageUtilization *int32 `json:"targetAverageUtilization,omitempty" protobuf:"varint,2,opt,name=targetAverageUtilization"`
259         // targetAverageValue is the target value of the average of the
260         // resource metric across all relevant pods, as a raw value (instead of as
261         // a percentage of the request), similar to the "pods" metric source type.
262         // +optional
263         TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,3,opt,name=targetAverageValue"`
264 }
265
266 // ExternalMetricSource indicates how to scale on a metric not associated with
267 // any Kubernetes object (for example length of queue in cloud
268 // messaging service, or QPS from loadbalancer running outside of cluster).
269 type ExternalMetricSource struct {
270         // metricName is the name of the metric in question.
271         MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
272         // metricSelector is used to identify a specific time series
273         // within a given metric.
274         // +optional
275         MetricSelector *metav1.LabelSelector `json:"metricSelector,omitempty" protobuf:"bytes,2,opt,name=metricSelector"`
276         // targetValue is the target value of the metric (as a quantity).
277         // Mutually exclusive with TargetAverageValue.
278         // +optional
279         TargetValue *resource.Quantity `json:"targetValue,omitempty" protobuf:"bytes,3,opt,name=targetValue"`
280         // targetAverageValue is the target per-pod value of global metric (as a quantity).
281         // Mutually exclusive with TargetValue.
282         // +optional
283         TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,4,opt,name=targetAverageValue"`
284 }
285
286 // MetricStatus describes the last-read state of a single metric.
287 type MetricStatus struct {
288         // type is the type of metric source.  It will be one of "Object",
289         // "Pods" or "Resource", each corresponds to a matching field in the object.
290         Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"`
291
292         // object refers to a metric describing a single kubernetes object
293         // (for example, hits-per-second on an Ingress object).
294         // +optional
295         Object *ObjectMetricStatus `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"`
296         // pods refers to a metric describing each pod in the current scale target
297         // (for example, transactions-processed-per-second).  The values will be
298         // averaged together before being compared to the target value.
299         // +optional
300         Pods *PodsMetricStatus `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"`
301         // resource refers to a resource metric (such as those specified in
302         // requests and limits) known to Kubernetes describing each pod in the
303         // current scale target (e.g. CPU or memory). Such metrics are built in to
304         // Kubernetes, and have special scaling options on top of those available
305         // to normal per-pod metrics using the "pods" source.
306         // +optional
307         Resource *ResourceMetricStatus `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"`
308         // external refers to a global metric that is not associated
309         // with any Kubernetes object. It allows autoscaling based on information
310         // coming from components running outside of cluster
311         // (for example length of queue in cloud messaging service, or
312         // QPS from loadbalancer running outside of cluster).
313         // +optional
314         External *ExternalMetricStatus `json:"external,omitempty" protobuf:"bytes,5,opt,name=external"`
315 }
316
317 // HorizontalPodAutoscalerConditionType are the valid conditions of
318 // a HorizontalPodAutoscaler.
319 type HorizontalPodAutoscalerConditionType string
320
321 var (
322         // ScalingActive indicates that the HPA controller is able to scale if necessary:
323         // it's correctly configured, can fetch the desired metrics, and isn't disabled.
324         ScalingActive HorizontalPodAutoscalerConditionType = "ScalingActive"
325         // AbleToScale indicates a lack of transient issues which prevent scaling from occurring,
326         // such as being in a backoff window, or being unable to access/update the target scale.
327         AbleToScale HorizontalPodAutoscalerConditionType = "AbleToScale"
328         // ScalingLimited indicates that the calculated scale based on metrics would be above or
329         // below the range for the HPA, and has thus been capped.
330         ScalingLimited HorizontalPodAutoscalerConditionType = "ScalingLimited"
331 )
332
333 // HorizontalPodAutoscalerCondition describes the state of
334 // a HorizontalPodAutoscaler at a certain point.
335 type HorizontalPodAutoscalerCondition struct {
336         // type describes the current condition
337         Type HorizontalPodAutoscalerConditionType `json:"type" protobuf:"bytes,1,name=type"`
338         // status is the status of the condition (True, False, Unknown)
339         Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,name=status"`
340         // lastTransitionTime is the last time the condition transitioned from
341         // one status to another
342         // +optional
343         LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
344         // reason is the reason for the condition's last transition.
345         // +optional
346         Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
347         // message is a human-readable explanation containing details about
348         // the transition
349         // +optional
350         Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
351 }
352
353 // ObjectMetricStatus indicates the current value of a metric describing a
354 // kubernetes object (for example, hits-per-second on an Ingress object).
355 type ObjectMetricStatus struct {
356         // target is the described Kubernetes object.
357         Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"`
358
359         // metricName is the name of the metric in question.
360         MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"`
361         // currentValue is the current value of the metric (as a quantity).
362         CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"`
363
364         // selector is the string-encoded form of a standard kubernetes label selector for the given metric
365         // When set in the ObjectMetricSource, it is passed as an additional parameter to the metrics server for more specific metrics scoping.
366         // When unset, just the metricName will be used to gather metrics.
367         // +optional
368         Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,4,name=selector"`
369         // averageValue is the current value of the average of the
370         // metric across all relevant pods (as a quantity)
371         // +optional
372         AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,5,name=averageValue"`
373 }
374
375 // PodsMetricStatus indicates the current value of a metric describing each pod in
376 // the current scale target (for example, transactions-processed-per-second).
377 type PodsMetricStatus struct {
378         // metricName is the name of the metric in question
379         MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
380         // currentAverageValue is the current value of the average of the
381         // metric across all relevant pods (as a quantity)
382         CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,2,name=currentAverageValue"`
383
384         // selector is the string-encoded form of a standard kubernetes label selector for the given metric
385         // When set in the PodsMetricSource, it is passed as an additional parameter to the metrics server for more specific metrics scoping.
386         // When unset, just the metricName will be used to gather metrics.
387         // +optional
388         Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,3,name=selector"`
389 }
390
391 // ResourceMetricStatus indicates the current value of a resource metric known to
392 // Kubernetes, as specified in requests and limits, describing each pod in the
393 // current scale target (e.g. CPU or memory).  Such metrics are built in to
394 // Kubernetes, and have special scaling options on top of those available to
395 // normal per-pod metrics using the "pods" source.
396 type ResourceMetricStatus struct {
397         // name is the name of the resource in question.
398         Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"`
399         // currentAverageUtilization is the current value of the average of the
400         // resource metric across all relevant pods, represented as a percentage of
401         // the requested value of the resource for the pods.  It will only be
402         // present if `targetAverageValue` was set in the corresponding metric
403         // specification.
404         // +optional
405         CurrentAverageUtilization *int32 `json:"currentAverageUtilization,omitempty" protobuf:"bytes,2,opt,name=currentAverageUtilization"`
406         // currentAverageValue is the current value of the average of the
407         // resource metric across all relevant pods, as a raw value (instead of as
408         // a percentage of the request), similar to the "pods" metric source type.
409         // It will always be set, regardless of the corresponding metric specification.
410         CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,3,name=currentAverageValue"`
411 }
412
413 // ExternalMetricStatus indicates the current value of a global metric
414 // not associated with any Kubernetes object.
415 type ExternalMetricStatus struct {
416         // metricName is the name of a metric used for autoscaling in
417         // metric system.
418         MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
419         // metricSelector is used to identify a specific time series
420         // within a given metric.
421         // +optional
422         MetricSelector *metav1.LabelSelector `json:"metricSelector,omitempty" protobuf:"bytes,2,opt,name=metricSelector"`
423         // currentValue is the current value of the metric (as a quantity)
424         CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"`
425         // currentAverageValue is the current value of metric averaged over autoscaled pods.
426         // +optional
427         CurrentAverageValue *resource.Quantity `json:"currentAverageValue,omitempty" protobuf:"bytes,4,opt,name=currentAverageValue"`
428 }