Skip to content

Commit

Permalink
metallb kind - wait added
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Osypenko <[email protected]>
  • Loading branch information
DanielOsypenko committed Apr 10, 2024
1 parent 2f2f5a6 commit 28658bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ocs_ci/deployment/metallb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
1 change: 1 addition & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 28658bc

Please sign in to comment.