Skip to content

Commit 2021978

Browse files
authored
[4.21] net, bgp: wait for network operator readiness before BGP setup (#5107)
##### What this PR does / why we need it: - replace brittle Deployment name wait (frr-k8s-statuscleaner) with wait_for_consistent_resource_conditions on ClusterOperator/network, ensuring FRR CRDs and webhooks are ready before creating FRRConfiguration - remove explicit FRR namespace cleanup, relying on CNO to handle revert - add type annotations to wait_for_consistent_resource_conditions ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: manual cherry-pick of #4876 (automated one is failed) ##### jira-ticket: https://redhat.atlassian.net/browse/CNV-78491 Signed-off-by: Sergei Volkov <sevolkov@redhat.com>
1 parent a32a05f commit 2021978

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

tests/network/libs/bgp.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@
99
from kubernetes.dynamic import DynamicClient
1010
from kubernetes.dynamic.exceptions import ResourceNotFoundError
1111
from ocp_resources.bgp_session_state import BGPSessionState
12-
from ocp_resources.deployment import Deployment
12+
from ocp_resources.cluster_operator import ClusterOperator
1313
from ocp_resources.frr_configuration import FRRConfiguration
14-
from ocp_resources.namespace import Namespace
1514
from ocp_resources.pod import Pod
1615
from ocp_resources.resource import ResourceEditor
1716
from ocp_resources.route_advertisements import RouteAdvertisements
1817
from timeout_sampler import retry
1918

2019
from libs.net.vmspec import IpNotFound
21-
from utilities.constants import NET_UTIL_CONTAINER_IMAGE
22-
from utilities.infra import get_resources_by_name_prefix
20+
from utilities.constants import DEFAULT_RESOURCE_CONDITIONS, NET_UTIL_CONTAINER_IMAGE
21+
from utilities.infra import get_resources_by_name_prefix, wait_for_consistent_resource_conditions
2322

2423
_CLUSTER_FRR_ASN: Final[int] = 64512
2524
_EXTERNAL_FRR_ASN: Final[int] = 64000
2625
_EXTERNAL_FRR_IMAGE: Final[str] = "quay.io/frrouting/frr:9.1.2"
27-
_FRR_DEPLOYMENT_NAME: Final[str] = "frr-k8s-statuscleaner"
2826
_FRR_NS_NAME: Final[str] = "openshift-frr-k8s"
2927
POD_SECONDARY_IFACE_NAME: Final[str] = "net1"
3028
EXTERNAL_FRR_POD_LABEL: Final[dict] = {"role": "frr-external"}
@@ -40,16 +38,13 @@ class ExternalFrrPodInfo:
4038
def enable_route_advertisements_in_cluster(
4139
network_resource: openshift_nc.Network, client: DynamicClient
4240
) -> Generator[None]:
43-
"""Enables route advertisements in the cluster network resource and deploys the FRR deployment.
41+
"""Enables route advertisements in the cluster network resource and deploys FRR.
4442
4543
Within the context, the cluster network resource is patched to enable
4644
additional routing capabilities with FRR and to enable route advertisements for OVN-Kubernetes.
47-
The FRR deployment is then created in the designated namespace and waits for its replicas to be ready.
45+
Waits for the network ClusterOperator to stabilize before proceeding.
4846
49-
After the context is exited, the changes are reverted and the FRR namespace is cleaned up.
50-
The cleanup is expected by the un-patching of the changes (ResourceEditor cleanup).
51-
However, it has been observed that the NS is not removed
52-
and therefore an explicit delete on the NS is performed.
47+
After the context is exited, the changes are reverted.
5348
5449
Args:
5550
network_resource (openshift_nc.Network): The cluster network resource to be patched.
@@ -68,13 +63,14 @@ def enable_route_advertisements_in_cluster(
6863
}
6964

7065
with ResourceEditor(patches=patch):
71-
deployment = Deployment(name=_FRR_DEPLOYMENT_NAME, namespace=_FRR_NS_NAME, client=client)
72-
deployment.wait_for_replicas()
73-
66+
wait_for_consistent_resource_conditions(
67+
dynamic_client=client,
68+
resource_kind=ClusterOperator,
69+
resource_name=network_resource.kind.lower(),
70+
expected_conditions=DEFAULT_RESOURCE_CONDITIONS,
71+
)
7472
yield
7573

76-
Namespace(name=_FRR_NS_NAME, client=client).clean_up()
77-
7874

7975
def create_cudn_route_advertisements(name: str, match_labels: dict, client: DynamicClient) -> RouteAdvertisements:
8076
"""Creates a RouteAdvertisements object for a ClusterUserDefinedNetwork (CUDN) based on the provided labels.

utilities/infra.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,19 @@ def get_daemonset_by_name(admin_client, daemonset_name, namespace_name):
327327

328328

329329
def wait_for_consistent_resource_conditions(
330-
dynamic_client,
331-
expected_conditions,
332-
resource_kind,
333-
stop_conditions=None,
334-
condition_key1="type",
335-
condition_key2="status",
336-
namespace=None,
337-
total_timeout=TIMEOUT_10MIN,
338-
polling_interval=5,
339-
consecutive_checks_count=10,
340-
exceptions_dict=None,
341-
resource_name=None,
342-
):
330+
dynamic_client: DynamicClient,
331+
expected_conditions: dict[str, str],
332+
resource_kind: type[Resource],
333+
stop_conditions: dict[str, str] | None = None,
334+
condition_key1: str = "type",
335+
condition_key2: str = "status",
336+
namespace: str | None = None,
337+
total_timeout: int = TIMEOUT_10MIN,
338+
polling_interval: int = 5,
339+
consecutive_checks_count: int = 10,
340+
exceptions_dict: dict[type[Exception], list[str]] | None = None,
341+
resource_name: str | None = None,
342+
) -> None:
343343
"""This function awaits certain conditions of a given resource_kind (HCO, CSV, etc.).
344344
345345
Using TimeoutSampler loop and poll the CR (of the resource_kind type) and attempt to match the expected conditions

0 commit comments

Comments
 (0)