Skip to content

Commit

Permalink
Merge pull request kubernetes#6908 from ialidzhikov/enh/admission-con…
Browse files Browse the repository at this point in the history
…troller-logging

vpa-admission-controller: Log object's namespace
  • Loading branch information
k8s-ci-robot authored Jun 27, 2024
2 parents 4e3cc27 + 8d19474 commit d52e4b9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (h *resourceHandler) GetPatches(ar *admissionv1.AdmissionRequest) ([]resour
pod.Name = pod.GenerateName + "%"
pod.Namespace = namespace
}
klog.V(4).Infof("Admitting pod %v", pod.ObjectMeta)
klog.V(4).Infof("Admitting pod %s", klog.KObj(&pod))
controllingVpa := h.vpaMatcher.GetMatchingVPA(&pod)
if controllingVpa == nil {
klog.V(4).Infof("No matching VPA found for pod %s/%s", pod.Namespace, pod.Name)
klog.V(4).Infof("No matching VPA found for pod %s", klog.KObj(&pod))
return []resource_admission.PatchRecord{}, nil
}
pod, err := h.preProcessor.Process(pod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *resourcesUpdatesPatchCalculator) CalculatePatches(pod *core.Pod, vpa *v

containersResources, annotationsPerContainer, err := c.recommendationProvider.GetContainersResourcesForPod(pod, vpa)
if err != nil {
return []resource_admission.PatchRecord{}, fmt.Errorf("Failed to calculate resource patch for pod %v/%v: %v", pod.Namespace, pod.Name, err)
return []resource_admission.PatchRecord{}, fmt.Errorf("Failed to calculate resource patch for pod %s/%s: %v", pod.Namespace, pod.Name, err)
}

if annotationsPerContainer == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p *recommendationProvider) GetContainersResourcesForPod(pod *core.Pod, vpa
var err error
recommendedPodResources, annotations, err = p.recommendationProcessor.Apply(vpa.Status.Recommendation, vpa.Spec.ResourcePolicy, vpa.Status.Conditions, pod)
if err != nil {
klog.V(2).Infof("cannot process recommendation for pod %s", pod.Name)
klog.V(2).Infof("cannot process recommendation for pod %s", klog.KObj(pod))
return nil, annotations, err
}
}
Expand All @@ -114,7 +114,7 @@ func (p *recommendationProvider) GetContainersResourcesForPod(pod *core.Pod, vpa
// Ensure that we are not propagating empty resource key if any.
for _, resource := range containerResources {
if resource.RemoveEmptyResourceKeyIfAny() {
klog.Infof("An empty resource key was found and purged for pod=%s/%s with vpa=", pod.Namespace, pod.Name, vpa.Name)
klog.Infof("An empty resource key was found and purged for pod=%s with vpa=%s", klog.KObj(pod), klog.KObj(vpa))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ func (m *matcher) GetMatchingVPA(pod *core.Pod) *vpa_types.VerticalPodAutoscaler
}
selector, err := m.selectorFetcher.Fetch(vpaConfig)
if err != nil {
klog.V(3).Infof("skipping VPA object %v because we cannot fetch selector: %s", vpaConfig.Name, err)
klog.V(3).Infof("skipping VPA object %s because we cannot fetch selector: %s", klog.KObj(vpaConfig), err)
continue
}
onConfigs = append(onConfigs, &vpa_api_util.VpaWithSelector{
Vpa: vpaConfig,
Selector: selector,
})
}
klog.V(2).Infof("Let's choose from %d configs for pod %s/%s", len(onConfigs), pod.Namespace, pod.Name)
klog.V(2).Infof("Let's choose from %d configs for pod %s", len(onConfigs), klog.KObj(pod))
result := vpa_api_util.GetControllingVPAForPod(pod, onConfigs, m.controllerFetcher)
if result != nil {
return result.Vpa
Expand Down
4 changes: 2 additions & 2 deletions vertical-pod-autoscaler/pkg/utils/vpa/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func GetControllingVPAForPod(pod *core.Pod, vpas []*VpaWithSelector, ctrlFetcher
}
parentController, err := ctrlFetcher.FindTopMostWellKnownOrScalable(k)
if err != nil {
klog.Errorf("fail to get pod controller: pod=%s err=%s", pod.Name, err.Error())
klog.Errorf("fail to get pod controller: pod=%s err=%s", klog.KObj(pod), err.Error())
return nil
}
if parentController == nil {
Expand Down Expand Up @@ -231,7 +231,7 @@ func CreateOrUpdateVpaCheckpoint(vpaCheckpointClient vpa_api.VerticalPodAutoscal
_, err = vpaCheckpointClient.Create(context.TODO(), vpaCheckpoint, meta.CreateOptions{})
}
if err != nil {
return fmt.Errorf("Cannot save checkpoint for vpa %v container %v. Reason: %+v", vpaCheckpoint.ObjectMeta.Name, vpaCheckpoint.Spec.ContainerName, err)
return fmt.Errorf("Cannot save checkpoint for vpa %s/%s container %s. Reason: %+v", vpaCheckpoint.Namespace, vpaCheckpoint.Name, vpaCheckpoint.Spec.ContainerName, err)
}
return nil
}

0 comments on commit d52e4b9

Please sign in to comment.