From ea031b8565686ae418d51154954c69f441415db3 Mon Sep 17 00:00:00 2001 From: Salvatore Daniele Date: Mon, 24 Jun 2024 11:12:25 -0400 Subject: [PATCH] Add check to ensure CRDs are in place Signed-off-by: Salvatore Daniele --- extraConfigSriov.py | 3 ++- k8sClient.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/extraConfigSriov.py b/extraConfigSriov.py index 9369e247..72f863b5 100644 --- a/extraConfigSriov.py +++ b/extraConfigSriov.py @@ -117,6 +117,7 @@ def _sno_make_deploy( break # Future proof for when sriov moves to new switchdev implementation: https://github.com/k8snetworkplumbingwg/sriov-network-operator/blob/master/doc/design/switchdev-refactoring.md + client.wait_for_crd(name="default", cr_name="sriovoperatorconfig", namespace="openshift-sriov-network-operator") client.oc("apply -f manifests/nicmode/sriov-operator-config.yaml") @@ -152,8 +153,8 @@ def ExtraConfigSriovSubscription(cc: ClustersConfig, cfg: ExtraConfigArgs, futur client.oc("create -f manifests/nicmode/sriov-operator-group.yaml") client.oc("create -f manifests/nicmode/sriov-subscription.yaml") + client.wait_for_crd(name="default", cr_name="sriovoperatorconfig", namespace="openshift-sriov-network-operator") client.oc("apply -f manifests/nicmode/sriov-operator-config.yaml") - _check_sriov_installed(client) diff --git a/k8sClient.py b/k8sClient.py index 6b2b7650..c89ab84c 100644 --- a/k8sClient.py +++ b/k8sClient.py @@ -85,3 +85,16 @@ def wait_for_mcp(self, mcp_name: str, resource: str = "resource") -> None: time.sleep(60) minutes, seconds = divmod(int(time.time() - start), 60) logger.info(f"It took {minutes}m {seconds}s for {resource} (attempts: {iteration})") + + + def wait_for_crd(self, name: str, cr_name: str, namespace: str) -> None: + logger.info(f"Waiting for crd {cr_name} to become available") + ret = self.oc(f"get {cr_name}/{name} -n {namespace}") + retries = 10 + while ret.returncode != 0: + time.sleep(10) + ret = self.oc(f"get {cr_name}/{name} -n {namespace}") + retries -= 1 + if retries <= 0: + logger.error_and_exit(f"Failed to get cr {cr_name}/{name}") +