Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cmd/controlplane-operator/main.go
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

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
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

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)
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

}

// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
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

controller-gen.kubebuilder.io/version: v0.20.1
name: managedcontrolplanes.controlplane.patrostkowski.dev
spec:
group: controlplane.patrostkowski.dev
Expand Down