Skip to content

Commit

Permalink
fix log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Aug 30, 2024
1 parent cc31a44 commit 4df4afd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/controllers/machine/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ func (d *Helper) EvictPods(ctx context.Context, podDeleteList *PodDeleteList) Ev
log = log.WithValues("reason", pd.Status.Message)
}

log.V(3).Info("Skip evicting Pod because it should be ignored")
log.V(4).Info("Skip evicting Pod because it should be ignored")
res.PodsIgnored = append(res.PodsIgnored, pd.Pod)
}

for _, pd := range podsWithDeletionTimestamp {
log := ctrl.LoggerFrom(ctx, "Pod", klog.KObj(pd.Pod))

log.V(3).Info("Skip triggering Pod eviction because it already has a deletionTimestamp")
log.V(4).Info("Skip triggering Pod eviction because it already has a deletionTimestamp")
res.PodsDeletionTimestampSet = append(res.PodsDeletionTimestampSet, pd.Pod)
}

Expand All @@ -212,22 +212,22 @@ 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.Error(err, "Error when evicting Pod")
log.V(4).Error(err, "Error when evicting Pod")
res.PodsFailedEviction[err.Error()] = append(res.PodsFailedEviction[err.Error()], pd.Pod)
continue evictionLoop
default:
}

log.Info("Evicting Pod")
log.V(4).Info("Evicting Pod")

err := d.evictPod(ctx, pd.Pod)
switch {
case err == nil:
log.Info("Pod eviction successfully triggered")
log.V(4).Info("Pod eviction successfully triggered")
res.PodsDeletionTimestampSet = append(res.PodsDeletionTimestampSet, pd.Pod)
case apierrors.IsNotFound(err):
// Pod doesn't exist anymore as it has been deleted in the meantime.
log.Info("Eviction not needed, Pod doesn't exist anymore")
log.V(4).Info("Eviction not needed, Pod doesn't exist anymore")
res.PodsNotFound = append(res.PodsNotFound, pd.Pod)
case apierrors.IsTooManyRequests(err):
var statusError *apierrors.StatusError
Expand All @@ -247,17 +247,17 @@ evictionLoop:
err = errors.New(errorMessage)
}

log.Error(err, "Error when evicting Pod")
log.V(4).Error(err, "Error when evicting Pod")
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.Error(err, msg)
log.V(4).Error(err, msg)
res.PodsFailedEviction[msg] = append(res.PodsFailedEviction[msg], pd.Pod)
default:
log.Error(err, "Error when evicting Pod")
log.V(4).Error(err, "Error when evicting Pod")
res.PodsFailedEviction[err.Error()] = append(res.PodsFailedEviction[err.Error()], pd.Pod)
}
}
Expand Down

0 comments on commit 4df4afd

Please sign in to comment.