Skip to content

feat: add logging levels to controlplane-operator#81

Draft
tscrond wants to merge 7 commits intopatrostkowski:mainfrom
tscrond:feature/improve-logging
Draft

feat: add logging levels to controlplane-operator#81
tscrond wants to merge 7 commits intopatrostkowski:mainfrom
tscrond:feature/improve-logging

Conversation

@tscrond
Copy link
Contributor

@tscrond tscrond commented Feb 13, 2026

Add configurable log levels to controlplane-operator

Changes

  • Add --log-level flag (default: warn)
  • Support zap levels: debug, info, warn, error, dpanic, panic, fatal
  • Validate input via zapcore.ParseLevel
  • Initialize logger with configured level
  • Add verification log for applied level
  • Bump controller-gen v0.19.0v0.20.1
  • Regenerate CRDs

Compatibility

  • No breaking changes
  • Backward compatible (defaults to info)

Added code to parse log level as commandline args

Fixes patrostkowski#38
@patrostkowski
Copy link
Owner

/ci

@github-actions
Copy link

CI success

Run: https://github.com/patrostkowski/controlplane-operator/actions/runs/22018956035
Commit: d799650f452c606fabb5b4b9c93b5d645dc03be9

kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.19.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0 hmm could you bump down your local binary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, i reverted the taskfile change: fd85833


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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do INFO as default log level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 694f39f

ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
zapLogLevel, err := zapcore.ParseLevel(logLevel)
if err != nil {
log.Println("errors setting the log level:", err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we cannot parse it, lets panic with error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: c93cf87

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the exact thing you were aiming for in this comment, but i think it's pretty accurate.

07a2acb

@tscrond tscrond marked this pull request as draft February 18, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants