Skip to content

Commit cbb3406

Browse files
albarker-rhrlobilloclaude
authored
CherryPicked: [cnv-4.20] [IUO]fix: Catch NotFoundError when pods are deleted during iteration (RedHatQE#4439)
4.21 cherry pick: (RedHatQE#4376) Cherry pick of (RedHatQE#3676) Same problematic code in 4.20, 4.19, 4.18 too Replace invalid exception handling that attempted to compare ex.reason (string) with ResourceNotFoundError (exception class), causing TypeError. When pod.instance.metadata is accessed for a deleted pod, the kubernetes dynamic client raises NotFoundError (which inherits from ApiException). The original code had invalid syntax trying to compare the HTTP reason string with an exception class. Changed from: except ApiException as ex: if ex.reason == ResourceNotFoundError: To: except NotFoundError: This correctly catches the NotFoundError when a pod is deleted during iteration and gracefully ignores it, following the established pattern in the codebase (tests/infrastructure/conftest.py). Also removed unused imports: ApiException and ResourceNotFoundError. Fixes test failures: - test_change_subscription_on_selected_node_before_workload - test_infrastructure_components_selection_change_allowed_after_workloads - N/A N/A https://redhat.atlassian.net/browse/CNV-83861 ##### Short description: ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: ##### jira-ticket: <!-- full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged If the task is not tracked by a Jira ticket, just write "NONE". --> Signed-off-by: Alex <albarker@redhat.com> Co-authored-by: Ramon Lobillo Mateos <62110535+rlobillo@users.noreply.github.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 0c03ea4 commit cbb3406

File tree

1 file changed

+3
-7
lines changed
  • tests/install_upgrade_operators/node_component

1 file changed

+3
-7
lines changed

tests/install_upgrade_operators/node_component/utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import logging
22
from collections import defaultdict
33

4-
from kubernetes.client.rest import ApiException
5-
from kubernetes.dynamic.exceptions import NotFoundError, ResourceNotFoundError
4+
from kubernetes.dynamic.exceptions import NotFoundError
65
from ocp_resources.pod import Pod
76
from ocp_resources.resource import ResourceEditor
87
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
@@ -366,11 +365,8 @@ def _get_pods_per_nodes(_filter_pods_by_name):
366365
# to filter out terminating pods, see: https://github.com/kubernetes/kubectl/issues/450
367366
if pod.instance.metadata.get("deletionTimestamp") is None:
368367
pods_per_nodes[pod.node.name].append(pod)
369-
except ApiException as ex:
370-
if ex.reason == ResourceNotFoundError:
371-
LOGGER.debug(
372-
f"Ignoring pods that disappeared during the query. node={pod.node.name} pod={pod.name}"
373-
)
368+
except NotFoundError:
369+
LOGGER.warning(f"Ignoring pods that disappeared during the query. node={pod.node.name} pod={pod.name}")
374370
return pods_per_nodes
375371

376372
pod_names_per_nodes = {}

0 commit comments

Comments
 (0)