fix(apiserver): convert V().Error() to V().Info() for verbosity-aware logging

The go-logr/logr package ignores verbosity levels when using the Error
method. This means logger.V(1).Error() will always log regardless of
the verbosity setting, which contradicts the developer's intent.

This commit converts V(1).Error(err, "msg") to V(1).Info("msg", "err", err)
in the authorizeUnsafeDelete function to properly respect the verbosity
level.

This issue was identified in PR #136190 which adds a logcheck linter
rule to detect this pattern.
This commit is contained in:
thc1006
2026-01-14 15:53:44 +00:00
parent b2ac9e206f
commit 97bbd4246c

View File

@@ -415,7 +415,7 @@ func authorizeUnsafeDelete(ctx context.Context, attr admission.Attributes, authz
decision, reason, err := authz.Authorize(ctx, record)
if err != nil {
err = fmt.Errorf("error while checking permission for %q, %w", record.Verb, err)
klog.FromContext(ctx).V(1).Error(err, "failed to authorize")
klog.FromContext(ctx).V(1).Info("failed to authorize", "err", err)
return admission.NewForbidden(attr, err)
}
if decision == authorizer.DecisionAllow {