Skip to content

Commit 7819a2b

Browse files
committed
address raywainman and omerap12 comments
Signed-off-by: Max Cao <[email protected]>
1 parent ed9358c commit 7819a2b

File tree

4 files changed

+46
-43
lines changed

4 files changed

+46
-43
lines changed

vertical-pod-autoscaler/pkg/updater/inplace/inplace_updated.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828

2929
type inPlaceUpdate struct{}
3030

31+
// CalculatePatches returns a patch that adds a "vpaInPlaceUpdated" annotation
32+
// to the pod, marking it as having been requested to be updated in-place by VPA.
3133
func (*inPlaceUpdate) CalculatePatches(pod *core.Pod, _ *vpa_types.VerticalPodAutoscaler) ([]resource_admission.PatchRecord, error) {
3234
vpaInPlaceUpdatedValue := annotations.GetVpaInPlaceUpdatedValue()
3335
return []resource_admission.PatchRecord{patch.GetAddAnnotationPatch(annotations.VpaInPlaceUpdatedLabel, vpaInPlaceUpdatedValue)}, nil

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (u *updater) RunOnce(ctx context.Context) {
252252
podsForInPlace = u.getPodsUpdateOrder(filterNonInPlaceUpdatablePods(livePods, inPlaceLimiter), vpa)
253253
inPlaceUpdatablePodsCounter.Add(vpaSize, len(podsForInPlace))
254254
} else {
255+
// If the feature gate is not enabled but update mode is InPlaceOrRecreate, updater will always fallback to eviction.
255256
if updateMode == vpa_types.UpdateModeInPlaceOrRecreate {
256257
klog.InfoS("Warning: feature gate is not enabled for this updateMode", "featuregate", features.InPlaceOrRecreate, "updateMode", vpa_types.UpdateModeInPlaceOrRecreate)
257258
}
@@ -283,7 +284,7 @@ func (u *updater) RunOnce(ctx context.Context) {
283284
err := inPlaceLimiter.InPlaceUpdate(pod, vpa, u.eventRecorder)
284285
if err != nil {
285286
klog.V(0).InfoS("In-place update failed", "error", err, "pod", klog.KObj(pod))
286-
return
287+
continue
287288
}
288289
withInPlaceUpdated = true
289290
metrics_updater.AddInPlaceUpdatedPod(vpaSize)

vertical-pod-autoscaler/pkg/updater/restriction/pods_inplace_restriction.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,45 @@ func (ip *PodsInPlaceRestrictionImpl) InPlaceUpdate(podToUpdate *apiv1.Pod, vpa
174174

175175
return nil
176176
}
177+
178+
// CanEvictInPlacingPod checks if the pod can be evicted while it is currently in the middle of an in-place update.
179+
func CanEvictInPlacingPod(pod *apiv1.Pod, singleGroupStats singleGroupStats, lastInPlaceAttemptTimeMap map[string]time.Time, clock clock.Clock) bool {
180+
if !isInPlaceUpdating(pod) {
181+
return false
182+
}
183+
lastUpdate, exists := lastInPlaceAttemptTimeMap[getPodID(pod)]
184+
if !exists {
185+
klog.V(4).InfoS("In-place update in progress for pod but no lastUpdateTime found, setting it to now", "pod", klog.KObj(pod))
186+
lastUpdate = clock.Now()
187+
lastInPlaceAttemptTimeMap[getPodID(pod)] = lastUpdate
188+
}
189+
190+
if singleGroupStats.isPodDisruptable() {
191+
// TODO(maxcao13): fix this after 1.33 KEP changes
192+
// if currently inPlaceUpdating, we should only fallback to eviction if the update has failed. i.e: one of the following conditions:
193+
// 1. .status.resize: Infeasible
194+
// 2. .status.resize: Deferred + more than 5 minutes has elapsed since the lastInPlaceUpdateTime
195+
// 3. .status.resize: InProgress + more than 1 hour has elapsed since the lastInPlaceUpdateTime
196+
switch pod.Status.Resize {
197+
case apiv1.PodResizeStatusDeferred:
198+
if clock.Since(lastUpdate) > DeferredResizeUpdateTimeout {
199+
klog.V(4).InfoS(fmt.Sprintf("In-place update deferred for more than %v, falling back to eviction", DeferredResizeUpdateTimeout), "pod", klog.KObj(pod))
200+
return true
201+
}
202+
case apiv1.PodResizeStatusInProgress:
203+
if clock.Since(lastUpdate) > InProgressResizeUpdateTimeout {
204+
klog.V(4).InfoS(fmt.Sprintf("In-place update in progress for more than %v, falling back to eviction", InProgressResizeUpdateTimeout), "pod", klog.KObj(pod))
205+
return true
206+
}
207+
case apiv1.PodResizeStatusInfeasible:
208+
klog.V(4).InfoS("In-place update infeasible, falling back to eviction", "pod", klog.KObj(pod))
209+
return true
210+
default:
211+
klog.V(4).InfoS("In-place update status unknown, falling back to eviction", "pod", klog.KObj(pod))
212+
return true
213+
}
214+
return false
215+
}
216+
klog.V(4).InfoS("Would be able to evict, but already resizing", "pod", klog.KObj(pod))
217+
return false
218+
}

vertical-pod-autoscaler/pkg/updater/restriction/pods_restriction_factory.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -350,45 +350,3 @@ func (s *singleGroupStats) isPodDisruptable() bool {
350350
func isInPlaceUpdating(podToCheck *apiv1.Pod) bool {
351351
return podToCheck.Status.Resize != ""
352352
}
353-
354-
// CanEvictInPlacingPod checks if the pod can be evicted while it is currently in the middle of an in-place update.
355-
func CanEvictInPlacingPod(pod *apiv1.Pod, singleGroupStats singleGroupStats, lastInPlaceAttemptTimeMap map[string]time.Time, clock clock.Clock) bool {
356-
if !isInPlaceUpdating(pod) {
357-
return false
358-
}
359-
lastUpdate, exists := lastInPlaceAttemptTimeMap[getPodID(pod)]
360-
if !exists {
361-
klog.V(4).InfoS("In-place update in progress for pod but no lastUpdateTime found, setting it to now", "pod", klog.KObj(pod))
362-
lastUpdate = clock.Now()
363-
lastInPlaceAttemptTimeMap[getPodID(pod)] = lastUpdate
364-
}
365-
366-
if singleGroupStats.isPodDisruptable() {
367-
// TODO(maxcao13): fix this after 1.33 KEP changes
368-
// if currently inPlaceUpdating, we should only fallback to eviction if the update has failed. i.e: one of the following conditions:
369-
// 1. .status.resize: Infeasible
370-
// 2. .status.resize: Deferred + more than 5 minutes has elapsed since the lastInPlaceUpdateTime
371-
// 3. .status.resize: InProgress + more than 1 hour has elapsed since the lastInPlaceUpdateTime
372-
switch pod.Status.Resize {
373-
case apiv1.PodResizeStatusDeferred:
374-
if clock.Since(lastUpdate) > DeferredResizeUpdateTimeout {
375-
klog.V(4).InfoS(fmt.Sprintf("In-place update deferred for more than %v, falling back to eviction", DeferredResizeUpdateTimeout), "pod", klog.KObj(pod))
376-
return true
377-
}
378-
case apiv1.PodResizeStatusInProgress:
379-
if clock.Since(lastUpdate) > InProgressResizeUpdateTimeout {
380-
klog.V(4).InfoS(fmt.Sprintf("In-place update in progress for more than %v, falling back to eviction", InProgressResizeUpdateTimeout), "pod", klog.KObj(pod))
381-
return true
382-
}
383-
case apiv1.PodResizeStatusInfeasible:
384-
klog.V(4).InfoS("In-place update infeasible, falling back to eviction", "pod", klog.KObj(pod))
385-
return true
386-
default:
387-
klog.V(4).InfoS("In-place update status unknown, falling back to eviction", "pod", klog.KObj(pod))
388-
return true
389-
}
390-
return false
391-
}
392-
klog.V(4).InfoS("Would be able to evict, but already resizing", "pod", klog.KObj(pod))
393-
return false
394-
}

0 commit comments

Comments
 (0)