Skip to content

Commit

Permalink
api: encode NamespacedName with lower case in JSON
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pohly authored and k8s-publishing-bot committed Apr 12, 2023
1 parent 54279fc commit 98a65ea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion logs/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ func TestZapLoggerInfo(t *testing.T) {
},
{
msg: "test for NamespacedName argument",
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for NamespacedName argument\",\"v\":0,\"obj\":{\"Name\":\"kube-proxy\",\"Namespace\":\"kube-system\"}}\n",
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for NamespacedName argument\",\"v\":0,\"obj\":{\"name\":\"kube-proxy\",\"namespace\":\"kube-system\"}}\n",
keysValues: []interface{}{"obj", types.NamespacedName{Name: "kube-proxy", Namespace: "kube-system"}},
},
{
msg: "test for NamespacedName argument with no namespace",
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for NamespacedName argument with no namespace\",\"v\":0,\"obj\":{\"name\":\"kube-proxy\"}}\n",
keysValues: []interface{}{"obj", types.NamespacedName{Name: "kube-proxy"}},
},
}

for _, data := range testDataInfo {
Expand Down

0 comments on commit 98a65ea

Please sign in to comment.