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

Method GetByKey

tools/cache/mutation_cache.go:90–114  ·  view source on GitHub ↗

GetByKey is never guaranteed to return back the value set in Mutation. It could be paged out, it could be older than another copy, the backingCache may be more recent or, you might have written twice into the same key. You get a value that was valid at some snapshot of time and will always return t

(key string)

Source from the content-addressed store, hash-verified

88// be older than another copy, the backingCache may be more recent or, you might have written twice into the same key.
89// You get a value that was valid at some snapshot of time and will always return the newer of backingCache and mutationCache.
90func (c *mutationCache) GetByKey(key string) (interface{}, bool, error) {
91 c.lock.Lock()
92 defer c.lock.Unlock()
93
94 obj, exists, err := c.backingCache.GetByKey(key)
95 if err != nil {
96 return nil, false, err
97 }
98 if !exists {
99 if !c.includeAdds {
100 // we can't distinguish between, "didn't observe create" and "was deleted after create", so
101 // if the key is missing, we always return it as missing
102 return nil, false, nil
103 }
104 obj, exists = c.mutationCache.Get(key)
105 if !exists {
106 return nil, false, nil
107 }
108 }
109 objRuntime, ok := obj.(runtime.Object)
110 if !ok {
111 return obj, true, nil
112 }
113 return c.newerObject(key, objRuntime), true, nil
114}
115
116// ByIndex returns the newer objects that match the provided index and indexer key.
117// Will return an error if no indexer was provided.

Callers

nothing calls this directly

Calls 3

newerObjectMethod · 0.95
GetByKeyMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected