mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Implemented MarshalLog in namespacedname.go
This commit is contained in:
parent
3aff1f97be
commit
e02168d291
@ -37,3 +37,13 @@ const (
|
|||||||
func (n NamespacedName) String() string {
|
func (n NamespacedName) String() string {
|
||||||
return n.Namespace + string(Separator) + n.Name
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
logsapi "k8s.io/component-base/logs/api/v1"
|
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",
|
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"},
|
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 {
|
for _, data := range testDataInfo {
|
||||||
|
Loading…
Reference in New Issue
Block a user