1/* 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 v1 18 19import ( 20 "k8s.io/apimachinery/pkg/api/resource" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 "k8s.io/client-go/pkg/api/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: http://releases.k8s.io/HEAD/docs/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. 37type 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 53type 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=true 76 77// configuration of a horizontal pod autoscaler. 78type HorizontalPodAutoscaler struct { 79 metav1.TypeMeta `json:",inline"` 80 // Standard object metadata. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata 81 // +optional 82 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 83 84 // behaviour of autoscaler. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status. 85 // +optional 86 Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 87 88 // current information about the autoscaler. 89 // +optional 90 Status HorizontalPodAutoscalerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 91} 92 93// list of horizontal pod autoscaler objects. 94type HorizontalPodAutoscalerList struct { 95 metav1.TypeMeta `json:",inline"` 96 // Standard list metadata. 97 // +optional 98 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 99 100 // list of horizontal pod autoscaler objects. 101 Items []HorizontalPodAutoscaler `json:"items" protobuf:"bytes,2,rep,name=items"` 102} 103 104// Scale represents a scaling request for a resource. 105type Scale struct { 106 metav1.TypeMeta `json:",inline"` 107 // Standard object metadata; More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata. 108 // +optional 109 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 110 111 // defines the behavior of the scale. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status. 112 // +optional 113 Spec ScaleSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 114 115 // current status of the scale. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status. Read-only. 116 // +optional 117 Status ScaleStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 118} 119 120// ScaleSpec describes the attributes of a scale subresource. 121type ScaleSpec struct { 122 // desired number of instances for the scaled object. 123 // +optional 124 Replicas int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"` 125} 126 127// ScaleStatus represents the current status of a scale subresource. 128type ScaleStatus struct { 129 // actual number of observed instances of the scaled object. 130 Replicas int32 `json:"replicas" protobuf:"varint,1,opt,name=replicas"` 131 132 // label query over pods that should match the replicas count. This is same 133 // as the label selector but in the string format to avoid introspection 134 // by clients. The string will be in the same format as the query-param syntax. 135 // More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors 136 // +optional 137 Selector string `json:"selector,omitempty" protobuf:"bytes,2,opt,name=selector"` 138} 139 140// the types below are used in the alpha metrics annotation 141 142// MetricSourceType indicates the type of metric. 143type MetricSourceType string 144 145var ( 146 // ObjectMetricSourceType is a metric describing a kubernetes object 147 // (for example, hits-per-second on an Ingress object). 148 ObjectMetricSourceType MetricSourceType = "Object" 149 // PodsMetricSourceType is a metric describing each pod in the current scale 150 // target (for example, transactions-processed-per-second). The values 151 // will be averaged together before being compared to the target value. 152 PodsMetricSourceType MetricSourceType = "Pods" 153 // ResourceMetricSourceType is a resource metric known to Kubernetes, as 154 // specified in requests and limits, describing each pod in the current 155 // scale target (e.g. CPU or memory). Such metrics are built in to 156 // Kubernetes, and have special scaling options on top of those available 157 // to normal per-pod metrics (the "pods" source). 158 ResourceMetricSourceType MetricSourceType = "Resource" 159) 160 161// MetricSpec specifies how to scale based on a single metric 162// (only `type` and one other matching field should be set at once). 163type MetricSpec struct { 164 // type is the type of metric source. It should match one of the fields below. 165 Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"` 166 167 // object refers to a metric describing a single kubernetes object 168 // (for example, hits-per-second on an Ingress object). 169 // +optional 170 Object *ObjectMetricSource `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"` 171 // pods refers to a metric describing each pod in the current scale target 172 // (for example, transactions-processed-per-second). The values will be 173 // averaged together before being compared to the target value. 174 // +optional 175 Pods *PodsMetricSource `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"` 176 // resource refers to a resource metric (such as those specified in 177 // requests and limits) known to Kubernetes describing each pod in the 178 // current scale target (e.g. CPU or memory). Such metrics are built in to 179 // Kubernetes, and have special scaling options on top of those available 180 // to normal per-pod metrics using the "pods" source. 181 // +optional 182 Resource *ResourceMetricSource `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"` 183} 184 185// ObjectMetricSource indicates how to scale on a metric describing a 186// kubernetes object (for example, hits-per-second on an Ingress object). 187type ObjectMetricSource struct { 188 // target is the described Kubernetes object. 189 Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"` 190 191 // metricName is the name of the metric in question. 192 MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"` 193 // targetValue is the target value of the metric (as a quantity). 194 TargetValue resource.Quantity `json:"targetValue" protobuf:"bytes,3,name=targetValue"` 195} 196 197// PodsMetricSource indicates how to scale on a metric describing each pod in 198// the current scale target (for example, transactions-processed-per-second). 199// The values will be averaged together before being compared to the target 200// value. 201type PodsMetricSource struct { 202 // metricName is the name of the metric in question 203 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"` 204 // targetAverageValue is the target value of the average of the 205 // metric across all relevant pods (as a quantity) 206 TargetAverageValue resource.Quantity `json:"targetAverageValue" protobuf:"bytes,2,name=targetAverageValue"` 207} 208 209// ResourceMetricSource indicates how to scale on a resource metric known to 210// Kubernetes, as specified in requests and limits, describing each pod in the 211// current scale target (e.g. CPU or memory). The values will be averaged 212// together before being compared to the target. Such metrics are built in to 213// Kubernetes, and have special scaling options on top of those available to 214// normal per-pod metrics using the "pods" source. Only one "target" type 215// should be set. 216type ResourceMetricSource struct { 217 // name is the name of the resource in question. 218 Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"` 219 // targetAverageUtilization is the target value of the average of the 220 // resource metric across all relevant pods, represented as a percentage of 221 // the requested value of the resource for the pods. 222 // +optional 223 TargetAverageUtilization *int32 `json:"targetAverageUtilization,omitempty" protobuf:"varint,2,opt,name=targetAverageUtilization"` 224 // targetAverageValue is the the target value of the average of the 225 // resource metric across all relevant pods, as a raw value (instead of as 226 // a percentage of the request), similar to the "pods" metric source type. 227 // +optional 228 TargetAverageValue *resource.Quantity `json:"targetAverageValue,omitempty" protobuf:"bytes,3,opt,name=targetAverageValue"` 229} 230 231// MetricStatus describes the last-read state of a single metric. 232type MetricStatus struct { 233 // type is the type of metric source. It will match one of the fields below. 234 Type MetricSourceType `json:"type" protobuf:"bytes,1,name=type"` 235 236 // object refers to a metric describing a single kubernetes object 237 // (for example, hits-per-second on an Ingress object). 238 // +optional 239 Object *ObjectMetricStatus `json:"object,omitempty" protobuf:"bytes,2,opt,name=object"` 240 // pods refers to a metric describing each pod in the current scale target 241 // (for example, transactions-processed-per-second). The values will be 242 // averaged together before being compared to the target value. 243 // +optional 244 Pods *PodsMetricStatus `json:"pods,omitempty" protobuf:"bytes,3,opt,name=pods"` 245 // resource refers to a resource metric (such as those specified in 246 // requests and limits) known to Kubernetes describing each pod in the 247 // current scale target (e.g. CPU or memory). Such metrics are built in to 248 // Kubernetes, and have special scaling options on top of those available 249 // to normal per-pod metrics using the "pods" source. 250 // +optional 251 Resource *ResourceMetricStatus `json:"resource,omitempty" protobuf:"bytes,4,opt,name=resource"` 252} 253 254// ObjectMetricStatus indicates the current value of a metric describing a 255// kubernetes object (for example, hits-per-second on an Ingress object). 256type ObjectMetricStatus struct { 257 // target is the described Kubernetes object. 258 Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"` 259 260 // metricName is the name of the metric in question. 261 MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"` 262 // currentValue is the current value of the metric (as a quantity). 263 CurrentValue resource.Quantity `json:"currentValue" protobuf:"bytes,3,name=currentValue"` 264} 265 266// PodsMetricStatus indicates the current value of a metric describing each pod in 267// the current scale target (for example, transactions-processed-per-second). 268type PodsMetricStatus struct { 269 // metricName is the name of the metric in question 270 MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"` 271 // currentAverageValue is the current value of the average of the 272 // metric across all relevant pods (as a quantity) 273 CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,2,name=currentAverageValue"` 274} 275 276// ResourceMetricStatus indicates the current value of a resource metric known to 277// Kubernetes, as specified in requests and limits, describing each pod in the 278// current scale target (e.g. CPU or memory). Such metrics are built in to 279// Kubernetes, and have special scaling options on top of those available to 280// normal per-pod metrics using the "pods" source. 281type ResourceMetricStatus struct { 282 // name is the name of the resource in question. 283 Name v1.ResourceName `json:"name" protobuf:"bytes,1,name=name"` 284 // currentAverageUtilization is the current value of the average of the 285 // resource metric across all relevant pods, represented as a percentage of 286 // the requested value of the resource for the pods. It will only be 287 // present if `targetAverageValue` was set in the corresponding metric 288 // specification. 289 // +optional 290 CurrentAverageUtilization *int32 `json:"currentAverageUtilization,omitempty" protobuf:"bytes,2,opt,name=currentAverageUtilization"` 291 // currentAverageValue is the the current value of the average of the 292 // resource metric across all relevant pods, as a raw value (instead of as 293 // a percentage of the request), similar to the "pods" metric source type. 294 // It will always be set, regardless of the corresponding metric specification. 295 CurrentAverageValue resource.Quantity `json:"currentAverageValue" protobuf:"bytes,3,name=currentAverageValue"` 296} 297