Ensure list of pods items is retrieved

Right now we attempt to retrieve the list of pods without
fetching the items field returned on the kubernetes response,
causing the wrong element to be fetched.

This commit fixes the issue by getting the list of pods
through the items.

Closes-bug: 1864451
Change-Id: I0144f68900011ba3b5c6373a439dc1df3a68f8ed
(cherry picked from commit 18a495ad83)
This commit is contained in:
Maysa Macedo 2020-02-24 10:55:36 +00:00 committed by Luis Tomas Bolivar
parent 4f0c489be5
commit 95289fae60
2 changed files with 4 additions and 2 deletions

View File

@ -308,7 +308,7 @@ def _parse_selectors_on_namespace(crd, direction, pod_selector,
sg_id, direction, pod_ip,
namespace=ns_name))
else:
ns_pods = driver_utils.get_pods(ns_selector)
ns_pods = driver_utils.get_pods(ns_selector)['items']
ns_cidr = driver_utils.get_namespace_subnet_cidr(namespace)
if 'ports' in rule_block:
for port in rule_block['ports']:

View File

@ -573,6 +573,8 @@ class TestNetworkPolicySecurityGroupsDriver(test_base.TestCase):
m_delete_sg_rule.assert_not_called()
m_patch_kuryrnetworkpolicy_crd.assert_not_called()
@mock.patch('kuryr_kubernetes.controller.drivers.utils.'
'get_pods')
@mock.patch('kuryr_kubernetes.controller.drivers.'
'network_policy_security_groups._create_sg_rule')
@mock.patch('kuryr_kubernetes.controller.drivers.utils.'
@ -580,7 +582,7 @@ class TestNetworkPolicySecurityGroupsDriver(test_base.TestCase):
@mock.patch('kuryr_kubernetes.controller.drivers.utils.'
'get_namespace_subnet_cidr')
def test__parse_rules(self, m_get_ns_subnet_cidr, m_match_selector,
m_create_sg_rule):
m_create_sg_rule, m_get_pods):
crd = get_crd_obj_no_match()
policy = crd['spec']['networkpolicy_spec']
i_rule = policy.get('ingress')[0]