/
types.go
424 lines (364 loc) · 21.2 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package v1 contains definitions of Vertical Pod Autoscaler related objects.
package v1
import (
autoscaling "k8s.io/api/autoscaling/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// VerticalPodAutoscalerList is a list of VerticalPodAutoscaler objects.
type VerticalPodAutoscalerList struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard list metadata.
// +optional
metav1.ListMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
// items is the list of vertical pod autoscaler objects.
Items []VerticalPodAutoscaler `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:storageversion
// +kubebuilder:resource:shortName=vpa
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Mode",type="string",JSONPath=".spec.updatePolicy.updateMode"
// +kubebuilder:printcolumn:name="CPU",type="string",JSONPath=".status.recommendation.containerRecommendations[0].target.cpu"
// +kubebuilder:printcolumn:name="Mem",type="string",JSONPath=".status.recommendation.containerRecommendations[0].target.memory"
// +kubebuilder:printcolumn:name="Provided",type="string",JSONPath=".status.conditions[?(@.type=='RecommendationProvided')].status"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// VerticalPodAutoscaler is the configuration for a vertical pod
// autoscaler, which automatically manages pod resources based on historical and
// real time resource utilization.
type VerticalPodAutoscaler struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Specification of the behavior of the autoscaler.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.
Spec VerticalPodAutoscalerSpec `json:"spec" protobuf:"bytes,2,name=spec"`
// Current information about the autoscaler.
// +optional
Status VerticalPodAutoscalerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// VerticalPodAutoscalerRecommenderSelector points to a specific Vertical Pod Autoscaler recommender.
// In the future it might pass parameters to the recommender.
type VerticalPodAutoscalerRecommenderSelector struct {
// Name of the recommender responsible for generating recommendation for this object.
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
}
// VerticalPodAutoscalerSpec is the specification of the behavior of the autoscaler.
type VerticalPodAutoscalerSpec struct {
// TargetRef points to the controller managing the set of pods for the
// autoscaler to control - e.g. Deployment, StatefulSet. VerticalPodAutoscaler
// can be targeted at controller implementing scale subresource (the pod set is
// retrieved from the controller's ScaleStatus) or some well known controllers
// (e.g. for DaemonSet the pod set is read from the controller's spec).
// If VerticalPodAutoscaler cannot use specified target it will report
// ConfigUnsupported condition.
// Note that VerticalPodAutoscaler does not require full implementation
// of scale subresource - it will not use it to modify the replica count.
// The only thing retrieved is a label selector matching pods grouped by
// the target resource.
TargetRef *autoscaling.CrossVersionObjectReference `json:"targetRef" protobuf:"bytes,1,name=targetRef"`
// Describes the rules on how changes are applied to the pods.
// If not specified, all fields in the `PodUpdatePolicy` are set to their
// default values.
// +optional
UpdatePolicy *PodUpdatePolicy `json:"updatePolicy,omitempty" protobuf:"bytes,2,opt,name=updatePolicy"`
// Controls how the autoscaler computes recommended resources.
// The resource policy may be used to set constraints on the recommendations
// for individual containers.
// If any individual containers need to be excluded from getting the VPA recommendations, then
// it must be disabled explicitly by setting mode to "Off" under containerPolicies.
// If not specified, the autoscaler computes recommended resources for all containers in the pod,
// without additional constraints.
// +optional
ResourcePolicy *PodResourcePolicy `json:"resourcePolicy,omitempty" protobuf:"bytes,3,opt,name=resourcePolicy"`
// Recommender responsible for generating recommendation for this object.
// List should be empty (then the default recommender will generate the
// recommendation) or contain exactly one recommender.
// +optional
Recommenders []*VerticalPodAutoscalerRecommenderSelector `json:"recommenders,omitempty" protobuf:"bytes,4,opt,name=recommenders"`
}
// EvictionChangeRequirement refers to the relationship between the new target recommendation for a Pod and its current requests, what kind of change is necessary for the Pod to be evicted
// +kubebuilder:validation:Enum:=TargetHigherThanRequests;TargetLowerThanRequests
type EvictionChangeRequirement string
const (
// TargetHigherThanRequests means the new target recommendation for a Pod is higher than its current requests, i.e. the Pod is scaled up
TargetHigherThanRequests EvictionChangeRequirement = "TargetHigherThanRequests"
// TargetLowerThanRequests means the new target recommendation for a Pod is lower than its current requests, i.e. the Pod is scaled down
TargetLowerThanRequests EvictionChangeRequirement = "TargetLowerThanRequests"
)
// EvictionRequirement defines a single condition which needs to be true in
// order to evict a Pod
type EvictionRequirement struct {
// Resources is a list of one or more resources that the condition applies
// to. If more than one resource is given, the EvictionRequirement is fulfilled
// if at least one resource meets `changeRequirement`.
Resources []v1.ResourceName `json:"resources" protobuf:"bytes,1,name=resources"`
ChangeRequirement EvictionChangeRequirement `json:"changeRequirement" protobuf:"bytes,2,name=changeRequirement"`
}
// PodUpdatePolicy describes the rules on how changes are applied to the pods.
type PodUpdatePolicy struct {
// Controls when autoscaler applies changes to the pod resources.
// The default is 'Auto'.
// +optional
UpdateMode *UpdateMode `json:"updateMode,omitempty" protobuf:"bytes,1,opt,name=updateMode"`
// Minimal number of replicas which need to be alive for Updater to attempt
// pod eviction (pending other checks like PDB). Only positive values are
// allowed. Overrides global '--min-replicas' flag.
// +optional
MinReplicas *int32 `json:"minReplicas,omitempty" protobuf:"varint,2,opt,name=minReplicas"`
// EvictionRequirements is a list of EvictionRequirements that need to
// evaluate to true in order for a Pod to be evicted. If more than one
// EvictionRequirement is specified, all of them need to be fulfilled to allow eviction.
// +optional
EvictionRequirements []*EvictionRequirement `json:"evictionRequirements,omitempty" protobuf:"bytes,3,opt,name=evictionRequirements"`
}
// UpdateMode controls when autoscaler applies changes to the pod resources.
// +kubebuilder:validation:Enum=Off;Initial;Recreate;Auto
type UpdateMode string
const (
// UpdateModeOff means that autoscaler never changes Pod resources.
// The recommender still sets the recommended resources in the
// VerticalPodAutoscaler object. This can be used for a "dry run".
UpdateModeOff UpdateMode = "Off"
// UpdateModeInitial means that autoscaler only assigns resources on pod
// creation and does not change them during the lifetime of the pod.
UpdateModeInitial UpdateMode = "Initial"
// UpdateModeRecreate means that autoscaler assigns resources on pod
// creation and additionally can update them during the lifetime of the
// pod by deleting and recreating the pod.
UpdateModeRecreate UpdateMode = "Recreate"
// UpdateModeAuto means that autoscaler assigns resources on pod creation
// and additionally can update them during the lifetime of the pod,
// using any available update method. Currently this is equivalent to
// Recreate, which is the only available update method.
UpdateModeAuto UpdateMode = "Auto"
)
// PodResourcePolicy controls how autoscaler computes the recommended resources
// for containers belonging to the pod. There can be at most one entry for every
// named container and optionally a single wildcard entry with `containerName` = '*',
// which handles all containers that don't have individual policies.
type PodResourcePolicy struct {
// Per-container resource policies.
// +optional
// +patchMergeKey=containerName
// +patchStrategy=merge
ContainerPolicies []ContainerResourcePolicy `json:"containerPolicies,omitempty" patchStrategy:"merge" patchMergeKey:"containerName" protobuf:"bytes,1,rep,name=containerPolicies"`
}
// ContainerResourcePolicy controls how autoscaler computes the recommended
// resources for a specific container.
type ContainerResourcePolicy struct {
// Name of the container or DefaultContainerResourcePolicy, in which
// case the policy is used by the containers that don't have their own
// policy specified.
ContainerName string `json:"containerName,omitempty" protobuf:"bytes,1,opt,name=containerName"`
// Whether autoscaler is enabled for the container. The default is "Auto".
// +optional
Mode *ContainerScalingMode `json:"mode,omitempty" protobuf:"bytes,2,opt,name=mode"`
// Specifies the minimal amount of resources that will be recommended
// for the container. The default is no minimum.
// +optional
MinAllowed v1.ResourceList `json:"minAllowed,omitempty" protobuf:"bytes,3,rep,name=minAllowed,casttype=ResourceList,castkey=ResourceName"`
// Specifies the maximum amount of resources that will be recommended
// for the container. The default is no maximum.
// +optional
MaxAllowed v1.ResourceList `json:"maxAllowed,omitempty" protobuf:"bytes,4,rep,name=maxAllowed,casttype=ResourceList,castkey=ResourceName"`
// Specifies the type of recommendations that will be computed
// (and possibly applied) by VPA.
// If not specified, the default of [ResourceCPU, ResourceMemory] will be used.
ControlledResources *[]v1.ResourceName `json:"controlledResources,omitempty" patchStrategy:"merge" protobuf:"bytes,5,rep,name=controlledResources"`
// Specifies which resource values should be controlled.
// The default is "RequestsAndLimits".
// +optional
ControlledValues *ContainerControlledValues `json:"controlledValues,omitempty" protobuf:"bytes,6,rep,name=controlledValues"`
}
const (
// DefaultContainerResourcePolicy can be passed as
// ContainerResourcePolicy.ContainerName to specify the default policy.
DefaultContainerResourcePolicy = "*"
)
// ContainerScalingMode controls whether autoscaler is enabled for a specific
// container.
// +kubebuilder:validation:Enum=Auto;Off
type ContainerScalingMode string
const (
// ContainerScalingModeAuto means autoscaling is enabled for a container.
ContainerScalingModeAuto ContainerScalingMode = "Auto"
// ContainerScalingModeOff means autoscaling is disabled for a container.
ContainerScalingModeOff ContainerScalingMode = "Off"
)
// ContainerControlledValues controls which resource value should be autoscaled.
// +kubebuilder:validation:Enum=RequestsAndLimits;RequestsOnly
type ContainerControlledValues string
const (
// ContainerControlledValuesRequestsAndLimits means resource request and limits
// are scaled automatically. The limit is scaled proportionally to the request.
ContainerControlledValuesRequestsAndLimits ContainerControlledValues = "RequestsAndLimits"
// ContainerControlledValuesRequestsOnly means only requested resource is autoscaled.
ContainerControlledValuesRequestsOnly ContainerControlledValues = "RequestsOnly"
)
// VerticalPodAutoscalerStatus describes the runtime state of the autoscaler.
type VerticalPodAutoscalerStatus struct {
// The most recently computed amount of resources recommended by the
// autoscaler for the controlled pods.
// +optional
Recommendation *RecommendedPodResources `json:"recommendation,omitempty" protobuf:"bytes,1,opt,name=recommendation"`
// Conditions is the set of conditions required for this autoscaler to scale its target,
// and indicates whether or not those conditions are met.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []VerticalPodAutoscalerCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
}
// RecommendedPodResources is the recommendation of resources computed by
// autoscaler. It contains a recommendation for each container in the pod
// (except for those with `ContainerScalingMode` set to 'Off').
type RecommendedPodResources struct {
// Resources recommended by the autoscaler for each container.
// +optional
ContainerRecommendations []RecommendedContainerResources `json:"containerRecommendations,omitempty" protobuf:"bytes,1,rep,name=containerRecommendations"`
}
// RecommendedContainerResources is the recommendation of resources computed by
// autoscaler for a specific container. Respects the container resource policy
// if present in the spec. In particular the recommendation is not produced for
// containers with `ContainerScalingMode` set to 'Off'.
type RecommendedContainerResources struct {
// Name of the container.
ContainerName string `json:"containerName,omitempty" protobuf:"bytes,1,opt,name=containerName"`
// Recommended amount of resources. Observes ContainerResourcePolicy.
Target v1.ResourceList `json:"target" protobuf:"bytes,2,rep,name=target,casttype=ResourceList,castkey=ResourceName"`
// Minimum recommended amount of resources. Observes ContainerResourcePolicy.
// This amount is not guaranteed to be sufficient for the application to operate in a stable way, however
// running with less resources is likely to have significant impact on performance/availability.
// +optional
LowerBound v1.ResourceList `json:"lowerBound,omitempty" protobuf:"bytes,3,rep,name=lowerBound,casttype=ResourceList,castkey=ResourceName"`
// Maximum recommended amount of resources. Observes ContainerResourcePolicy.
// Any resources allocated beyond this value are likely wasted. This value may be larger than the maximum
// amount of application is actually capable of consuming.
// +optional
UpperBound v1.ResourceList `json:"upperBound,omitempty" protobuf:"bytes,4,rep,name=upperBound,casttype=ResourceList,castkey=ResourceName"`
// The most recent recommended resources target computed by the autoscaler
// for the controlled pods, based only on actual resource usage, not taking
// into account the ContainerResourcePolicy.
// May differ from the Recommendation if the actual resource usage causes
// the target to violate the ContainerResourcePolicy (lower than MinAllowed
// or higher that MaxAllowed).
// Used only as status indication, will not affect actual resource assignment.
// +optional
UncappedTarget v1.ResourceList `json:"uncappedTarget,omitempty" protobuf:"bytes,5,opt,name=uncappedTarget"`
}
// VerticalPodAutoscalerConditionType are the valid conditions of
// a VerticalPodAutoscaler.
type VerticalPodAutoscalerConditionType string
var (
// RecommendationProvided indicates whether the VPA recommender was able to calculate a recommendation.
RecommendationProvided VerticalPodAutoscalerConditionType = "RecommendationProvided"
// LowConfidence indicates whether the VPA recommender has low confidence in the recommendation for
// some of containers.
LowConfidence VerticalPodAutoscalerConditionType = "LowConfidence"
// NoPodsMatched indicates that label selector used with VPA object didn't match any pods.
NoPodsMatched VerticalPodAutoscalerConditionType = "NoPodsMatched"
// FetchingHistory indicates that VPA recommender is in the process of loading additional history samples.
FetchingHistory VerticalPodAutoscalerConditionType = "FetchingHistory"
// ConfigDeprecated indicates that this VPA configuration is deprecated
// and will stop being supported soon.
ConfigDeprecated VerticalPodAutoscalerConditionType = "ConfigDeprecated"
// ConfigUnsupported indicates that this VPA configuration is unsupported
// and recommendations will not be provided for it.
ConfigUnsupported VerticalPodAutoscalerConditionType = "ConfigUnsupported"
)
// VerticalPodAutoscalerCondition describes the state of
// a VerticalPodAutoscaler at a certain point.
type VerticalPodAutoscalerCondition struct {
// type describes the current condition
Type VerticalPodAutoscalerConditionType `json:"type" protobuf:"bytes,1,name=type"`
// status is the status of the condition (True, False, Unknown)
Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,name=status"`
// lastTransitionTime is the last time the condition transitioned from
// one status to another
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
// reason is the reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
// message is a human-readable explanation containing details about
// the transition
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
}
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:storageversion
// +kubebuilder:resource:shortName=vpacheckpoint
// VerticalPodAutoscalerCheckpoint is the checkpoint of the internal state of VPA that
// is used for recovery after recommender's restart.
type VerticalPodAutoscalerCheckpoint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Specification of the checkpoint.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.
// +optional
Spec VerticalPodAutoscalerCheckpointSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
// Data of the checkpoint.
// +optional
Status VerticalPodAutoscalerCheckpointStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// VerticalPodAutoscalerCheckpointList is a list of VerticalPodAutoscalerCheckpoint objects.
type VerticalPodAutoscalerCheckpointList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []VerticalPodAutoscalerCheckpoint `json:"items"`
}
// VerticalPodAutoscalerCheckpointSpec is the specification of the checkpoint object.
type VerticalPodAutoscalerCheckpointSpec struct {
// Name of the VPA object that stored VerticalPodAutoscalerCheckpoint object.
VPAObjectName string `json:"vpaObjectName,omitempty" protobuf:"bytes,1,opt,name=vpaObjectName"`
// Name of the checkpointed container.
ContainerName string `json:"containerName,omitempty" protobuf:"bytes,2,opt,name=containerName"`
}
// VerticalPodAutoscalerCheckpointStatus contains data of the checkpoint.
type VerticalPodAutoscalerCheckpointStatus struct {
// The time when the status was last refreshed.
// +nullable
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty" protobuf:"bytes,1,opt,name=lastUpdateTime"`
// Version of the format of the stored data.
Version string `json:"version,omitempty" protobuf:"bytes,2,opt,name=version"`
// Checkpoint of histogram for consumption of CPU.
CPUHistogram HistogramCheckpoint `json:"cpuHistogram,omitempty" protobuf:"bytes,3,rep,name=cpuHistograms"`
// Checkpoint of histogram for consumption of memory.
MemoryHistogram HistogramCheckpoint `json:"memoryHistogram,omitempty" protobuf:"bytes,4,rep,name=memoryHistogram"`
// Timestamp of the fist sample from the histograms.
// +nullable
FirstSampleStart metav1.Time `json:"firstSampleStart,omitempty" protobuf:"bytes,5,opt,name=firstSampleStart"`
// Timestamp of the last sample from the histograms.
// +nullable
LastSampleStart metav1.Time `json:"lastSampleStart,omitempty" protobuf:"bytes,6,opt,name=lastSampleStart"`
// Total number of samples in the histograms.
TotalSamplesCount int `json:"totalSamplesCount,omitempty" protobuf:"bytes,7,opt,name=totalSamplesCount"`
}
// HistogramCheckpoint contains data needed to reconstruct the histogram.
type HistogramCheckpoint struct {
// Reference timestamp for samples collected within this histogram.
// +nullable
ReferenceTimestamp metav1.Time `json:"referenceTimestamp,omitempty" protobuf:"bytes,1,opt,name=referenceTimestamp"`
// Map from bucket index to bucket weight.
// +kubebuilder:validation:Type=object
// +kubebuilder:validation:XPreserveUnknownFields
BucketWeights map[int]uint32 `json:"bucketWeights,omitempty" protobuf:"bytes,2,opt,name=bucketWeights"`
// Sum of samples to be used as denominator for weights from BucketWeights.
TotalWeight float64 `json:"totalWeight,omitempty" protobuf:"bytes,3,opt,name=totalWeight"`
}