Browse Source

Adapt selfLink calculation for KuryrPort CRD objects.

Implements: blueprint selflink
Change-Id: Ib86babcbbd2ebc7d7859047ab0f857220cc0460f
changes/30/768330/9
Roman Dobosz 2 months ago
parent
commit
31b96f3ecc
5 changed files with 21 additions and 13 deletions
  1. +2
    -1
      kuryr_kubernetes/cni/plugins/k8s_cni_registry.py
  2. +2
    -1
      kuryr_kubernetes/controller/handlers/kuryrport.py
  3. +2
    -2
      kuryr_kubernetes/controller/handlers/vif.py
  4. +3
    -1
      kuryr_kubernetes/tests/unit/cni/plugins/test_k8s_cni_registry.py
  5. +12
    -8
      kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrport.py

+ 2
- 1
kuryr_kubernetes/cni/plugins/k8s_cni_registry.py View File

@ -25,6 +25,7 @@ from kuryr_kubernetes.cni.plugins import base as base_cni
from kuryr_kubernetes.cni import utils
from kuryr_kubernetes import constants as k_const
from kuryr_kubernetes import exceptions
from kuryr_kubernetes import utils as k_utils
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
@ -61,7 +62,7 @@ class K8sCNIRegistryPlugin(base_cni.CNIPlugin):
if kp_name in self.registry:
cached_kp = self.registry[kp_name]['kp']
try:
kp = self.k8s.get(cached_kp['metadata']['selfLink'])
kp = self.k8s.get(k_utils.get_res_link(cached_kp))
except Exception:
LOG.exception('Error when getting KuryrPort %s', kp_name)
raise exceptions.ResourceNotReady(kp_name)


+ 2
- 1
kuryr_kubernetes/controller/handlers/kuryrport.py View File

@ -23,6 +23,7 @@ from kuryr_kubernetes.controller.drivers import base as drivers
from kuryr_kubernetes.controller.drivers import utils as driver_utils
from kuryr_kubernetes import exceptions as k_exc
from kuryr_kubernetes.handlers import k8s_base
from kuryr_kubernetes import utils
LOG = logging.getLogger(__name__)
KURYRPORT_URI = constants.K8S_API_CRD_NAMESPACES + '/{ns}/kuryrports/{crd}'
@ -274,7 +275,7 @@ class KuryrPortHandler(k8s_base.ResourceEventHandler):
vif_dict[ifname] = {'default': data['default'],
'vif': data['vif'].obj_to_primitive()}
self.k8s.patch_crd('status', kuryrport_crd['metadata']['selfLink'],
self.k8s.patch_crd('status', utils.get_res_link(kuryrport_crd),
{'vifs': vif_dict})
def _is_network_policy_enabled(self):


+ 2
- 2
kuryr_kubernetes/controller/handlers/vif.py View File

@ -61,7 +61,7 @@ class VIFHandler(k8s_base.ResourceEventHandler):
f'{utils.get_res_unique_name(kuryrport)} created '
f'for host networking pod. Deleting it.')
try:
k8s.delete(kuryrport['metadata']['selfLink'])
k8s.delete(utils.get_res_link(kuryrport))
except k_exc.K8sResourceNotFound:
pass
@ -137,7 +137,7 @@ class VIFHandler(k8s_base.ResourceEventHandler):
# annotations, force an emition of event to trigger on_finalize
# method on the KuryrPort.
try:
k8s.annotate(kp['metadata']['selfLink'], {'KuryrTrigger': '1'})
k8s.annotate(utils.get_res_link(kp), {'KuryrTrigger': '1'})
except k_exc.K8sResourceNotFound:
LOG.error('Cannot annotate existing KuryrPort %s.',
kp['metadata']['name'])


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

@ -29,7 +29,9 @@ class TestK8sCNIRegistryPlugin(base.TestCase):
self.k8s_mock = self.useFixture(kuryr_fixtures.MockK8sClient()).client
self.default_iface = 'baz'
self.additional_iface = 'eth1'
self.kp = {'metadata': {'name': 'foo', 'uid': 'bar',
self.kp = {'apiVersion': 'openstack.org/v1',
'kind': 'KuryrPort',
'metadata': {'name': 'foo', 'uid': 'bar',
'namespace': 'default', 'selfLink': 'baz'},
'spec': {'podUid': 'bar'}}
self.vifs = fake._fake_vifs()


+ 12
- 8
kuryr_kubernetes/tests/unit/controller/handlers/test_kuryrport.py View File

@ -25,6 +25,7 @@ from kuryr_kubernetes.controller.handlers import kuryrport
from kuryr_kubernetes import exceptions as k_exc
from kuryr_kubernetes.tests import base as test_base
from kuryr_kubernetes.tests.unit import kuryr_fixtures as k_fix
from kuryr_kubernetes import utils
CONF = cfg.CONF
@ -41,12 +42,13 @@ class TestKuryrPortHandler(test_base.TestCase):
self._pod_version = mock.sentinel.pod_version
self._pod_link = mock.sentinel.pod_link
self._kp_version = mock.sentinel.kp_version
self._kp_link = mock.sentinel.kp_link
self._kp_namespace = mock.sentinel.namespace
self._kp_uid = mock.sentinel.kp_uid
self._kp_name = 'pod1'
self._pod = {'metadata': {'resourceVersion': self._pod_version,
self._pod = {'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {'resourceVersion': self._pod_version,
'selfLink': self._pod_link,
'name': self._kp_name,
'deletionTimestamp': mock.sentinel.date,
@ -54,9 +56,10 @@ class TestKuryrPortHandler(test_base.TestCase):
'spec': {'nodeName': self._host}}
self._kp = {
'apiVersion': 'openstack.org/v1',
'kind': 'KuryrPort',
'metadata': {
'resourceVersion': self._kp_version,
'selfLink': self._kp_link,
'name': self._kp_name,
'namespace': self._kp_namespace,
'labels': {
@ -69,6 +72,7 @@ class TestKuryrPortHandler(test_base.TestCase):
},
'status': {'vifs': {}}
}
self._vif1 = os_obj.vif.VIFBase()
self._vif2 = os_obj.vif.VIFBase()
self._vif1.active = False
@ -696,11 +700,11 @@ class TestKuryrPortHandler(test_base.TestCase):
vif1 = self._vif1.obj_to_primitive()
vif2 = self._vif2.obj_to_primitive()
kp.k8s.patch_crd.assert_called_once_with(
'status', self._kp_link, {'vifs': {'eth0': {'default': True,
'vif': vif1},
'eth1': {'default': False,
'vif': vif2}}})
arg = {'vifs': {'eth0': {'default': True, 'vif': vif1},
'eth1': {'default': False, 'vif': vif2}}}
kp.k8s.patch_crd.assert_called_once_with('status',
utils.get_res_link(self._kp),
arg)
@mock.patch('kuryr_kubernetes.clients.get_kubernetes_client')
@mock.patch('kuryr_kubernetes.controller.drivers.base.MultiVIFDriver.'


Loading…
Cancel
Save