Skip to content

Commit f99c5e1

Browse files
committed
address comments
1 parent 7ca3bb2 commit f99c5e1

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ import (
3636
metrics_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/metrics/admission"
3737
)
3838

39+
const (
40+
vpaGroup = "autoscaling.k8s.io"
41+
vpaResource = "verticalpodautoscalers"
42+
autoDeprecationWarning = `UpdateMode "Auto" is deprecated and will be removed in a future API version. ` +
43+
`Use explicit update modes like "Recreate", "Initial", or "InPlaceOrRecreate" instead. ` +
44+
`See https://github.com/kubernetes/autoscaler/issues/8424 for more details.`
45+
)
46+
3947
// AdmissionServer is an admission webhook server that modifies pod resources request based on VPA recommendation
4048
type AdmissionServer struct {
4149
limitsChecker limitrange.LimitRangeCalculator
@@ -71,27 +79,23 @@ func (s *AdmissionServer) addDeprecationWarnings(req *admissionv1.AdmissionReque
7179
Resource: req.Resource.Resource,
7280
}
7381

74-
if admittedGroupResource.Group != "autoscaling.k8s.io" || admittedGroupResource.Resource != "verticalpodautoscalers" {
82+
if admittedGroupResource.Group != vpaGroup || admittedGroupResource.Resource != vpaResource {
7583
return
7684
}
7785

7886
var vpa vpa_types.VerticalPodAutoscaler
7987
if err := json.Unmarshal(req.Object.Raw, &vpa); err != nil {
80-
// If we can't unmarshal, skip warning
88+
klog.V(4).InfoS("Failed to unmarshal VPA object for deprecation warning check", "err", err)
8189
return
8290
}
8391

8492
if vpa.Spec.UpdatePolicy != nil && vpa.Spec.UpdatePolicy.UpdateMode != nil &&
8593
*vpa.Spec.UpdatePolicy.UpdateMode == vpa_types.UpdateModeAuto {
8694

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-
9195
if resp.Warnings == nil {
9296
resp.Warnings = []string{}
9397
}
94-
resp.Warnings = append(resp.Warnings, warning)
98+
resp.Warnings = append(resp.Warnings, autoDeprecationWarning)
9599
}
96100
}
97101

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func logDeprecationWarnings(vpa *vpa_types.VerticalPodAutoscaler) {
5656
if vpa.Spec.UpdatePolicy != nil && vpa.Spec.UpdatePolicy.UpdateMode != nil &&
5757
*vpa.Spec.UpdatePolicy.UpdateMode == vpa_types.UpdateModeAuto {
5858

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)
59+
klog.InfoS("VPA 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'",
60+
"vpa", klog.KObj(vpa), "issue", "https://github.com/kubernetes/autoscaler/issues/8424")
6161
}
6262
}
6363

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -507,41 +507,62 @@ func TestNewEventRecorder(t *testing.T) {
507507

508508
func TestLogDeprecationWarnings(t *testing.T) {
509509
tests := []struct {
510-
name string
511-
updateMode *vpa_types.UpdateMode
510+
name string
511+
updateMode *vpa_types.UpdateMode
512+
updatePolicy *vpa_types.PodUpdatePolicy
513+
shouldLogWarning bool
512514
}{
513515
{
514-
name: "Auto mode logs deprecation warning",
515-
updateMode: &[]vpa_types.UpdateMode{vpa_types.UpdateModeAuto}[0],
516+
name: "Auto mode should trigger deprecation warning logic",
517+
updateMode: &[]vpa_types.UpdateMode{vpa_types.UpdateModeAuto}[0],
518+
shouldLogWarning: true,
516519
},
517520
{
518-
name: "Recreate mode does not log warning",
519-
updateMode: &[]vpa_types.UpdateMode{vpa_types.UpdateModeRecreate}[0],
521+
name: "Recreate mode should not trigger warning logic",
522+
updateMode: &[]vpa_types.UpdateMode{vpa_types.UpdateModeRecreate}[0],
523+
shouldLogWarning: false,
520524
},
521525
{
522-
name: "Initial mode does not log warning",
523-
updateMode: &[]vpa_types.UpdateMode{vpa_types.UpdateModeInitial}[0],
526+
name: "Initial mode should not trigger warning logic",
527+
updateMode: &[]vpa_types.UpdateMode{vpa_types.UpdateModeInitial}[0],
528+
shouldLogWarning: false,
524529
},
525530
{
526-
name: "nil update mode does not log warning",
527-
updateMode: nil,
531+
name: "nil update policy should not trigger warning logic",
532+
updatePolicy: nil,
533+
shouldLogWarning: false,
528534
},
529535
}
530536

531537
for _, tc := range tests {
532538
t.Run(tc.name, func(t *testing.T) {
539+
var updatePolicy *vpa_types.PodUpdatePolicy
540+
if tc.updatePolicy != nil {
541+
updatePolicy = tc.updatePolicy
542+
} else if tc.updateMode != nil {
543+
updatePolicy = &vpa_types.PodUpdatePolicy{
544+
UpdateMode: tc.updateMode,
545+
}
546+
}
547+
533548
vpa := &vpa_types.VerticalPodAutoscaler{
534549
ObjectMeta: metav1.ObjectMeta{
535550
Name: "test-vpa",
536551
Namespace: "default",
537552
},
538553
Spec: vpa_types.VerticalPodAutoscalerSpec{
539-
UpdatePolicy: &vpa_types.PodUpdatePolicy{
540-
UpdateMode: tc.updateMode,
541-
},
554+
UpdatePolicy: updatePolicy,
542555
},
543556
}
544557

558+
shouldLogWarning := vpa.Spec.UpdatePolicy != nil &&
559+
vpa.Spec.UpdatePolicy.UpdateMode != nil &&
560+
*vpa.Spec.UpdatePolicy.UpdateMode == vpa_types.UpdateModeAuto
561+
562+
assert.Equal(t, tc.shouldLogWarning, shouldLogWarning,
563+
"Expected shouldLogWarning=%v for test case %s", tc.shouldLogWarning, tc.name)
564+
565+
// Call the function to ensure it doesn't panic
545566
logDeprecationWarnings(vpa)
546567
})
547568
}

0 commit comments

Comments
 (0)