Skip to content

Commit 787da72

Browse files
committed
add updatemode check
Signed-off-by: Sinelnikov Michail <mikhail.sinelnikov@flant.com>
1 parent 454ca9a commit 787da72

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

pkg/linters/templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Error: VPA updateMode cannot be 'Auto'
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: 14 additions & 0 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:
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())
@@ -159,6 +169,10 @@ func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList *
159169
errorListObj.Errorf("VPA updateMode cannot be 'Auto'")
160170
}
161171

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)