ByIndex returns the newer objects that match the provided index and indexer key. Will return an error if no indexer was provided.
(name string, indexKey string)
| 116 | // ByIndex returns the newer objects that match the provided index and indexer key. |
| 117 | // Will return an error if no indexer was provided. |
| 118 | func (c *mutationCache) ByIndex(name string, indexKey string) ([]interface{}, error) { |
| 119 | c.lock.Lock() |
| 120 | defer c.lock.Unlock() |
| 121 | if c.indexer == nil { |
| 122 | return nil, fmt.Errorf("no indexer has been provided to the mutation cache") |
| 123 | } |
| 124 | keys, err := c.indexer.IndexKeys(name, indexKey) |
| 125 | if err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | var items []interface{} |
| 129 | keySet := sets.NewString() |
| 130 | for _, key := range keys { |
| 131 | keySet.Insert(key) |
| 132 | obj, exists, err := c.indexer.GetByKey(key) |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | if !exists { |
| 137 | continue |
| 138 | } |
| 139 | if objRuntime, ok := obj.(runtime.Object); ok { |
| 140 | items = append(items, c.newerObject(key, objRuntime)) |
| 141 | } else { |
| 142 | items = append(items, obj) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if c.includeAdds { |
| 147 | fn := c.indexer.GetIndexers()[name] |
| 148 | // Keys() is returned oldest to newest, so full traversal does not alter the LRU behavior |
| 149 | for _, key := range c.mutationCache.Keys() { |
| 150 | updated, ok := c.mutationCache.Get(key) |
| 151 | if !ok { |
| 152 | continue |
| 153 | } |
| 154 | if keySet.Has(key.(string)) { |
| 155 | continue |
| 156 | } |
| 157 | elements, err := fn(updated) |
| 158 | if err != nil { |
| 159 | klog.V(4).Infof("Unable to calculate an index entry for mutation cache entry %s: %v", key, err) |
| 160 | continue |
| 161 | } |
| 162 | for _, inIndex := range elements { |
| 163 | if inIndex != indexKey { |
| 164 | continue |
| 165 | } |
| 166 | items = append(items, updated) |
| 167 | break |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return items, nil |
| 173 | } |
| 174 | |
| 175 | // newerObject checks the mutation cache for a newer object and returns one if found. If the |
nothing calls this directly
no test coverage detected