1

I am wrestling with logging in a Kubernetes operator built with:

  • KubeBuilderVersion: 3.7.0
  • go version: go1.20.1 linux/amd64

Up and until now, for logging purposes, I have made use of the zap logger package ("sigs.k8s.io/controller-runtime/pkg/log/zap") and it worked fine.

Lately the need has arisen to make the logging more compatible with Elasticsearch and the ecs logger was suggested. I have tried the example listed here in a simple go app and it works fine.

The next step was to substitute the existing zap logging setup inside the operator's code with the ecs one, and that is when progress grinded to a halt.

The current setup:

"sigs.k8s.io/controller-runtime/pkg/log/zap"  
ctrl "sigs.k8s.io/controller-runtime"

opts := zap.Options{
    Development: true,
}
opts.BindFlags(flag.CommandLine)

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

ctrl.SetLogger expects a parameter of type logr.Logger and that is also exactly what zap.New(zap.UseFlagOptions(&opts)) returns – so it all works fine and dandy.

*** setup trying to use the ecszap logger ***
Using the ecszap example stated here again, I end up with the following:

ctrl "sigs.k8s.io/controller-runtime"  
ecszap "go.elastic.co/ecszap"  
uzap "go.uber.org/zap"  

encoderConfig := ecszap.NewDefaultEncoderConfig()
core := ecszap.NewCore(encoderConfig, os.Stdout, uzap.DebugLevel)
logger := uzap.New(core, uzap.AddCaller())

The uzap.New(core, uzap.AddCaller()) returns a pointer to the type Logger struct. This is (as far as I can see) not what the ctrl.SetLogger is expecting (it requires logr.Logger) and it then obviously fails for a type mismatch.

enter image description here

My question is: What is the correct way to get ecszap logger hooked up for usage in an operator?

Any help will be greatly appreciated.
Many thanks in advance!

Morné Kruger
  • 309
  • 1
  • 12

0 Answers0