Merge pull request #29672 from lixiaobing10051267/masterLen

Automatic merge from submit-queue

Add handling empty index key that may cause panic issue

if len(indexKeys) == 0, "return indexKeys[0]" will cause unexpected result.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/29672)
<!-- Reviewable:end -->
This commit is contained in:
Kubernetes Submit Queue 2016-08-10 14:29:45 -07:00 committed by GitHub
commit 48b7aca2c9

View File

@ -55,6 +55,9 @@ func IndexFuncToKeyFuncAdapter(indexFunc IndexFunc) KeyFunc {
if len(indexKeys) > 1 {
return "", fmt.Errorf("too many keys: %v", indexKeys)
}
if len(indexKeys) == 0 {
return "", fmt.Errorf("unexpected empty indexKeys")
}
return indexKeys[0], nil
}
}