From cc852ec7867b3cff959730c6f6ab023f137d481f Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 12 Apr 2023 12:35:57 +0200 Subject: [PATCH] api: encode NamespacedName with lower case in JSON That is how a workaround in controller-runtime has encoded NamespacedName (https://github.com/kubernetes-sigs/controller-runtime/blob/a33d038b84d0e7f615b8d803bdc47f0d1f8484b7/pkg/log/zap/kube_helpers.go#L49-L57) and it is also more consistent with Kubernetes API standards. The namespace can be left out. Returning an anonymous struct in MarshalLog makes it impossible for controller-runtime to adapt the type and thus blocks updating controller-runtime to Kubernetes 1.27 because log content would change. Kubernetes-commit: f564f7a3559a2710b879122dd81b536fc930c410 --- pkg/types/namespacedname.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/types/namespacedname.go b/pkg/types/namespacedname.go index 29fb4f950..db18ce1ce 100644 --- a/pkg/types/namespacedname.go +++ b/pkg/types/namespacedname.go @@ -41,7 +41,8 @@ func (n NamespacedName) String() string { // MarshalLog emits a struct containing required key/value pair func (n NamespacedName) MarshalLog() interface{} { return struct { - Name, Namespace string + Name string `json:"name"` + Namespace string `json:"namespace,omitempty"` }{ Name: n.Name, Namespace: n.Namespace,