Skip to content

Commit 4f0b0b3

Browse files
committed
Introduce API changes and fetaure gate CPU startup boost
1 parent 2289138 commit 4f0b0b3

File tree

6 files changed

+451
-0
lines changed

6 files changed

+451
-0
lines changed

vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,94 @@ spec:
372372
- Auto
373373
- "Off"
374374
type: string
375+
startupBoost:
376+
description: |-
377+
StartupBoost specifies the startup boost policy for the container.
378+
This overrides any pod-level startup boost policy.
379+
properties:
380+
cpu:
381+
description: |-
382+
CPU specifies the CPU startup boost policy.
383+
If this field is not set, no startup boost is applied.
384+
properties:
385+
duration:
386+
description: |-
387+
Duration indicates for how long to keep the pod boosted after it goes to Ready.
388+
Defaults to 0s.
389+
type: string
390+
factor:
391+
description: |-
392+
Factor specifies the factor to apply to the CPU request.
393+
This field is to be used only when Type is "Factor".
394+
format: int32
395+
type: integer
396+
quantity:
397+
anyOf:
398+
- type: integer
399+
- type: string
400+
description: |-
401+
Quantity specifies the absolute CPU resource quantity.
402+
This field is to be used only when Type is "Quantity".
403+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
404+
x-kubernetes-int-or-string: true
405+
type:
406+
description: |-
407+
Type specifies the kind of boost to apply.
408+
Supported values are: "Factor", "Quantity".
409+
Defaults to "Factor".
410+
enum:
411+
- Factor
412+
- Quantity
413+
type: string
414+
required:
415+
- type
416+
type: object
417+
type: object
375418
type: object
376419
type: array
377420
type: object
421+
startupBoost:
422+
description: StartupBoost specifies the startup boost policy for the
423+
pod.
424+
properties:
425+
cpu:
426+
description: |-
427+
CPU specifies the CPU startup boost policy.
428+
If this field is not set, no startup boost is applied.
429+
properties:
430+
duration:
431+
description: |-
432+
Duration indicates for how long to keep the pod boosted after it goes to Ready.
433+
Defaults to 0s.
434+
type: string
435+
factor:
436+
description: |-
437+
Factor specifies the factor to apply to the CPU request.
438+
This field is to be used only when Type is "Factor".
439+
format: int32
440+
type: integer
441+
quantity:
442+
anyOf:
443+
- type: integer
444+
- type: string
445+
description: |-
446+
Quantity specifies the absolute CPU resource quantity.
447+
This field is to be used only when Type is "Quantity".
448+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
449+
x-kubernetes-int-or-string: true
450+
type:
451+
description: |-
452+
Type specifies the kind of boost to apply.
453+
Supported values are: "Factor", "Quantity".
454+
Defaults to "Factor".
455+
enum:
456+
- Factor
457+
- Quantity
458+
type: string
459+
required:
460+
- type
461+
type: object
462+
type: object
378463
targetRef:
379464
description: |-
380465
TargetRef points to the controller managing the set of pods for the

vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,16 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
163163
return fmt.Errorf("controlledValues shouldn't be specified if container scaling mode is off")
164164
}
165165
}
166+
if err := validateStartupBoost(policy.StartupBoost, isCreate); err != nil {
167+
return fmt.Errorf("invalid startupBoost in container %s: %v", policy.ContainerName, err)
168+
}
166169
}
167170
}
168171

172+
if err := validateStartupBoost(vpa.Spec.StartupBoost, isCreate); err != nil {
173+
return fmt.Errorf("invalid startupBoost: %v", err)
174+
}
175+
169176
if isCreate && vpa.Spec.TargetRef == nil {
170177
return fmt.Errorf("targetRef is required. If you're using v1beta1 version of the API, please migrate to v1")
171178
}
@@ -177,6 +184,49 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
177184
return nil
178185
}
179186

187+
func validateStartupBoost(startupBoost *vpa_types.StartupBoost, isCreate bool) error {
188+
if startupBoost == nil {
189+
return nil
190+
}
191+
192+
if !features.Enabled(features.CPUStartupBoost) && isCreate {
193+
return fmt.Errorf("in order to use startupBoost, you must enable feature gate %s in the admission-controller args", features.CPUStartupBoost)
194+
}
195+
196+
cpuBoost := startupBoost.CPU
197+
if cpuBoost == nil {
198+
return nil
199+
}
200+
boostType := cpuBoost.Type
201+
if boostType == nil {
202+
// Default to Factor when type is not specified.
203+
defaultType := vpa_types.FactorStartupBoostType
204+
boostType = &defaultType
205+
}
206+
207+
if *boostType != vpa_types.FactorStartupBoostType && *boostType != vpa_types.QuantityStartupBoostType {
208+
return fmt.Errorf("unexpected StartupBoost.CPU.Type value %s", *boostType)
209+
}
210+
211+
if *boostType == vpa_types.FactorStartupBoostType {
212+
if cpuBoost.Factor == nil {
213+
return fmt.Errorf("StartupBoost.CPU.Factor is required when Type is Factor")
214+
}
215+
if *cpuBoost.Factor < 1 {
216+
return fmt.Errorf("invalid StartupBoost.CPU.Factor: must be >= 1 for Type Factor")
217+
}
218+
} else if *boostType == vpa_types.QuantityStartupBoostType {
219+
if cpuBoost.Quantity == nil {
220+
return fmt.Errorf("StartupBoost.CPU.Quantity is required when Type is Quantity")
221+
}
222+
if err := validateCPUResolution(*cpuBoost.Quantity); err != nil {
223+
return fmt.Errorf("invalid StartupBoost.CPU.Quantity: %v", err)
224+
}
225+
}
226+
println("NO ERROR")
227+
return nil
228+
}
229+
180230
func validateResourceResolution(name corev1.ResourceName, val apires.Quantity) error {
181231
switch name {
182232
case corev1.ResourceCPU:

0 commit comments

Comments
 (0)