#17563·kyverno

[Bug] Structured logging anti-pattern: fmt.Sprintf used in logr messages (remaining instances)

Author: sapnilbiswasCreated Sep 13, 2026Updated Sep 18, 2026
Labelsbugtriage

Kyverno Version

1.16.4

Description

Description

In issue #17381 ([Bug] Structured logging anti-pattern: fmt.Sprintf used in logr messages causing high cardinality), the team fixed multiple instances of fmt.Sprintf being used inside logr messages.

However, a few lingering instances of this anti-pattern were left behind in the main branch. Using fmt.Sprintf directly inside logger.Error or logger.Info defeats the purpose of structured logging, as it triggers string allocations unconditionally and prevents logging backends from properly indexing the keys/values.

I have found remaining instances in the following files:

  • pkg/controllers/report/resource/controller.go (1 instance)
  • pkg/admissionpolicy/validate.go (3 instances)
  • cmd/kyverno-init/main.go (2 instances)
  • cmd/kyverno/watch/watcher.go (1 instance)

Example from pkg/controllers/report/resource/controller.go:

go
// Current (Anti-pattern)
logger.Error(statusErr, fmt.Sprintf("watch error for gvr: %s", gvr))

// Should be
logger.Error(statusErr, "watch error for gvr", "gvr", gvr.String())


### Slack discussion

None

### Troubleshooting

- [x] I have read and followed the documentation AND the [troubleshooting guide](https://kyverno.io/docs/troubleshooting/).
- [x] I have searched other issues in this repository and mine is not recorded.