kubernetes-sigs / controller-runtime

Repo for the controller-runtime subproject of kubebuilder (sig-apimachinery)
Apache License 2.0
2.55k stars 1.15k forks source link

Bad log message #2914

Open tamalsaha opened 2 months ago

tamalsaha commented 2 months ago

We see log lines like below in our cluster:

I0808 07:14:05.625541 1 controller.go:130] "msg"="Starting EventSource" "controller"="servicemonitor" "controllerGroup"="monitoring.coreos.com" "controllerKind"="ServiceMonitor" "source"=<<error: json: unsupported type: func(event.TypedCreateEvent[sigs.k8s.io/controller-runtime/pkg/client.Object]) bool>>

This is coming from https://github.com/kubernetes-sigs/controller-runtime/blob/fdc8bd7d9c539b57eaf2285680e10e3393604d4d/pkg/internal/controller/controller.go#L132

It seems that src can't be converted into a json object. We are using v0.18.4

sbueringer commented 2 months ago

Hm. I think we have a few options:

(cc @alvaroaleman)

tamalsaha commented 2 months ago

Delete only the source k/v pair

I vote for this.

alvaroaleman commented 2 months ago

Weird, did we break this or did it never work but no one reported it?

sbueringer commented 2 months ago

I think we didn't break it, it's just that not every source is nicely printable that way :)

E.g. kind source looks better:

{"ts":1723448825525.443,"caller":"controller/controller.go:173","msg":"Starting EventSource","controller":"remote/clustercache","controllerGroup":"cluster.x-k8s.io","controllerKind":"Cluster","v":0,"source":"kind source: *v1beta1.Cluster"}

Hm, I guess actually the better fix would be to add String() funcs to the sources that don't have one already

sbueringer commented 2 months ago

@tamalsaha What source are you using?

tamalsaha commented 2 months ago

func(event.TypedCreateEvent[sigs.k8s.io/controller-runtime/pkg/client.Object]) bool

sbueringer commented 2 months ago

Is this a builtin source from controller-runtime or one that has been implemented outside of it?

tamalsaha commented 2 months ago

This is a typical SetupWithManager() method written in our operator. It is coming from one of these 2 Setups:

sbueringer commented 2 months ago

Hm that's strange. I would have expected all of them to use the kind source and thus have a String() func and produce a similar output to: https://github.com/kubernetes-sigs/controller-runtime/issues/2914#issuecomment-2283825385

sbueringer commented 2 months ago

I'm wondering what logger is used that tries to convert the source to a JSON.

We're using component-base in Cluster API and neither the text format (klog) nor the JSON format (zap) is doing this:

text:

I0812 12:40:03.514514 17 controller.go:173] "Starting EventSource" controller="clusterclass" controllerGroup="cluster.x-k8s.io" controllerKind="ClusterClass" source="kind source: *v1beta1.ClusterClass"

JSON:

{"ts":1723448825525.5396,"caller":"controller/controller.go:173","msg":"Starting EventSource","controller":"clusterclass","controllerGroup":"cluster.x-k8s.io","controllerKind":"ClusterClass","v":0,"source":"kind source: *v1beta1.ClusterClass"}

tamalsaha commented 2 months ago

"k8s.io/klog/v2/klogr" klogr.New()