You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IndexFunc: takes an object, and produces a list of index values. Index: a mapping from index value to key set. Indexers: a mapping from index name to IndexFunc. Indices: a mapping from index name to Index
// Index returns a list of items that match on the index function// Index is thread-safe so long as you treat all items as immutablefunc (c*threadSafeMap) Index(indexNamestring, objinterface{}) ([]interface{}, error) {
c.lock.RLock()
deferc.lock.RUnlock()
indexFunc:=c.indexers[indexName]
ifindexFunc==nil {
returnnil, fmt.Errorf("Index with name %s does not exist", indexName)
}
indexKeys, err:=indexFunc(obj)
iferr!=nil {
returnnil, err
}
index:=c.indices[indexName]
// need to de-dupe the return list. Since multiple keys are allowed, this can happen.returnKeySet:= sets.String{}
for_, indexKey:=rangeindexKeys {
set:=index[indexKey]
for_, key:=rangeset.UnsortedList() {
returnKeySet.Insert(key)
}
}
list:=make([]interface{}, 0, returnKeySet.Len())
forabsoluteKey:=rangereturnKeySet {
list=append(list, c.items[absoluteKey])
}
returnlist, nil
}
先通过indexName获取indexFunc.
对obj做indexFunc拿到[]string的index values.
再通过indexName获取index.
对每个index value, 从index中取出key set.
合并所有的key set.
从storage中根据key set取出所有的object.
The text was updated successfully, but these errors were encountered:
Source Code: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/tools/cache/index.go.
IndexFunc: takes an object, and produces a list of index values.
Index: a mapping from index value to key set.
Indexers: a mapping from index name to IndexFunc.
Indices: a mapping from index name to Index
The text was updated successfully, but these errors were encountered: