diff --git a/pkg/linters/templates/README.md b/pkg/linters/templates/README.md index 8adde76b..f380b94d 100644 --- a/pkg/linters/templates/README.md +++ b/pkg/linters/templates/README.md @@ -187,12 +187,12 @@ spec: **Error:** ``` -Error: VPA updateMode cannot be 'Auto' +Error: VPA updateMode cannot be 'Auto' as it is deprecated. Please use 'InPlaceOrRecreate' instead ``` **Why updateMode: Auto is no longer supported:** -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. +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. 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. **Which mode to use instead of Auto** diff --git a/pkg/linters/templates/rules/types.go b/pkg/linters/templates/rules/types.go index 1a0bfd3d..e4e54ef1 100644 --- a/pkg/linters/templates/rules/types.go +++ b/pkg/linters/templates/rules/types.go @@ -115,11 +115,16 @@ const ( // creation and additionally can update them during the lifetime of the // pod by deleting and recreating the pod. UpdateModeRecreate UpdateMode = "Recreate" + // DEPRECATED since vpa version 1.5.1. It is now recommended to use InPlaceOrRecreate instead. // 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" + // UpdateModeInPlaceOrReacreate means that autoscaler assigns resources on pod creation + // if Kubernetes support is available, in-place resource updates are performed, + // and if it is not available, a fallback to eviction is performed. + UpdateModeInPlaceOrReacreate UpdateMode = "InPlaceOrRecreate" ) // PodResourcePolicy controls how autoscaler computes the recommended resources diff --git a/pkg/linters/templates/rules/vpa.go b/pkg/linters/templates/rules/vpa.go index bcc7b83c..70ccfb51 100644 --- a/pkg/linters/templates/rules/vpa.go +++ b/pkg/linters/templates/rules/vpa.go @@ -129,6 +129,16 @@ func fillVPAMaps( vpaUpdateModes[target] = updateMode } +// isValidUpdateMode checks if the updateMode is one of the allowed values +func isValidUpdateMode(updateMode UpdateMode) bool { + switch updateMode { + case UpdateModeOff, UpdateModeInitial, UpdateModeRecreate, UpdateModeInPlaceOrReacreate, UpdateModeAuto: + return true + default: + return false + } +} + // parseVPAResourcePolicyContainers parses VPA containers names in ResourcePolicy and check if minAllowed and maxAllowed for container is set func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList *errors.LintRuleErrorsList) (UpdateMode, set.Set, bool) { errorListObj := errorList.WithObjectID(vpaObject.Identity()).WithFilePath(vpaObject.ShortPath()) @@ -145,10 +155,6 @@ func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList * } updateMode := *v.Spec.UpdatePolicy.UpdateMode - if updateMode == UpdateModeAuto { - errorListObj.Errorf("VPA updateMode cannot be 'Auto'") - return updateMode, containers, false - } if updateMode == UpdateModeOff { return updateMode, containers, true } @@ -159,6 +165,14 @@ func parseVPAResourcePolicyContainers(vpaObject storage.StoreObject, errorList * return updateMode, containers, false } + if updateMode == UpdateModeAuto { + errorListObj.Errorf("VPA updateMode cannot be 'Auto' as it is deprecated. Please use 'InPlaceOrRecreate' instead") + } + + if !isValidUpdateMode(updateMode) { + errorListObj.Errorf("Invalid updateMode '%s'. Allowed values are: Off, Initial, Recreate, InPlaceOrRecreate", updateMode) + } + for _, cp := range v.Spec.ResourcePolicy.ContainerPolicies { if cp.MinAllowed.Cpu().IsZero() { errorListObj.Errorf("No VPA specs minAllowed.cpu is found for container %s", cp.ContainerName)