Skip to content

Commit 1d726e6

Browse files
committed
deprecate UpdateMode Auto in VPA
1 parent c12135c commit 1d726e6

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

vertical-pod-autoscaler/docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ _Appears in:_
218218
| `Off` | UpdateModeOff means that autoscaler never changes Pod resources.<br />The recommender still sets the recommended resources in the<br />VerticalPodAutoscaler object. This can be used for a "dry run".<br /> |
219219
| `Initial` | UpdateModeInitial means that autoscaler only assigns resources on pod<br />creation and does not change them during the lifetime of the pod.<br /> |
220220
| `Recreate` | UpdateModeRecreate means that autoscaler assigns resources on pod<br />creation and additionally can update them during the lifetime of the<br />pod by deleting and recreating the pod.<br /> |
221-
| `Auto` | UpdateModeAuto means that autoscaler assigns resources on pod creation<br />and additionally can update them during the lifetime of the pod,<br />using any available update method. Currently this is equivalent to<br />Recreate.<br /> |
221+
| `Auto` | **Deprecated** - UpdateModeAuto means that autoscaler assigns resources on pod creation<br />and additionally can update them during the lifetime of the pod,<br />using any available update method. Currently this is equivalent to<br />Recreate. **This mode is deprecated and will be removed in a future API version.**<br />**Use explicit modes like "Recreate", "Initial", or "InPlaceOrRecreate" instead.**<br />See [issue #8424](https://github.com/kubernetes/autoscaler/issues/8424) for more details.<br /> |
222222
| `InPlaceOrRecreate` | UpdateModeInPlaceOrRecreate means that autoscaler tries to assign resources in-place.<br />If this is not possible (e.g., resizing takes too long or is infeasible), it falls back to the<br />"Recreate" update mode.<br />Requires VPA level feature gate "InPlaceOrRecreate" to be enabled<br />on the admission and updater pods.<br />Requires cluster feature gate "InPlacePodVerticalScaling" to be enabled.<br /> |
223223

224224

vertical-pod-autoscaler/pkg/admission-controller/logic/server.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod"
3232
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch"
3333
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/vpa"
34+
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
3435
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/limitrange"
3536
metrics_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/metrics/admission"
3637
)
@@ -58,6 +59,42 @@ func (s *AdmissionServer) RegisterResourceHandler(resourceHandler resource.Handl
5859
s.resourceHandlers[resourceHandler.GroupResource()] = resourceHandler
5960
}
6061

62+
// addDeprecationWarnings adds deprecation warnings to the admission response for VPA objects using deprecated modes
63+
func (s *AdmissionServer) addDeprecationWarnings(req *admissionv1.AdmissionRequest, resp *admissionv1.AdmissionResponse) {
64+
if req.Object.Raw == nil {
65+
return
66+
}
67+
68+
// Check if this is a VPA object
69+
admittedGroupResource := metav1.GroupResource{
70+
Group: req.Resource.Group,
71+
Resource: req.Resource.Resource,
72+
}
73+
74+
if admittedGroupResource.Group != "autoscaling.k8s.io" || admittedGroupResource.Resource != "verticalpodautoscalers" {
75+
return
76+
}
77+
78+
var vpa vpa_types.VerticalPodAutoscaler
79+
if err := json.Unmarshal(req.Object.Raw, &vpa); err != nil {
80+
// If we can't unmarshal, skip warning
81+
return
82+
}
83+
84+
if vpa.Spec.UpdatePolicy != nil && vpa.Spec.UpdatePolicy.UpdateMode != nil &&
85+
*vpa.Spec.UpdatePolicy.UpdateMode == vpa_types.UpdateModeAuto {
86+
87+
warning := `UpdateMode "Auto" is deprecated and will be removed in a future API version. ` +
88+
`Use explicit update modes like "Recreate", "Initial", or "InPlaceOrRecreate" instead. ` +
89+
`See https://github.com/kubernetes/autoscaler/issues/8424 for more details.`
90+
91+
if resp.Warnings == nil {
92+
resp.Warnings = []string{}
93+
}
94+
resp.Warnings = append(resp.Warnings, warning)
95+
}
96+
}
97+
6198
func (s *AdmissionServer) admit(ctx context.Context, data []byte) (*admissionv1.AdmissionResponse, metrics_admission.AdmissionStatus, metrics_admission.AdmissionResource) {
6299
// we don't block the admission by default, even on unparsable JSON
63100
response := admissionv1.AdmissionResponse{}
@@ -124,6 +161,9 @@ func (s *AdmissionServer) admit(ctx context.Context, data []byte) (*admissionv1.
124161
metrics_admission.OnAdmittedPod(status == metrics_admission.Applied)
125162
}
126163

164+
// Add deprecation warnings for VPA objects using deprecated modes
165+
s.addDeprecationWarnings(ar.Request, &response)
166+
127167
return &response, status, resource
128168
}
129169

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ func (h *resourceHandler) GetPatches(_ context.Context, ar *v1.AdmissionRequest)
9595
patches := []resource.PatchRecord{}
9696
if vpa.Spec.UpdatePolicy == nil {
9797
// Sets the default updatePolicy.
98-
defaultUpdateMode := vpa_types.UpdateModeAuto
98+
// Changed from UpdateModeAuto to UpdateModeRecreate as part of Auto mode deprecation
99+
defaultUpdateMode := vpa_types.UpdateModeRecreate
99100
patches = append(patches, resource.PatchRecord{
100101
Op: "add",
101102
Path: "/spec/updatePolicy",

vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ const (
170170
// and additionally can update them during the lifetime of the pod,
171171
// using any available update method. Currently this is equivalent to
172172
// Recreate.
173+
// Deprecated: This value is deprecated and will be removed in a future API version.
174+
// Use explicit update modes like "Recreate", "Initial", or "InPlaceOrRecreate" instead.
175+
// See https://github.com/kubernetes/autoscaler/issues/8424 for more details.
173176
UpdateModeAuto UpdateMode = "Auto"
174177
// UpdateModeInPlaceOrRecreate means that autoscaler tries to assign resources in-place.
175178
// If this is not possible (e.g., resizing takes too long or is infeasible), it falls back to the

vertical-pod-autoscaler/pkg/updater/logic/updater.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ import (
5151
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"
5252
)
5353

54+
// logDeprecationWarnings logs deprecation warnings for VPAs using deprecated modes
55+
func logDeprecationWarnings(vpa *vpa_types.VerticalPodAutoscaler) {
56+
if vpa.Spec.UpdatePolicy != nil && vpa.Spec.UpdatePolicy.UpdateMode != nil &&
57+
*vpa.Spec.UpdatePolicy.UpdateMode == vpa_types.UpdateModeAuto {
58+
59+
klog.Warningf("VPA %s/%s uses deprecated UpdateMode 'Auto'. This mode is deprecated and will be removed in a future API version. Please use explicit update modes like 'Recreate', 'Initial', or 'InPlaceOrRecreate'. See https://github.com/kubernetes/autoscaler/issues/8424",
60+
vpa.Namespace, vpa.Name)
61+
}
62+
}
63+
5464
// Updater performs updates on pods if recommended by Vertical Pod Autoscaler
5565
type Updater interface {
5666
// RunOnce represents single iteration in the main-loop of Updater
@@ -159,6 +169,10 @@ func (u *updater) RunOnce(ctx context.Context) {
159169
klog.V(3).InfoS("Skipping VPA object in ignored namespace", "vpa", klog.KObj(vpa), "namespace", vpa.Namespace)
160170
continue
161171
}
172+
173+
// Log deprecation warnings for VPAs using deprecated modes
174+
logDeprecationWarnings(vpa)
175+
162176
if vpa_api_util.GetUpdateMode(vpa) != vpa_types.UpdateModeRecreate &&
163177
vpa_api_util.GetUpdateMode(vpa) != vpa_types.UpdateModeAuto && vpa_api_util.GetUpdateMode(vpa) != vpa_types.UpdateModeInPlaceOrRecreate {
164178
klog.V(3).InfoS("Skipping VPA object because its mode is not \"InPlaceOrRecreate\", \"Recreate\" or \"Auto\"", "vpa", klog.KObj(vpa))

0 commit comments

Comments
 (0)