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

Function IndexFuncToKeyFuncAdapter

tools/cache/index.go:51–65  ·  tools/cache/index.go::IndexFuncToKeyFuncAdapter

IndexFuncToKeyFuncAdapter adapts an indexFunc to a keyFunc. This is only useful if your index function returns unique values for every object. This is conversion can create errors when more than one key is found. You should prefer to make proper key and index functions.

(indexFunc IndexFunc)

Source from the content-addressed store, hash-verified

49// unique values for every object. This is conversion can create errors when more than one key is found. You
50// should prefer to make proper key and index functions.
51func IndexFuncToKeyFuncAdapter(indexFunc IndexFunc) KeyFunc {
52 return func(obj interface{}) (string, error) {
53 indexKeys, err := indexFunc(obj)
54 if err != nil {
55 return "", err
56 }
57 if len(indexKeys) > 1 {
58 return "", fmt.Errorf("too many keys: %v", indexKeys)
59 }
60 if len(indexKeys) == 0 {
61 return "", fmt.Errorf("unexpected empty indexKeys")
62 }
63 return indexKeys[0], nil
64 }
65}
66
67const (
68 NamespaceIndex string = "namespace"

Callers

nothing calls this directly

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected