@@ -43,6 +43,7 @@ import (
43
43
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
44
44
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned/scheme"
45
45
vpa_lister "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/listers/autoscaling.k8s.io/v1"
46
+ "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
46
47
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target"
47
48
controllerfetcher "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/controller_fetcher"
48
49
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/updater/eviction"
@@ -235,28 +236,34 @@ func (u *updater) RunOnce(ctx context.Context) {
235
236
vpaSize := len (livePods )
236
237
controlledPodsCounter .Add (vpaSize , vpaSize )
237
238
evictionLimiter := u .evictionFactory .NewPodsEvictionRestriction (livePods , vpa , u .patchCalculators )
238
- podsForUpdate := u .getPodsUpdateOrder (filterNonEvictablePods (livePods , evictionLimiter ), vpa )
239
+ podsForUpdate := u .getPodsUpdateOrder (filterNonUpdatablePods (livePods , evictionLimiter ), vpa )
239
240
evictablePodsCounter .Add (vpaSize , len (podsForUpdate ))
240
241
241
242
withInPlaceUpdatable := false
242
243
withInPlaceUpdated := false
243
244
withEvictable := false
244
245
withEvicted := false
245
246
247
+ logDisabledFeatureGate := false
248
+
246
249
for _ , pod := range podsForUpdate {
247
250
if vpa_api_util .GetUpdateMode (vpa ) == vpa_types .UpdateModeInPlaceOrRecreate {
248
- withInPlaceUpdatable = true
249
- fallBackToEviction , err := u .AttemptInPlaceUpdate (ctx , vpa , pod , evictionLimiter )
250
- if err != nil {
251
- klog .V (0 ).InfoS ("In-place update failed" , "error" , err , "pod" , klog .KObj (pod ))
252
- return
253
- }
254
- if fallBackToEviction {
255
- klog .V (4 ).InfoS ("Falling back to eviction for pod" , "pod" , klog .KObj (pod ))
251
+ if features .Enabled (features .InPlaceVerticalScaling ) {
252
+ withInPlaceUpdatable = true
253
+ fallBackToEviction , err := u .AttemptInPlaceUpdate (ctx , vpa , pod , evictionLimiter )
254
+ if err != nil {
255
+ klog .V (0 ).InfoS ("In-place update failed" , "error" , err , "pod" , klog .KObj (pod ))
256
+ return
257
+ }
258
+ if fallBackToEviction {
259
+ klog .V (4 ).InfoS ("Falling back to eviction for pod" , "pod" , klog .KObj (pod ))
260
+ } else {
261
+ withInPlaceUpdated = true
262
+ metrics_updater .AddInPlaceUpdatedPod (vpaSize )
263
+ continue
264
+ }
256
265
} else {
257
- withInPlaceUpdated = true
258
- metrics_updater .AddInPlaceUpdatedPod (vpaSize )
259
- continue
266
+ logDisabledFeatureGate = true
260
267
}
261
268
}
262
269
@@ -291,6 +298,9 @@ func (u *updater) RunOnce(ctx context.Context) {
291
298
if withEvicted {
292
299
vpasWithEvictedPodsCounter .Add (vpaSize , 1 )
293
300
}
301
+ if logDisabledFeatureGate {
302
+ klog .InfoS ("Warning: feature gate is not enabled for this updateMode" , "featuregate" , features .InPlaceVerticalScaling , "updateMode" , vpa_types .UpdateModeInPlaceOrRecreate )
303
+ }
294
304
}
295
305
timer .ObserveStep ("EvictPods" )
296
306
}
@@ -323,10 +333,10 @@ func (u *updater) getPodsUpdateOrder(pods []*apiv1.Pod, vpa *vpa_types.VerticalP
323
333
return priorityCalculator .GetSortedPods (u .evictionAdmission )
324
334
}
325
335
326
- func filterNonEvictablePods (pods []* apiv1.Pod , evictionRestriction eviction.PodsEvictionRestriction ) []* apiv1.Pod {
336
+ func filterNonUpdatablePods (pods []* apiv1.Pod , evictionRestriction eviction.PodsEvictionRestriction ) []* apiv1.Pod {
327
337
result := make ([]* apiv1.Pod , 0 )
328
338
for _ , pod := range pods {
329
- if evictionRestriction .CanEvict (pod ) {
339
+ if evictionRestriction .CanEvict (pod ) || evictionRestriction . CanInPlaceUpdate ( pod ) {
330
340
result = append (result , pod )
331
341
}
332
342
}
@@ -375,6 +385,9 @@ func newEventRecorder(kubeClient kube_client.Interface) record.EventRecorder {
375
385
}
376
386
377
387
func (u * updater ) AttemptInPlaceUpdate (ctx context.Context , vpa * vpa_types.VerticalPodAutoscaler , pod * apiv1.Pod , evictionLimiter eviction.PodsEvictionRestriction ) (fallBackToEviction bool , err error ) {
388
+ if features .Enabled (features .InPlaceVerticalScaling ) {
389
+ return false , fmt .Errorf ("can't in-place update pod, %s not enabled" , features .InPlaceVerticalScaling )
390
+ }
378
391
klog .V (4 ).InfoS ("Checking preconditions for attemping in-place update" , "pod" , klog .KObj (pod ))
379
392
if ! evictionLimiter .CanInPlaceUpdate (pod ) {
380
393
if pod .Status .QOSClass == apiv1 .PodQOSGuaranteed {
0 commit comments