Browse Source

Merge "Adapt selfLink calculation for any k8s objects."

changes/68/772568/1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
3e38af9a4c
21 changed files with 22 additions and 44 deletions
  1. +0
    -2
      doc/source/installation/network_policy.rst
  2. +0
    -1
      doc/source/specs/queens/network_policy.rst
  3. +2
    -3
      kuryr_kubernetes/handlers/retry.py
  4. +2
    -2
      kuryr_kubernetes/k8s_client.py
  5. +0
    -2
      kuryr_kubernetes/tests/fake.py
  6. +1
    -1
      kuryr_kubernetes/tests/unit/cni/plugins/test_k8s_cni_registry.py
  7. +0
    -1
      kuryr_kubernetes/tests/unit/controller/drivers/test_multi_vif.py
  8. +0
    -1
      kuryr_kubernetes/tests/unit/controller/drivers/test_namespace_subnet.py
  9. +2
    -6
      kuryr_kubernetes/tests/unit/controller/drivers/test_network_policy.py
  10. +4
    -8
      kuryr_kubernetes/tests/unit/controller/drivers/test_network_policy_security_groups.py
  11. +0
    -1
      kuryr_kubernetes/tests/unit/controller/drivers/test_vif_pool.py
  12. +0
    -1
      kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrnetwork.py
  13. +0
    -2
      kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrnetworkpolicy.py
  14. +0
    -1
      kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrport.py
  15. +0
    -1
      kuryr_kubernetes/tests/unit/controller/handlers/test_loadbalancer.py
  16. +1
    -3
      kuryr_kubernetes/tests/unit/controller/handlers/test_namespace.py
  17. +0
    -1
      kuryr_kubernetes/tests/unit/controller/handlers/test_pod_label.py
  18. +0
    -1
      kuryr_kubernetes/tests/unit/controller/handlers/test_policy.py
  19. +4
    -2
      kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py
  20. +6
    -2
      kuryr_kubernetes/tests/unit/handlers/test_retry.py
  21. +0
    -2
      kuryr_kubernetes/tests/unit/test_utils.py

+ 0
- 2
doc/source/installation/network_policy.rst View File

@ -182,7 +182,6 @@ Testing the network policy support functionality
name: test-network-policy
namespace: default
resourceVersion: "2117"
selfLink: /apis/openstack.org/v1/namespaces/default/kuryrnetworkpolicies/test-network-policy
uid: afb99326-c634-11e8-b63d-002564fdd760
spec:
egressSgRules:
@ -269,7 +268,6 @@ Testing the network policy support functionality
name: test-network-policy
namespace: default
resourceVersion: "1546"
selfLink: /apis/openstack.org/v1/namespaces/default/kuryrnetworkpolicies/np-test-network-policy
uid: afb99326-c634-11e8-b63d-002564fdd760
spec:
egressSgRules:


+ 0
- 1
doc/source/specs/queens/network_policy.rst View File

@ -240,7 +240,6 @@ that matched the named port.
name: np-allow-client-a-via-named-port-ingress-rule
namespace: default
resourceVersion: "66522"
selfLink: /apis/openstack.org/v1/namespaces/default/kuryrnetpolicies/np-allow-client-a-via-named-port-ingress-rule
uid: 66eee462-70d5-11e9-9986-fa163e6aa097
spec:
egressSgRules:


+ 2
- 3
kuryr_kubernetes/handlers/retry.py View File

@ -60,10 +60,9 @@ class Retry(base.EventHandler):
obj = event.get('object')
if obj:
try:
obj_link = obj['metadata']['selfLink']
obj_link = utils.get_res_link(obj)
except KeyError:
LOG.debug("Skipping object check as it does not have "
"selfLink: %s", obj)
LOG.debug("Unknown object, skipping: %s", obj)
else:
try:
self._k8s.get(obj_link)


+ 2
- 2
kuryr_kubernetes/k8s_client.py View File

@ -267,7 +267,7 @@ class K8sClient(object):
if finalizer in obj['metadata'].get('finalizers', []):
return True
path = obj['metadata']['selfLink']
path = utils.get_res_link(obj)
LOG.debug(f"Add finalizer {finalizer} to {path}")
url, headers = self._get_url_and_header(
path, 'application/merge-patch+json')
@ -307,7 +307,7 @@ class K8sClient(object):
self._raise_from_response(response)
def remove_finalizer(self, obj, finalizer):
path = obj['metadata']['selfLink']
path = utils.get_res_link(obj)
LOG.debug(f"Remove finalizer {finalizer} from {path}")
url, headers = self._get_url_and_header(
path, 'application/merge-patch+json')


+ 0
- 2
kuryr_kubernetes/tests/fake.py View File

@ -176,8 +176,6 @@ def get_k8s_pod():
'name': 'pod-5bb648d658-55n76',
'namespace': 'default',
'resourceVersion': '19416',
'selfLink': '/api/v1/namespaces/default/pods/'
'pod-5bb648d658-55n76',
'uid': '683da866-6bb1-4da2-bf6a-a5f4137c38e7'},
'spec': {},
'status': {}}

+ 1
- 1
kuryr_kubernetes/tests/unit/cni/plugins/test_k8s_cni_registry.py View File

@ -32,7 +32,7 @@ class TestK8sCNIRegistryPlugin(base.TestCase):
self.kp = {'apiVersion': 'openstack.org/v1',
'kind': 'KuryrPort',
'metadata': {'name': 'foo', 'uid': 'bar',
'namespace': 'default', 'selfLink': 'baz'},
'namespace': 'default'},
'spec': {'podUid': 'bar'}}
self.vifs = fake._fake_vifs()
registry = {'default/foo': {'kp': self.kp, 'vifs': self.vifs,


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/drivers/test_multi_vif.py View File

@ -42,7 +42,6 @@ def get_pod_obj():
'name': 'busybox-sleep1',
'namespace': 'default',
'resourceVersion': '53808',
'selfLink': '/api/v1/namespaces/default/pods/busybox-sleep1',
'uid': '452176db-4a85-11e7-80bd-fa163e29dbbb',
'annotations': {
'openstack.org/kuryr-vif': {},


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/drivers/test_namespace_subnet.py View File

@ -45,7 +45,6 @@ def get_pod_obj():
'name': 'busybox-sleep1',
'namespace': 'default',
'resourceVersion': '53808',
'selfLink': '/api/v1/namespaces/default/pods/busybox-sleep1',
'uid': '452176db-4a85-11e7-80bd-fa163e29dbbb',
'annotations': {
'openstack.org/kuryr-vif': {}


+ 2
- 6
kuryr_kubernetes/tests/unit/controller/drivers/test_network_policy.py View File

@ -41,7 +41,6 @@ def get_pod_obj():
'name': 'busybox-sleep1',
'namespace': 'default',
'resourceVersion': '53808',
'selfLink': '/api/v1/namespaces/default/pods/busybox-sleep1',
'uid': '452176db-4a85-11e7-80bd-fa163e29dbbb',
'annotations': {
'openstack.org/kuryr-vif': {}
@ -86,7 +85,6 @@ class TestNetworkPolicyDriver(test_base.TestCase):
'creationTimestamp': '2018-09-18T14:09:51Z',
'namespace': 'default',
'annotations': {},
'selfLink': self._policy_link,
'uid': self._policy_uid
},
'spec': {
@ -109,8 +107,7 @@ class TestNetworkPolicyDriver(test_base.TestCase):
self.crd = {
'metadata': {'name': 'foobar',
'namespace': 'default',
'selfLink': mock.sentinel.selfLink},
'namespace': 'default'},
'spec': {
'egressSgRules': [
{'sgRule':
@ -142,8 +139,7 @@ class TestNetworkPolicyDriver(test_base.TestCase):
self.old_crd = {
'metadata': {'name': 'np-foobar',
'namespace': 'default',
'selfLink': mock.sentinel.selfLink},
'namespace': 'default'},
'spec': {
'egressSgRules': [
{'security_group_rule':


+ 4
- 8
kuryr_kubernetes/tests/unit/controller/drivers/test_network_policy_security_groups.py View File

@ -30,8 +30,7 @@ def get_no_match_crd_namespace_obj():
"openstack.org/kuryr-net-crd": "ns-dev"
},
"labels": {"name": "prod"},
"name": "prod",
"selfLink": "/api/v1/namespaces/dev"}}
"name": "prod"}}
def get_match_crd_namespace_obj():
@ -45,8 +44,7 @@ def get_match_crd_namespace_obj():
"labels": {
"name": "dev"
},
"name": "dev",
"selfLink": "/api/v1/namespaces/dev"}}
"name": "dev"}}
def get_match_crd_pod_obj():
@ -155,8 +153,7 @@ class TestNetworkPolicySecurityGroupsDriver(test_base.TestCase):
self._sg_id2 = mock.sentinel._sg_id2
self._namespace = 'default'
self._crd = {
'metadata': {'name': mock.sentinel.name,
'selfLink': mock.sentinel.selfLink},
'metadata': {'name': mock.sentinel.name},
'spec': {
'egressSgRules': [
{'sgRule':
@ -196,8 +193,7 @@ class TestNetworkPolicySecurityGroupsDriver(test_base.TestCase):
}
self._crd2 = {
'metadata': {'name': mock.sentinel.name3,
'selfLink': mock.sentinel.selfLink},
'metadata': {'name': mock.sentinel.name3},
'spec': {
'ingressSgRules': [
{'sgRule':


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/drivers/test_vif_pool.py View File

@ -54,7 +54,6 @@ def get_pod_obj():
'name': 'busybox-sleep1',
'namespace': 'default',
'resourceVersion': '53808',
'selfLink': '/api/v1/namespaces/default/pods/busybox-sleep1',
'uid': '452176db-4a85-11e7-80bd-fa163e29dbbb',
'annotations': {
'openstack.org/kuryr-vif': {}


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrnetwork.py View File

@ -36,7 +36,6 @@ class TestKuryrNetworkHandler(test_base.TestCase):
self._kuryrnet_crd = {
'metadata': {
'name': 'ns-test-namespace',
'selfLink': 'test-selfLink',
},
'spec': {
'nsName': 'test-namespace',


+ 0
- 2
kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrnetworkpolicy.py View File

@ -45,7 +45,6 @@ class TestPolicyHandler(test_base.TestCase):
'creationTimestamp': '2018-09-18T14:09:51Z',
'namespace': 'default',
'annotations': {},
'selfLink': self._policy_link,
'uid': self._policy_uid
},
'spec': {
@ -104,7 +103,6 @@ class TestPolicyHandler(test_base.TestCase):
'apiVersion': 'openstack.org/v1',
'kind': 'KuryrNetPolicy',
'metadata': {
'selfLink': self_link,
'namespace': 'ns',
'name': 'old-knp'
}


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrport.py View File

@ -49,7 +49,6 @@ class TestKuryrPortHandler(test_base.TestCase):
self._pod = {'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {'resourceVersion': self._pod_version,
'selfLink': self._pod_link,
'name': self._kp_name,
'deletionTimestamp': mock.sentinel.date,
'namespace': self._kp_namespace},


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/handlers/test_loadbalancer.py View File

@ -41,7 +41,6 @@ def get_lb_crd():
"name": "test",
"namespace": "default",
"resourceVersion": "111871",
"selfLink": "test",
"uid": "584fe3ea-04dd-43f7-be2f-713e861694ec"
},
"spec": {


+ 1
- 3
kuryr_kubernetes/tests/unit/controller/handlers/test_namespace.py View File

@ -35,8 +35,7 @@ class TestNamespaceHandler(test_base.TestCase):
self._namespace_name = 'ns-test'
self._namespace = {
'metadata': {'name': self._namespace_name,
'resourceVersion': self._namespace_version,
'selfLink': self._namespace_link},
'resourceVersion': self._namespace_version},
'status': {'phase': 'Active'}
}
self._crd_id = 'ns-' + self._namespace_name
@ -57,7 +56,6 @@ class TestNamespaceHandler(test_base.TestCase):
crd = {
'kind': 'KuryrNet',
'metadata': {
'selfLink': mock.sentinel.self_link,
'name': self._namespace_name,
'namespace': self._namespace_name,
},


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/handlers/test_pod_label.py View File

@ -32,7 +32,6 @@ class TestPodLabelHandler(test_base.TestCase):
self._pod_link = mock.sentinel.pod_link
self._pod = {
'metadata': {'resourceVersion': self._pod_version,
'selfLink': self._pod_link,
'namespace': 'default'},
'status': {'phase': k_const.K8S_POD_STATUS_PENDING},
'spec': {'hostNetwork': False,


+ 0
- 1
kuryr_kubernetes/tests/unit/controller/handlers/test_policy.py View File

@ -41,7 +41,6 @@ class TestPolicyHandler(test_base.TestCase):
'creationTimestamp': '2018-09-18T14:09:51Z',
'namespace': 'default',
'annotations': {},
'selfLink': self._policy_link,
'uid': self._policy_uid
},
'spec': {


+ 4
- 2
kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py View File

@ -44,7 +44,7 @@ class TestVIFHandler(test_base.TestCase):
self._pod_version = mock.sentinel.pod_version
self._pod_link = mock.sentinel.pod_link
self._pod_namespace = mock.sentinel.namespace
self._pod_namespace = 'namespace1'
self._pod_uid = mock.sentinel.pod_uid
self._pod_name = 'pod1'
self._pod = fake.get_k8s_pod()
@ -351,4 +351,6 @@ class TestVIFHandler(test_base.TestCase):
m_get_k8s_client.assert_called_once()
k8s.remove_annotations.assert_called_once_with(
self._pod['metadata']['selfLink'], k_const.K8S_ANNOTATION_VIF)
f'/api/v1/namespaces/{self._pod["metadata"]["namespace"]}/'
f'pods/{self._pod["metadata"]["name"]}',
k_const.K8S_ANNOTATION_VIF)

+ 6
- 2
kuryr_kubernetes/tests/unit/handlers/test_retry.py View File

@ -103,14 +103,18 @@ class TestRetryHandler(test_base.TestCase):
def test_call_outdated_event(self, m_sleep, m_count):
m_handler = mock.Mock()
m_count.return_value = list(range(1, 5))
obj = {'metadata': {'selfLink': mock.sentinel.selflink}}
self_link = '/api/v1/namespaces/ns1/services/srv1'
obj = {'apiVersion': 'v1',
'kind': 'Service',
'metadata': {'name': 'srv1',
'namespace': 'ns1'}}
event = {'type': 'MODIFIED', 'object': obj}
self.k8s.get.side_effect = exceptions.K8sResourceNotFound(obj)
retry = h_retry.Retry(m_handler)
retry(event)
self.k8s.get.assert_called_once_with(obj['metadata']['selfLink'])
self.k8s.get.assert_called_once_with(self_link)
m_handler.assert_not_called()
m_sleep.assert_not_called()


+ 0
- 2
kuryr_kubernetes/tests/unit/test_utils.py View File

@ -116,7 +116,6 @@ class TestUtils(test_base.TestCase):
"metadata": {
"continue": "",
"resourceVersion": "33018",
"selfLink": "/apis/openstack.org/v1/kuryrnets"
}
}
@ -138,7 +137,6 @@ class TestUtils(test_base.TestCase):
"metadata": {
"continue": "",
"resourceVersion": "34186",
"selfLink": "/apis/openstack.org/v1/kuryrnetpolicies"
}
}
kubernetes = self.useFixture(k_fix.MockK8sClient()).client


Loading…
Cancel
Save