Skip to content

Commit

Permalink
Merge pull request #731 from openshift-cherrypick-robot/cherry-pick-7…
Browse files Browse the repository at this point in the history
…26-to-release-4.12

[release-4.12] OCPBUGS-13778: KuryrPort cleanup: Fix issue of subport not found
  • Loading branch information
openshift-merge-robot committed Jun 14, 2023
2 parents cc1d1fb + 5a765db commit 31dd228
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions kuryr_kubernetes/constants.py
Expand Up @@ -48,6 +48,8 @@
K8S_POD_STATUS_SUCCEEDED = 'Succeeded'
K8S_POD_STATUS_FAILED = 'Failed'

K8S_NODE_ADDRESS_INTERNAL = 'InternalIP'

K8S_ANNOTATION_PREFIX = 'openstack.org/kuryr'
K8S_ANNOTATION_VIF = K8S_ANNOTATION_PREFIX + '-vif'
K8S_ANNOTATION_LABEL = K8S_ANNOTATION_PREFIX + '-pod-label'
Expand Down
28 changes: 25 additions & 3 deletions kuryr_kubernetes/controller/handlers/kuryrport.py
Expand Up @@ -156,9 +156,31 @@ def _mock_cleanup_pod(self, kuryrport_crd):
main_vif = objects.base.VersionedObject.obj_from_primitive(
kuryrport_crd['status']['vifs'][constants.DEFAULT_IFNAME]
['vif'])
port_id = utils.get_parent_port_id(main_vif)
host_ip = utils.get_parent_port_ip(port_id)
pod['status'] = {'hostIP': host_ip}

# Let's try to get the node's address using nodeName saved in CRD
host_ip = None
try:
node = self.k8s.get(f"{constants.K8S_API_BASE}/nodes/"
f"{kuryrport_crd['spec']['podNodeName']}")
for address in node['status']['addresses']:
if address['type'] == constants.K8S_NODE_ADDRESS_INTERNAL:
host_ip = address['address']
break
except k_exc.K8sClientException:
LOG.warning('Could not find node %s when cleaning up port.',
kuryrport_crd['spec']['podNodeName'])

if not host_ip:
# We can still try to use OpenStack API if this is nested VIF
port_id = utils.get_parent_port_id(main_vif)
if port_id:
host_ip = utils.get_parent_port_ip(port_id)

if host_ip:
pod['status'] = {'hostIP': host_ip}

# If we failed to find host_ip we still allow cleanup to follow, we
# catch all exceptions from release_vif anyway.
return pod

def on_finalize(self, kuryrport_crd, *args, **kwargs):
Expand Down
Expand Up @@ -97,6 +97,7 @@ def setUp(self):
f"/{self._kp['metadata']['namespace']}/pods/"
f"{self._kp['metadata']['name']}")
self._kp_uri = utils.get_res_link(self._kp)
self._node_uri = f"{constants.K8S_API_BASE}/nodes/{self._host}"
self.useFixture(k_fix.MockNetworkClient())
self._driver = multi_vif.NoopMultiVIFDriver()

Expand Down Expand Up @@ -337,7 +338,8 @@ def test_on_finalize_exception_on_pod(self, ged, k8s, gppip, gppid,

self.assertIsNone(kp.on_finalize(self._kp))

k8s.get.assert_called_once_with(self._pod_uri)
k8s.get.assert_has_calls([mock.call(self._pod_uri),
mock.call(self._node_uri)])
k8s.remove_finalizer.assert_has_calls(
(mock.call(mock.ANY, constants.POD_FINALIZER),
mock.call(self._kp, constants.KURYRPORT_FINALIZER)))
Expand Down

0 comments on commit 31dd228

Please sign in to comment.