Commit e7518d8a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50555 from atlassian/fix-error-handling-from-index-funcs

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. threadSafeMap: panic if index function call fails **Which issue this PR fixes** Fixes #43605 **Release note**: ```release-note NONE ``` /kind bug /sig api-machinery
parents dd99659d 65369a68
...@@ -241,7 +241,7 @@ func (c *threadSafeMap) AddIndexers(newIndexers Indexers) error { ...@@ -241,7 +241,7 @@ func (c *threadSafeMap) AddIndexers(newIndexers Indexers) error {
// updateIndices modifies the objects location in the managed indexes, if this is an update, you must provide an oldObj // updateIndices modifies the objects location in the managed indexes, if this is an update, you must provide an oldObj
// updateIndices must be called from a function that already has a lock on the cache // updateIndices must be called from a function that already has a lock on the cache
func (c *threadSafeMap) updateIndices(oldObj interface{}, newObj interface{}, key string) error { func (c *threadSafeMap) updateIndices(oldObj interface{}, newObj interface{}, key string) {
// if we got an old object, we need to remove it before we add it again // if we got an old object, we need to remove it before we add it again
if oldObj != nil { if oldObj != nil {
c.deleteFromIndices(oldObj, key) c.deleteFromIndices(oldObj, key)
...@@ -249,7 +249,7 @@ func (c *threadSafeMap) updateIndices(oldObj interface{}, newObj interface{}, ke ...@@ -249,7 +249,7 @@ func (c *threadSafeMap) updateIndices(oldObj interface{}, newObj interface{}, ke
for name, indexFunc := range c.indexers { for name, indexFunc := range c.indexers {
indexValues, err := indexFunc(newObj) indexValues, err := indexFunc(newObj)
if err != nil { if err != nil {
return err panic(fmt.Errorf("unable to calculate an index entry for key %q on index %q: %v", key, name, err))
} }
index := c.indices[name] index := c.indices[name]
if index == nil { if index == nil {
...@@ -266,16 +266,15 @@ func (c *threadSafeMap) updateIndices(oldObj interface{}, newObj interface{}, ke ...@@ -266,16 +266,15 @@ func (c *threadSafeMap) updateIndices(oldObj interface{}, newObj interface{}, ke
set.Insert(key) set.Insert(key)
} }
} }
return nil
} }
// deleteFromIndices removes the object from each of the managed indexes // deleteFromIndices removes the object from each of the managed indexes
// it is intended to be called from a function that already has a lock on the cache // it is intended to be called from a function that already has a lock on the cache
func (c *threadSafeMap) deleteFromIndices(obj interface{}, key string) error { func (c *threadSafeMap) deleteFromIndices(obj interface{}, key string) {
for name, indexFunc := range c.indexers { for name, indexFunc := range c.indexers {
indexValues, err := indexFunc(obj) indexValues, err := indexFunc(obj)
if err != nil { if err != nil {
return err panic(fmt.Errorf("unable to calculate an index entry for key %q on index %q: %v", key, name, err))
} }
index := c.indices[name] index := c.indices[name]
...@@ -289,7 +288,6 @@ func (c *threadSafeMap) deleteFromIndices(obj interface{}, key string) error { ...@@ -289,7 +288,6 @@ func (c *threadSafeMap) deleteFromIndices(obj interface{}, key string) error {
} }
} }
} }
return nil
} }
func (c *threadSafeMap) Resync() error { func (c *threadSafeMap) Resync() error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment