Browse Source

Adapt selfLink calculation for Pod objects.

Implements: blueprint selflink
Change-Id: Ie98aae21ef910f11eaff5a6f6814d16ee1542ff2
changes/29/768329/9
Roman Dobosz 2 months ago
parent
commit
b521fee8cb
10 changed files with 52 additions and 33 deletions
  1. +2
    -1
      kuryr_kubernetes/cmd/status.py
  2. +2
    -1
      kuryr_kubernetes/controller/drivers/sriov.py
  3. +2
    -1
      kuryr_kubernetes/controller/handlers/pod_label.py
  4. +1
    -1
      kuryr_kubernetes/controller/handlers/vif.py
  5. +2
    -1
      kuryr_kubernetes/os_vif_util.py
  6. +20
    -0
      kuryr_kubernetes/tests/fake.py
  7. +5
    -3
      kuryr_kubernetes/tests/unit/cmd/test_status.py
  8. +11
    -14
      kuryr_kubernetes/tests/unit/controller/drivers/test_sriov.py
  9. +4
    -9
      kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py
  10. +3
    -2
      kuryr_kubernetes/tests/unit/test_os_vif_util.py

+ 2
- 1
kuryr_kubernetes/cmd/status.py View File

@ -34,6 +34,7 @@ from kuryr_kubernetes import constants
from kuryr_kubernetes import exceptions
from kuryr_kubernetes import objects
from kuryr_kubernetes.objects import vif
from kuryr_kubernetes import utils
from kuryr_kubernetes import version
CONF = config.CONF
@ -173,7 +174,7 @@ class UpgradeCommands(object):
jsonutils.dumps(serialized)
}
self.k8s.annotate(
pod['metadata']['selfLink'], ann,
utils.get_res_link(pod), ann,
pod['metadata']['resourceVersion'])
except exceptions.K8sClientException:
print('Error when updating annotation for pod %s/%s' %


+ 2
- 1
kuryr_kubernetes/controller/drivers/sriov.py View File

@ -22,6 +22,7 @@ from kuryr_kubernetes import constants
from kuryr_kubernetes.controller.drivers import neutron_vif
from kuryr_kubernetes.controller.drivers import utils as c_utils
from kuryr_kubernetes import os_vif_util as ovu
from kuryr_kubernetes import utils
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
@ -64,7 +65,7 @@ class SriovVIFDriver(neutron_vif.NeutronPodVIFDriver):
vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets)
vif.physnet = physnet
vif.pod_name = pod_name
vif.pod_link = pod['metadata']['selfLink']
vif.pod_link = utils.get_res_link(pod)
LOG.debug("{} vifs are available for the pod {}".format(
amount, pod_name))


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

@ -22,6 +22,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__)
@ -97,7 +98,7 @@ class PodLabelHandler(k8s_base.ResourceEventHandler):
LOG.debug("Setting info annotations: %r", annotation)
k8s = clients.get_kubernetes_client()
k8s.annotate(pod['metadata']['selfLink'],
k8s.annotate(utils.get_res_link(pod),
{
constants.K8S_ANNOTATION_LABEL: annotation[0],
constants.K8S_ANNOTATION_IP: annotation[1]


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

@ -240,7 +240,7 @@ class VIFHandler(k8s_base.ResourceEventHandler):
raise k_exc.ResourceNotReady(pod)
k8s = clients.get_kubernetes_client()
k8s.remove_annotations(pod['metadata']['selfLink'],
k8s.remove_annotations(utils.get_res_link(pod),
constants.K8S_ANNOTATION_VIF)
return True

+ 2
- 1
kuryr_kubernetes/os_vif_util.py View File

@ -33,6 +33,7 @@ from kuryr_kubernetes import config
from kuryr_kubernetes import constants as const
from kuryr_kubernetes import exceptions as k_exc
from kuryr_kubernetes.objects import vif as k_vif
from kuryr_kubernetes import utils
LOG = logging.getLogger(__name__)
@ -400,7 +401,7 @@ def neutron_to_osvif_vif_dpdk(os_port, subnets, pod):
details = os_port.get('binding:vif_details', {})
profile = osv_vif.VIFPortProfileK8sDPDK(
l3_setup=False,
selflink=pod['metadata']['selfLink'])
selflink=utils.get_res_link(pod))
return k_vif.VIFDPDKNested(
id=os_port['id'],


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

@ -161,3 +161,23 @@ def get_sgr_obj(sgr_id='7621d1e0-a2d2-4496-94eb-ffd375d20877',
'tenant_id': '5ea46368c7fe436bb8732738c149fbce'}
return os_sgr.SecurityGroupRule(**sgr_data)
def get_k8s_pod():
return {'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {'creationTimestamp': '2020-12-22T09:04:29Z',
'finalizers': ['kuryr.openstack.org/pod-finalizer'],
'generateName': 'pod-5bb648d658-',
'labels': {'app': 'pod',
'pod-template-hash': '5bb648d658'},
'operation': 'Update',
'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': {}}

+ 5
- 3
kuryr_kubernetes/tests/unit/cmd/test_status.py View File

@ -161,11 +161,13 @@ class TestStatusCmd(test_base.TestCase):
pods = {
'items': [
{
'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {
'annotations': {
constants.K8S_ANNOTATION_VIF: ann
},
'selfLink': name,
'name': name,
'resourceVersion': 1,
}
} for name, ann in ann_objs
@ -178,8 +180,8 @@ class TestStatusCmd(test_base.TestCase):
def test_update_annotations(self):
self._test__convert_annotations(self.cmd.update_annotations,
[('bar', mock.ANY, 1)])
[('/api/v1/pods/bar', mock.ANY, 1)])
def test_downgrade_annotations(self):
self._test__convert_annotations(self.cmd.downgrade_annotations,
[('foo', mock.ANY, 1)])
[('/api/v1/pods/foo', mock.ANY, 1)])

+ 11
- 14
kuryr_kubernetes/tests/unit/controller/drivers/test_sriov.py View File

@ -17,6 +17,7 @@ import uuid
from kuryr_kubernetes.controller.drivers import sriov as drvs
from kuryr_kubernetes.tests import base as test_base
from kuryr_kubernetes.tests import fake
from kuryr_kubernetes.tests.unit import kuryr_fixtures as k_fix
from kuryr_kubernetes import constants as k_const
@ -49,23 +50,19 @@ class TestSriovVIFDriver(test_base.TestCase):
drvs.sriov_make_resource(k_const.K8S_SRIOV_PREFIX,
SRIOV_RESOURCE_NAME_B): (
str(AMOUNT_FOR_SUBNET_B))}
self._pod = {
'metadata': {
'resourceVersion': mock.sentinel.pod_version,
'selfLink': mock.sentinel.pod_link,
'name': 'podname'},
'status': {'phase': k_const.K8S_POD_STATUS_PENDING},
'spec': {
'hostNetwork': False,
'nodeName': 'hostname',
'containers': [{
self._pod = fake.get_k8s_pod()
self._pod['status'] = {'phase': k_const.K8S_POD_STATUS_PENDING}
self._pod['spec'] = {
'hostNetwork': False,
'nodeName': 'hostname',
'containers': [
{
'resources': {
'requests': sriov_request
}
}]
}
}
}
]
}
def test_activate_vif(self):
cls = drvs.SriovVIFDriver


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

@ -24,6 +24,7 @@ from kuryr_kubernetes.controller.handlers import vif as h_vif
from kuryr_kubernetes import exceptions as k_exc
from kuryr_kubernetes.objects import vif
from kuryr_kubernetes.tests import base as test_base
from kuryr_kubernetes.tests import fake
class TestVIFHandler(test_base.TestCase):
@ -46,15 +47,9 @@ class TestVIFHandler(test_base.TestCase):
self._pod_namespace = mock.sentinel.namespace
self._pod_uid = mock.sentinel.pod_uid
self._pod_name = 'pod1'
self._pod = {
'metadata': {'resourceVersion': self._pod_version,
'selfLink': self._pod_link,
'name': self._pod_name,
'namespace': self._pod_namespace},
'status': {'phase': k_const.K8S_POD_STATUS_PENDING},
'spec': {'hostNetwork': False,
'nodeName': 'hostname'}
}
self._pod = fake.get_k8s_pod()
self._pod['status'] = {'phase': k_const.K8S_POD_STATUS_PENDING}
self._pod['spec'] = {'hostNetwork': False, 'nodeName': 'hostname'}
self._kp_version = mock.sentinel.kp_version
self._kp_link = mock.sentinel.kp_link


+ 3
- 2
kuryr_kubernetes/tests/unit/test_os_vif_util.py View File

@ -29,6 +29,7 @@ from kuryr_kubernetes import exceptions as k_exc
from kuryr_kubernetes import os_vif_util as ovu
from kuryr_kubernetes.tests import base as test_base
from kuryr_kubernetes.tests import fake
from kuryr_kubernetes import utils
# REVISIT(ivc): move to kuryr-lib along with 'os_vif_util'
@ -455,7 +456,7 @@ class TestOSVIFUtils(test_base.TestCase):
m_mk_vif.return_value = vif
m_mk_port_profile.return_value = port_profile
pod = mock.MagicMock()
pod = fake.get_k8s_pod()
port = {'id': port_id,
'mac_address': mac_address,
@ -471,7 +472,7 @@ class TestOSVIFUtils(test_base.TestCase):
m_get_vif_name.assert_called_once_with(port)
m_mk_port_profile.assert_called_once_with(
l3_setup=False,
selflink=pod['metadata']['selfLink'])
selflink=utils.get_res_link(pod))
m_mk_vif.assert_called_once_with(
id=port_id,


Loading…
Cancel
Save