Merge pull request #106379 from shivanshu1333/feature/master/105782

Implemented MarshalLog in namespacedname.go
This commit is contained in:
Kubernetes Prow Robot 2023-01-24 12:55:53 -08:00 committed by GitHub
commit 14549722e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -37,3 +37,13 @@ const (
func (n NamespacedName) String() string {
return n.Namespace + string(Separator) + n.Name
}
// MarshalLog emits a struct containing required key/value pair
func (n NamespacedName) MarshalLog() interface{} {
return struct {
Name, Namespace string
}{
Name: n.Name,
Namespace: n.Namespace,
}
}

View File

@ -27,6 +27,7 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/types"
logsapi "k8s.io/component-base/logs/api/v1"
)
@ -71,6 +72,11 @@ func TestZapLoggerInfo(t *testing.T) {
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for duplicate keys\",\"v\":0,\"akey\":\"avalue\",\"akey\":\"anothervalue\"}\n",
keysValues: []interface{}{"akey", "avalue", "akey", "anothervalue"},
},
{
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",
keysValues: []interface{}{"obj", types.NamespacedName{Name: "kube-proxy", Namespace: "kube-system"}},
},
}
for _, data := range testDataInfo {