feat: add logging levels to controlplane-operator#81
feat: add logging levels to controlplane-operator#81tscrond wants to merge 7 commits intopatrostkowski:mainfrom
Conversation
Added code to parse log level as commandline args Fixes patrostkowski#38
|
/ci |
|
✅ CI success Run: https://github.com/patrostkowski/controlplane-operator/actions/runs/22018956035 |
| kind: CustomResourceDefinition | ||
| metadata: | ||
| annotations: | ||
| controller-gen.kubebuilder.io/version: v0.19.0 |
There was a problem hiding this comment.
lets not bump the tools yet. I must find good way to provide contributors with toolset without any deps on their own setup, like using container image
There was a problem hiding this comment.
OK, right now the pre-commit does bump automatically - i think the best fix for that is to temporarily comment this line in Taskfile:
dev:codegen:
desc: "Run all code generation scripts (client + CRDs) inside hack/"
cmds:
- addlicense -c "Patryk Rostkowski" -l apache -y 2025 .
- bash hack/update-codegen.sh
# - bash hack/update-crds.sh
WDYT?
There was a problem hiding this comment.
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0 hmm could you bump down your local binary?
There was a problem hiding this comment.
Done, i reverted the taskfile change: fd85833
cmd/controlplane-operator/main.go
Outdated
|
|
||
| flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") | ||
| flag.StringVar(&healthProbeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") | ||
| flag.StringVar(&logLevel, "log-level", "warn", "Log level for the controller") |
There was a problem hiding this comment.
lets do INFO as default log level
cmd/controlplane-operator/main.go
Outdated
| ctrl.SetLogger(zap.New(zap.UseDevMode(true))) | ||
| zapLogLevel, err := zapcore.ParseLevel(logLevel) | ||
| if err != nil { | ||
| log.Println("errors setting the log level:", err) |
There was a problem hiding this comment.
if we cannot parse it, lets panic with error
There was a problem hiding this comment.
To keep things tidy, lets not expose users to setting the log levels using arbitrary numbers and instead implement an interface that could allow us to call log.Info/Debug/Warn/Error instead. something like
type Logger interface {
Debug(msg string, keysAndValues ...any)
Info(msg string, keysAndValues ...any)
Warn(msg string, keysAndValues ...any)
Error(err error, msg string, keysAndValues ...any)
}
and under the hood we should just map it like:
func (l *zapLogger) Debug(msg string, kv ...any) {
l.log.V(zapcore.DebugLevel).Info(msg, kv...)
}
...
(other methods implemented in the same fashion)
There was a problem hiding this comment.
I don't know if this is the exact thing you were aiming for in this comment, but i think it's pretty accurate.
Add configurable log levels to controlplane-operator
Changes
--log-levelflag (default:warn)debug,info,warn,error,dpanic,panic,fatalzapcore.ParseLevelcontroller-genv0.19.0→v0.20.1Compatibility
info)