Skip to content

Commit 1ed6534

Browse files
RottenRatSinelnikov Michail
andauthored
VPA Unnecessary error fix and add updateMode value validation (#336)
Signed-off-by: Sinelnikov Michail <[email protected]> Co-authored-by: Sinelnikov Michail <[email protected]>
1 parent 75411b0 commit 1ed6534

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

pkg/linters/templates/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ spec:
187187
188188
**Error:**
189189
```
190-
Error: VPA updateMode cannot be 'Auto'
190+
Error: VPA updateMode cannot be 'Auto' as it is deprecated. Please use 'InPlaceOrRecreate' instead
191191
```
192192
193193
**Why updateMode: Auto is no longer supported:**
194194
195-
The `updateMode: Auto` is no longer supported (considered deprecated) because in the upstream `Vertical Pod Autoscaler`, this mode has been deprecated since `VPA 1.4.0` and is now an alias for `Recreate` - that is, it always works through eviction/recreation of Pods and does not provide the advantages of in-place resizing.
195+
The `updateMode: Auto` is no longer supported (considered deprecated) because in the upstream `Vertical Pod Autoscaler`, this mode has been deprecated since `VPA 1.5.1` and is now an alias for `Recreate` - that is, it always works through eviction/recreation of Pods and does not provide the advantages of in-place resizing.
196196
In `Deckhouse`, this has been fixed with a change: all `Deckhouse-managed VPAs` have been switched from `Auto` to `InPlaceOrRecreate` so that, if Kubernetes support is available, in-place resource updates are performed, and if it is not available, a fallback to eviction is performed.
197197

198198
**Which mode to use instead of Auto**

pkg/linters/templates/rules/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,16 @@ const (
115115
// creation and additionally can update them during the lifetime of the
116116
// pod by deleting and recreating the pod.
117117
UpdateModeRecreate UpdateMode = "Recreate"
118+
// DEPRECATED since vpa version 1.5.1. It is now recommended to use InPlaceOrRecreate instead.
118119
// UpdateModeAuto means that autoscaler assigns resources on pod creation
119120
// and additionally can update them during the lifetime of the pod,
120121
// using any available update method. Currently this is equivalent to
121122
// Recreate, which is the only available update method.
122123
UpdateModeAuto UpdateMode = "Auto"
124+
// UpdateModeInPlaceOrReacreate means that autoscaler assigns resources on pod creation
125+
// if Kubernetes support is available, in-place resource updates are performed,
126+
// and if it is not available, a fallback to eviction is performed.
127+
UpdateModeInPlaceOrReacreate UpdateMode = "InPlaceOrRecreate"
123128
)
124129

125130
// PodResourcePolicy controls how autoscaler computes the recommended resources

pkg/linters/templates/rules/vpa.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ func fillVPAMaps(
129129
vpaUpdateModes[target] = updateMode
130130
}
131131

132+
// isValidUpdateMode checks if the updateMode is one of the allowed values
133+
func isValidUpdateMode(updateMode UpdateMode) bool {
134+
switch updateMode {
135+
case UpdateModeOff, UpdateModeInitial, UpdateModeRecreate, UpdateModeInPlaceOrReacreate, UpdateModeAuto:
136+
return true
137+
default:
138+
return false
139+
}
140+
}
141+
132142
// parseVPAResourcePolicyContainers parses VPA containers names in ResourcePolicy and check if minAllowed and maxAllowed for container is set
133143
func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList *errors.LintRuleErrorsList) (UpdateMode, set.Set, bool) {
134144
errorListObj := errorList.WithObjectID(vpaObject.Identity()).WithFilePath(vpaObject.ShortPath())
@@ -145,10 +155,6 @@ func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList *
145155
}
146156

147157
updateMode := *v.Spec.UpdatePolicy.UpdateMode
148-
if updateMode == UpdateModeAuto {
149-
errorListObj.Errorf("VPA updateMode cannot be 'Auto'")
150-
return updateMode, containers, false
151-
}
152158
if updateMode == UpdateModeOff {
153159
return updateMode, containers, true
154160
}
@@ -159,6 +165,14 @@ func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList *
159165
return updateMode, containers, false
160166
}
161167

168+
if updateMode == UpdateModeAuto {
169+
errorListObj.Errorf("VPA updateMode cannot be 'Auto' as it is deprecated. Please use 'InPlaceOrRecreate' instead")
170+
}
171+
172+
if !isValidUpdateMode(updateMode) {
173+
errorListObj.Errorf("Invalid updateMode '%s'. Allowed values are: Off, Initial, Recreate, InPlaceOrRecreate", updateMode)
174+
}
175+
162176
for _, cp := range v.Spec.ResourcePolicy.ContainerPolicies {
163177
if cp.MinAllowed.Cpu().IsZero() {
164178
errorListObj.Errorf("No VPA specs minAllowed.cpu is found for container %s", cp.ContainerName)

0 commit comments

Comments
 (0)