plugin/kubernetes: Don't panic with metadata enabled and pods mode not verified (#3869)

* prevent panic in podWithIP

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* add unit test, correct existing unit test

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* unit tests make more sense this way

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2020-05-04 04:17:26 -04:00 committed by GitHub
parent 5347bc38e7
commit a5e286ac4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View file

@ -51,6 +51,9 @@ func (k *Kubernetes) AutoPath(state request.Request) []string {
// podWithIP return the api.Pod for source IP. It returns nil if nothing can be found.
func (k *Kubernetes) podWithIP(ip string) *object.Pod {
if k.podMode != podModeVerified {
return nil
}
ps := k.APIConn.PodIndex(ip)
if len(ps) == 0 {
return nil