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{})
| 74 | // TODO: replace key-as-string with a key-as-struct so that this |
| 75 | // packing/unpacking won't be necessary. |
| 76 | func 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. |