-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add logging levels to controlplane-operator #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
d799650
694f39f
9505879
9c73347
c93cf87
07a2acb
fd85833
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,13 @@ package main | |
|
|
||
| import ( | ||
| "flag" | ||
| "log" | ||
| "os" | ||
|
|
||
| certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" | ||
| mcpv1alpha1 "github.com/patrostkowski/controlplane-operator/pkg/apis/controlplane.patrostkowski.dev/v1alpha1" | ||
| "github.com/patrostkowski/controlplane-operator/pkg/controller" | ||
| "go.uber.org/zap/zapcore" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/healthz" | ||
|
|
@@ -31,12 +33,23 @@ import ( | |
| func main() { | ||
| var metricsAddr string | ||
| var healthProbeAddr string | ||
| var logLevel string | ||
|
|
||
| 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") | ||
|
||
| flag.Parse() | ||
|
|
||
| ctrl.SetLogger(zap.New(zap.UseDevMode(true))) | ||
| zapLogLevel, err := zapcore.ParseLevel(logLevel) | ||
| if err != nil { | ||
| log.Println("errors setting the log level:", err) | ||
|
||
| } | ||
|
|
||
| // set log level for controller runtime components | ||
| ctrl.SetLogger(zap.New(zap.UseDevMode(true), zap.Level(zapLogLevel))) | ||
|
|
||
| // Test debug logging | ||
| ctrl.Log.V(int(zapLogLevel)).Info("logging is enabled", "logLevelInt", int(zapLogLevel), "logLevelStr", zapLogLevel) | ||
|
|
||
| mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
| Scheme: nil, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 | |
| kind: CustomResourceDefinition | ||
| metadata: | ||
| annotations: | ||
| controller-gen.kubebuilder.io/version: v0.19.0 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: WDYT?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, i reverted the taskfile change: fd85833 |
||
| controller-gen.kubebuilder.io/version: v0.20.1 | ||
| name: managedcontrolplanes.controlplane.patrostkowski.dev | ||
| spec: | ||
| group: controlplane.patrostkowski.dev | ||
|
|
||
There was a problem hiding this comment.
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/Errorinstead. something likeand under the hood we should just map it like:
There was a problem hiding this comment.
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