Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#11233 from sbueringer/pr-log-error…
Browse files Browse the repository at this point in the history
…s-correctly

🐛 Log errors on specific log levels correctly
  • Loading branch information
k8s-ci-robot authored Sep 27, 2024
2 parents 187f385 + 0456d46 commit 56b5af9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions exp/internal/controllers/machinepool_controller_noderef.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *MachinePoolReconciler) deleteRetiredNodes(ctx context.Context, c client
for _, nodeRef := range nodeRefs {
node := &corev1.Node{}
if err := c.Get(ctx, client.ObjectKey{Name: nodeRef.Name}, node); err != nil {
log.V(2).Error(err, "Failed to get Node, skipping", "Node", klog.KRef("", nodeRef.Name))
log.Error(err, "Failed to get Node, skipping", "Node", klog.KRef("", nodeRef.Name))
continue
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *MachinePoolReconciler) patchNodes(ctx context.Context, c client.Client,
for _, nodeRef := range references {
node := &corev1.Node{}
if err := c.Get(ctx, client.ObjectKey{Name: nodeRef.Name}, node); err != nil {
log.V(2).Error(err, "Failed to get Node, skipping setting annotations", "Node", klog.KRef("", nodeRef.Name))
log.Error(err, "Failed to get Node, skipping setting annotations", "Node", klog.KRef("", nodeRef.Name))
continue
}
patchHelper, err := patch.NewHelper(node, c)
Expand All @@ -219,7 +219,7 @@ func (r *MachinePoolReconciler) patchNodes(ctx context.Context, c client.Client,
// Patch the node if needed.
if hasAnnotationChanges || hasTaintChanges {
if err := patchHelper.Patch(ctx, node); err != nil {
log.V(2).Error(err, "Failed patch Node to set annotations and drop taints", "Node", klog.KObj(node))
log.Error(err, "Failed patch Node to set annotations and drop taints", "Node", klog.KObj(node))
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/machine/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ evictionLoop:
case <-ctx.Done():
// Skip eviction if the eviction timeout is reached.
err := fmt.Errorf("eviction timeout of %s reached, eviction will be retried", evictionTimeout)
log.V(4).Error(err, "Error when evicting Pod")
log.V(4).Info("Error when evicting Pod", "err", err)
res.PodsFailedEviction[err.Error()] = append(res.PodsFailedEviction[err.Error()], pd.Pod)
continue evictionLoop
default:
Expand Down Expand Up @@ -250,17 +250,17 @@ evictionLoop:
err = errors.New(errorMessage)
}

log.V(4).Error(err, "Error when evicting Pod")
log.V(4).Info("Error when evicting Pod", "err", err)
res.PodsFailedEviction[err.Error()] = append(res.PodsFailedEviction[err.Error()], pd.Pod)
case apierrors.IsForbidden(err) && apierrors.HasStatusCause(err, corev1.NamespaceTerminatingCause):
// Creating an eviction resource in a terminating namespace will throw a forbidden error, e.g.:
// "pods "pod-6-to-trigger-eviction-namespace-terminating" is forbidden: unable to create new content in namespace test-namespace because it is being terminated"
// The kube-controller-manager is supposed to set the deletionTimestamp on the Pod and then this error will go away.
msg := "Cannot evict pod from terminating namespace: unable to create eviction (kube-controller-manager should set deletionTimestamp)"
log.V(4).Error(err, msg)
log.V(4).Info(msg, "err", err)
res.PodsFailedEviction[msg] = append(res.PodsFailedEviction[msg], pd.Pod)
default:
log.V(4).Error(err, "Error when evicting Pod")
log.V(4).Info("Error when evicting Pod", "err", err)
res.PodsFailedEviction[err.Error()] = append(res.PodsFailedEviction[err.Error()], pd.Pod)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *Reconciler) reconcileOldMachineSetsOnDelete(ctx context.Context, oldMSs
}
selectorMap, err := metav1.LabelSelectorAsMap(&oldMS.Spec.Selector)
if err != nil {
log.V(4).Error(err, "failed to convert MachineSet label selector to a map")
log.V(4).Info("Failed to convert MachineSet label selector to a map", "err", err)
continue
}
log.V(4).Info("Fetching Machines associated with MachineSet")
Expand All @@ -127,7 +127,7 @@ func (r *Reconciler) reconcileOldMachineSetsOnDelete(ctx context.Context, oldMSs
}
machineSetScaleDownAmountDueToMachineDeletion := *oldMS.Spec.Replicas - updatedReplicaCount
if machineSetScaleDownAmountDueToMachineDeletion < 0 {
log.V(4).Error(errors.Errorf("Unexpected negative scale down amount: %d", machineSetScaleDownAmountDueToMachineDeletion), fmt.Sprintf("Error reconciling MachineSet %s", oldMS.Name))
log.V(4).Info(fmt.Sprintf("Error reconciling MachineSet %s", oldMS.Name), "err", errors.Errorf("Unexpected negative scale down amount: %d", machineSetScaleDownAmountDueToMachineDeletion))
}
scaleDownAmount -= machineSetScaleDownAmountDueToMachineDeletion
log.V(4).Info("Adjusting replica count for deleted machines", "oldReplicas", oldMS.Spec.Replicas, "newReplicas", updatedReplicaCount)
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func ClusterToInfrastructureMapFunc(ctx context.Context, gvk schema.GroupVersion
key := types.NamespacedName{Namespace: cluster.Namespace, Name: cluster.Spec.InfrastructureRef.Name}

if err := c.Get(ctx, key, providerCluster); err != nil {
log.V(4).Error(err, fmt.Sprintf("Failed to get %T", providerCluster))
log.V(4).Info(fmt.Sprintf("Failed to get %T", providerCluster), "err", err)
return nil
}

Expand Down

0 comments on commit 56b5af9

Please sign in to comment.