Merge pull request #117238 from pohly/namespaces-name-lowercase

encode NamespacedName with lower case in JSON
This commit is contained in:
Kubernetes Prow Robot 2023-04-13 07:32:38 -07:00 committed by GitHub
commit b98659ba62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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,

View File

@ -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 {