Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/mas/devops/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,95 @@ def updateGlobalPullSecret(dynClient: DynamicClient, registryUrl: str, username:
"registry": registryUrl,
"changed": True
}


def configureIngressForPathBasedRouting(dynClient: DynamicClient, ingressControllerName: str = "default") -> bool:
"""
Configure OpenShift IngressController for path-based routing.

Sets the namespaceOwnership to InterNamespaceAllowed on the specified IngressController,
which is required for path-based routing mode in MAS.

Args:
dynClient: OpenShift Dynamic Client
ingressControllerName (optional): Name of the IngressController to configure. Defaults to "default".

Returns:
bool: True if configuration was successful or already configured, False otherwise

Raises:
NotFoundError: If the IngressController resource cannot be found
"""
logger.info(f"Configuring IngressController '{ingressControllerName}' for path-based routing")

try:
ingressControllerAPI = dynClient.resources.get(
api_version="operator.openshift.io/v1",
kind="IngressController"
)

try:
ingressController = ingressControllerAPI.get(
name=ingressControllerName,
namespace="openshift-ingress-operator"
)
except NotFoundError:
logger.error(f"IngressController '{ingressControllerName}' not found in namespace 'openshift-ingress-operator'")
return False

currentPolicy = None
if hasattr(ingressController, 'spec') and hasattr(ingressController.spec, 'routeAdmission'):
if hasattr(ingressController.spec.routeAdmission, 'namespaceOwnership'):
currentPolicy = ingressController.spec.routeAdmission.namespaceOwnership

logger.debug(f"Current namespaceOwnership policy: {currentPolicy if currentPolicy else 'Not set'}")

if currentPolicy == "InterNamespaceAllowed":
logger.info(f"IngressController '{ingressControllerName}' is already configured with namespaceOwnership: InterNamespaceAllowed")
return True

logger.info(f"Patching IngressController '{ingressControllerName}' to enable InterNamespaceAllowed")

patch = {
"spec": {
"routeAdmission": {
"namespaceOwnership": "InterNamespaceAllowed"
}
}
}

ingressControllerAPI.patch(
body=patch,
name=ingressControllerName,
namespace="openshift-ingress-operator",
content_type="application/merge-patch+json"
)

maxRetries = 5
retryDelay = 5

for attempt in range(maxRetries):
sleep(retryDelay)
try:
updatedController = ingressControllerAPI.get(
name=ingressControllerName,
namespace="openshift-ingress-operator"
)

if (hasattr(updatedController, 'spec') and hasattr(updatedController.spec, 'routeAdmission') and hasattr(updatedController.spec.routeAdmission, 'namespaceOwnership') and updatedController.spec.routeAdmission.namespaceOwnership == "InterNamespaceAllowed"):

logger.info(f"Successfully configured IngressController '{ingressControllerName}' for path-based routing")
return True

except NotFoundError:
logger.warning(f"IngressController '{ingressControllerName}' not found during verification (attempt {attempt + 1}/{maxRetries})")

if attempt < maxRetries - 1:
logger.debug(f"Waiting for IngressController to reconcile (attempt {attempt + 1}/{maxRetries})")

logger.error(f"Failed to verify IngressController configuration after {maxRetries} attempts")
return False

except Exception as e:
logger.error(f"Failed to configure IngressController '{ingressControllerName}': {str(e)}")
return False
4 changes: 0 additions & 4 deletions src/mas/devops/templates/pipelinerun-install.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,6 @@ spec:
- name: mas_ingress_controller_name
value: "{{ mas_ingress_controller_name }}"
{%- endif %}
{%- if mas_configure_ingress is defined and mas_configure_ingress != "" %}
- name: mas_configure_ingress
value: "{{ mas_configure_ingress }}"
{%- endif %}

# MAS Workspace
# -------------------------------------------------------------------------
Expand Down