From 7d13fc82ee0df90a87a5ce4413d7dbdd1d1e4a8e Mon Sep 17 00:00:00 2001 From: Ismail Alidzhikov Date: Fri, 7 Jun 2024 13:05:30 +0300 Subject: [PATCH] vpa-updater: Log the Pod namespace when evicting a Pod --- .../updater/eviction/pods_eviction_restriction.go | 10 +++++----- .../pkg/updater/logic/updater.go | 10 +++++----- .../updater/priority/update_priority_calculator.go | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/vertical-pod-autoscaler/pkg/updater/eviction/pods_eviction_restriction.go b/vertical-pod-autoscaler/pkg/updater/eviction/pods_eviction_restriction.go index 5777cfdc36e1..2ef319a96f2f 100644 --- a/vertical-pod-autoscaler/pkg/updater/eviction/pods_eviction_restriction.go +++ b/vertical-pod-autoscaler/pkg/updater/eviction/pods_eviction_restriction.go @@ -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/%s: not in replicated pods map", podToEvict.Namespace, podToEvict.Name) } if !e.CanEvict(podToEvict) { - return fmt.Errorf("cannot evict pod %v : eviction budget exceeded", podToEvict.Name) + return fmt.Errorf("cannot evict pod %s/%s: eviction budget exceeded", podToEvict.Namespace, podToEvict.Name) } eviction := &policyv1.Eviction{ @@ -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 { @@ -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 { diff --git a/vertical-pod-autoscaler/pkg/updater/logic/updater.go b/vertical-pod-autoscaler/pkg/updater/logic/updater.go index a2c44f965c0d..7e9c7f8a1e2f 100644 --- a/vertical-pod-autoscaler/pkg/updater/logic/updater.go +++ b/vertical-pod-autoscaler/pkg/updater/logic/updater.go @@ -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 } @@ -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) diff --git a/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go b/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go index d47a4ae9f516..00ac6326b063 100644 --- a/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go +++ b/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go @@ -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 } @@ -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) } } @@ -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,