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

Method Mutation

tools/cache/mutation_cache.go:199–220  ·  view source on GitHub ↗

Mutation adds a change to the cache that can be returned in GetByKey if it is newer than the backingCache copy. If you call Mutation twice with the same object on different threads, one will win, but its not defined which one. This doesn't affect correctness, since the GetByKey guaranteed of "late

(obj interface{})

Source from the content-addressed store, hash-verified

197// preserved, but you may not get the version of the object you want. The object you get is only guaranteed to
198// "one that was valid at some point in time", not "the one that I want".
199func (c *mutationCache) Mutation(obj interface{}) {
200 c.lock.Lock()
201 defer c.lock.Unlock()
202
203 key, err := DeletionHandlingMetaNamespaceKeyFunc(obj)
204 if err != nil {
205 // this is a "nice to have", so failures shouldn't do anything weird
206 utilruntime.HandleError(err)
207 return
208 }
209
210 if objRuntime, ok := obj.(runtime.Object); ok {
211 if mutatedObj, exists := c.mutationCache.Get(key); exists {
212 if mutatedObjRuntime, ok := mutatedObj.(runtime.Object); ok {
213 if c.comparator.CompareResourceVersion(objRuntime, mutatedObjRuntime) < 0 {
214 return
215 }
216 }
217 }
218 }
219 c.mutationCache.Add(key, obj, c.ttl)
220}
221
222// etcdObjectVersioner implements versioning and extracting etcd node information
223// for objects that have an embedded ObjectMeta or ListMeta field.

Callers

nothing calls this directly

Calls 4

GetMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected