From 28658bc01a8f768820e0005702c000ac12439c37 Mon Sep 17 00:00:00 2001 From: Daniel Osypenko Date: Wed, 10 Apr 2024 17:22:04 +0300 Subject: [PATCH] metallb kind - wait added Signed-off-by: Daniel Osypenko --- ocs_ci/deployment/metallb.py | 29 +++++++++++++++++++++++++++++ ocs_ci/ocs/constants.py | 1 + 2 files changed, 30 insertions(+) diff --git a/ocs_ci/deployment/metallb.py b/ocs_ci/deployment/metallb.py index 3ee68f8dc8f3..388cd4fccb86 100644 --- a/ocs_ci/deployment/metallb.py +++ b/ocs_ci/deployment/metallb.py @@ -265,6 +265,24 @@ def metallb_instance_created(self): resource_name="metallb", ) + def metallb_kind_available(self): + """ + Check if MetalLB Kind is available + This method is a hack to avoid 'Error is error: the server doesn't have a resource type "MetalLB"' or time.sleep + + Returns: + bool: True if MetalLB Kind is available, False otherwise + """ + return bool( + len( + ( + exec_cmd("oc api-resources | grep MetalLB", shell=True) + .stdout.decode("utf-8") + .strip() + ) + ) + ) + def create_metallb_instance(self): """ Create MetalLB instance @@ -276,6 +294,17 @@ def create_metallb_instance(self): logger.info("MetalLB instance already exists") return + # hack to avoid Error is error: the server doesn't have a resource type "MetalLB" + # that appears even after csv is installed and operator pods are running + for sample in TimeoutSampler( + timeout=10 * 60, + sleep=15, + func=self.metallb_kind_available, + ): + if sample: + logger.info("MetalLB api is available") + break + logger.info("Creating MetalLB instance") metallb_inst_data = templating.load_yaml(constants.METALLB_INSTANCE_YAML) metallb_inst_data.get("metadata").update({"namespace": self.namespace_lb}) diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 4146f3f26316..2336124c035a 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -854,6 +854,7 @@ METALLB_CONTROLLER_MANAGER_PREFIX = "metallb-operator-controller-manager" METALLB_WEBHOOK_PREFIX = "metallb-operator-webhook-server" METALLB_DEFAULT_NAMESPACE = "metallb-system" +METALLB_KIND = "MetalLB" METALLB_OPERATOR_GROUP_YAML = os.path.join( TEMPLATE_DEPLOYMENT_DIR_METALLB, "operator-group.yaml" )