MCPcopy
hub / github.com/kubernetes/client-go / MetaNamespaceKeyFunc

Function MetaNamespaceKeyFunc

tools/cache/store.go:76–88  ·  view source on GitHub ↗

MetaNamespaceKeyFunc is a convenient default KeyFunc which knows how to make keys for API objects which implement meta.Interface. The key uses the format <namespace>/<name> unless <namespace> is empty, then it's just <name>. TODO: replace key-as-string with a key-as-struct so that this packing/unpa

(obj interface{})

Source from the content-addressed store, hash-verified

74// TODO: replace key-as-string with a key-as-struct so that this
75// packing/unpacking won't be necessary.
76func MetaNamespaceKeyFunc(obj interface{}) (string, error) {
77 if key, ok := obj.(ExplicitKey); ok {
78 return string(key), nil
79 }
80 meta, err := meta.Accessor(obj)
81 if err != nil {
82 return "", fmt.Errorf("object has no meta: %v", err)
83 }
84 if len(meta.GetNamespace()) > 0 {
85 return meta.GetNamespace() + "/" + meta.GetName(), nil
86 }
87 return meta.GetName(), nil
88}
89
90// SplitMetaNamespaceKey returns the namespace and name that
91// MetaNamespaceKeyFunc encoded into key.

Callers 3

mainFunction · 0.92
handleMethod · 0.85

Calls 3

ErrorfMethod · 0.65
GetNamespaceMethod · 0.65
GetNameMethod · 0.65

Tested by 1

handleMethod · 0.68