Skip to content

Commit

Permalink
vpa-updater: Log the Pod namespace when evicting a Pod
Browse files Browse the repository at this point in the history
  • Loading branch information
ialidzhikov committed Jun 7, 2024
1 parent bd8153b commit e3c8f4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ func (e *podsEvictionRestrictionImpl) CanEvict(pod *apiv1.Pod) bool {
func (e *podsEvictionRestrictionImpl) Evict(podToEvict *apiv1.Pod, eventRecorder record.EventRecorder) error {
cr, present := e.podToReplicaCreatorMap[getPodID(podToEvict)]
if !present {
return fmt.Errorf("pod not suitable for eviction %v : not in replicated pods map", podToEvict.Name)
return fmt.Errorf("pod not suitable for eviction %s: not in replicated pods map", klog.KObj(podToEvict))
}

if !e.CanEvict(podToEvict) {
return fmt.Errorf("cannot evict pod %v : eviction budget exceeded", podToEvict.Name)
return fmt.Errorf("cannot evict pod %s: eviction budget exceeded", klog.KObj(podToEvict))
}

eviction := &policyv1.Eviction{
Expand All @@ -140,7 +140,7 @@ func (e *podsEvictionRestrictionImpl) Evict(podToEvict *apiv1.Pod, eventRecorder
}
err := e.client.CoreV1().Pods(podToEvict.Namespace).EvictV1(context.TODO(), eviction)
if err != nil {
klog.Errorf("failed to evict pod %s/%s, error: %v", podToEvict.Namespace, podToEvict.Name, err)
klog.Errorf("failed to evict pod %s, error: %v", klog.KObj(podToEvict), err)
return err
}
eventRecorder.Event(podToEvict, apiv1.EventTypeNormal, "EvictedByVPA",
Expand Down Expand Up @@ -199,7 +199,7 @@ func (f *podsEvictionRestrictionFactoryImpl) NewPodsEvictionRestriction(pods []*
for _, pod := range pods {
creator, err := getPodReplicaCreator(pod)
if err != nil {
klog.Errorf("failed to obtain replication info for pod %s: %v", pod.Name, err)
klog.Errorf("failed to obtain replication info for pod %s: %v", klog.KObj(pod), err)
continue
}
if creator == nil {
Expand All @@ -216,8 +216,8 @@ func (f *podsEvictionRestrictionFactoryImpl) NewPodsEvictionRestriction(pods []*
required := f.minReplicas
if vpa.Spec.UpdatePolicy != nil && vpa.Spec.UpdatePolicy.MinReplicas != nil {
required = int(*vpa.Spec.UpdatePolicy.MinReplicas)
klog.V(3).Infof("overriding minReplicas from global %v to per-VPA %v for VPA %v/%v",
f.minReplicas, required, vpa.Namespace, vpa.Name)
klog.V(3).Infof("overriding minReplicas from global %v to per-VPA %v for VPA %s",
f.minReplicas, required, klog.KObj(vpa))
}

for creator, replicas := range livePods {
Expand Down
10 changes: 5 additions & 5 deletions vertical-pod-autoscaler/pkg/updater/logic/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func (u *updater) RunOnce(ctx context.Context) {
for _, vpa := range vpaList {
if vpa_api_util.GetUpdateMode(vpa) != vpa_types.UpdateModeRecreate &&
vpa_api_util.GetUpdateMode(vpa) != vpa_types.UpdateModeAuto {
klog.V(3).Infof("skipping VPA object %v because its mode is not \"Recreate\" or \"Auto\"", vpa.Name)
klog.V(3).Infof("skipping VPA object %s because its mode is not \"Recreate\" or \"Auto\"", klog.KObj(vpa))
continue
}
selector, err := u.selectorFetcher.Fetch(vpa)
if err != nil {
klog.V(3).Infof("skipping VPA object %v because we cannot fetch selector", vpa.Name)
klog.V(3).Infof("skipping VPA object %s because we cannot fetch selector", klog.KObj(vpa))
continue
}

Expand Down Expand Up @@ -214,13 +214,13 @@ func (u *updater) RunOnce(ctx context.Context) {
}
err := u.evictionRateLimiter.Wait(ctx)
if err != nil {
klog.Warningf("evicting pod %v failed: %v", pod.Name, err)
klog.Warningf("evicting pod %s failed: %v", klog.KObj(pod), err)
return
}
klog.V(2).Infof("evicting pod %v", pod.Name)
klog.V(2).Infof("evicting pod %s", klog.KObj(pod))
evictErr := evictionLimiter.Evict(pod, u.eventRecorder)
if evictErr != nil {
klog.Warningf("evicting pod %v failed: %v", pod.Name, evictErr)
klog.Warningf("evicting pod %s failed: %v", klog.KObj(pod), evictErr)
} else {
withEvicted = true
metrics_updater.AddEvictedPod(vpaSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewUpdatePriorityCalculator(vpa *vpa_types.VerticalPodAutoscaler,
func (calc *UpdatePriorityCalculator) AddPod(pod *apiv1.Pod, now time.Time) {
processedRecommendation, _, err := calc.recommendationProcessor.Apply(calc.vpa.Status.Recommendation, calc.vpa.Spec.ResourcePolicy, calc.vpa.Status.Conditions, pod)
if err != nil {
klog.V(2).Infof("cannot process recommendation for pod %s/%s: %v", pod.Namespace, pod.Name, err)
klog.V(2).Infof("cannot process recommendation for pod %s: %v", klog.KObj(pod), err)
return
}

Expand Down Expand Up @@ -114,7 +114,7 @@ func (calc *UpdatePriorityCalculator) AddPod(pod *apiv1.Pod, now time.Time) {
terminationState.Terminated.Reason == "OOMKilled" &&
terminationState.Terminated.FinishedAt.Time.Sub(terminationState.Terminated.StartedAt.Time) < *evictAfterOOMThreshold {
quickOOM = true
klog.V(2).Infof("quick OOM detected in pod %v/%v, container %v", pod.Namespace, pod.Name, cs.Name)
klog.V(2).Infof("quick OOM detected in pod %s, container %v", klog.KObj(pod), cs.Name)
}
}

Expand All @@ -125,25 +125,25 @@ func (calc *UpdatePriorityCalculator) AddPod(pod *apiv1.Pod, now time.Time) {
if !updatePriority.OutsideRecommendedRange && !quickOOM {
if pod.Status.StartTime == nil {
// TODO: Set proper condition on the VPA.
klog.V(4).Infof("not updating pod %v/%v, missing field pod.Status.StartTime", pod.Namespace, pod.Name)
klog.V(4).Infof("not updating pod %s, missing field pod.Status.StartTime", klog.KObj(pod))
return
}
if now.Before(pod.Status.StartTime.Add(*podLifetimeUpdateThreshold)) {
klog.V(4).Infof("not updating a short-lived pod %v/%v, request within recommended range", pod.Namespace, pod.Name)
klog.V(4).Infof("not updating a short-lived pod %s, request within recommended range", klog.KObj(pod))
return
}
if updatePriority.ResourceDiff < calc.config.MinChangePriority {
klog.V(4).Infof("not updating pod %v/%v, resource diff too low: %v", pod.Namespace, pod.Name, updatePriority)
klog.V(4).Infof("not updating pod %s, resource diff too low: %v", klog.KObj(pod), updatePriority)
return
}
}

// If the pod has quick OOMed then evict only if the resources will change
if quickOOM && updatePriority.ResourceDiff == 0 {
klog.V(4).Infof("not updating pod %v/%v because resource would not change", pod.Namespace, pod.Name)
klog.V(4).Infof("not updating pod %s because resource would not change", klog.KObj(pod))
return
}
klog.V(2).Infof("pod accepted for update %v/%v with priority %v - processed recommendations:\n%v", pod.Namespace, pod.Name, updatePriority.ResourceDiff, calc.GetProcessedRecommendationTargets(processedRecommendation))
klog.V(2).Infof("pod accepted for update %s with priority %v - processed recommendations:\n%v", klog.KObj(pod), updatePriority.ResourceDiff, calc.GetProcessedRecommendationTargets(processedRecommendation))
calc.pods = append(calc.pods, prioritizedPod{
pod: pod,
priority: updatePriority,
Expand Down

0 comments on commit e3c8f4c

Please sign in to comment.