Skip to content

Commit f695f43

Browse files
dixitgsathwaraDixit Sathwara
andauthored
[minor] Add configureIngressForPathBasedRouting() (#183)
Co-authored-by: Dixit Sathwara <Dixit.Sathwara1@ibm.com>
1 parent 1ac6fbb commit f695f43

2 files changed

Lines changed: 92 additions & 4 deletions

File tree

src/mas/devops/ocp.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,95 @@ def updateGlobalPullSecret(dynClient: DynamicClient, registryUrl: str, username:
632632
"registry": registryUrl,
633633
"changed": True
634634
}
635+
636+
637+
def configureIngressForPathBasedRouting(dynClient: DynamicClient, ingressControllerName: str = "default") -> bool:
638+
"""
639+
Configure OpenShift IngressController for path-based routing.
640+
641+
Sets the namespaceOwnership to InterNamespaceAllowed on the specified IngressController,
642+
which is required for path-based routing mode in MAS.
643+
644+
Args:
645+
dynClient: OpenShift Dynamic Client
646+
ingressControllerName (optional): Name of the IngressController to configure. Defaults to "default".
647+
648+
Returns:
649+
bool: True if configuration was successful or already configured, False otherwise
650+
651+
Raises:
652+
NotFoundError: If the IngressController resource cannot be found
653+
"""
654+
logger.info(f"Configuring IngressController '{ingressControllerName}' for path-based routing")
655+
656+
try:
657+
ingressControllerAPI = dynClient.resources.get(
658+
api_version="operator.openshift.io/v1",
659+
kind="IngressController"
660+
)
661+
662+
try:
663+
ingressController = ingressControllerAPI.get(
664+
name=ingressControllerName,
665+
namespace="openshift-ingress-operator"
666+
)
667+
except NotFoundError:
668+
logger.error(f"IngressController '{ingressControllerName}' not found in namespace 'openshift-ingress-operator'")
669+
return False
670+
671+
currentPolicy = None
672+
if hasattr(ingressController, 'spec') and hasattr(ingressController.spec, 'routeAdmission'):
673+
if hasattr(ingressController.spec.routeAdmission, 'namespaceOwnership'):
674+
currentPolicy = ingressController.spec.routeAdmission.namespaceOwnership
675+
676+
logger.debug(f"Current namespaceOwnership policy: {currentPolicy if currentPolicy else 'Not set'}")
677+
678+
if currentPolicy == "InterNamespaceAllowed":
679+
logger.info(f"IngressController '{ingressControllerName}' is already configured with namespaceOwnership: InterNamespaceAllowed")
680+
return True
681+
682+
logger.info(f"Patching IngressController '{ingressControllerName}' to enable InterNamespaceAllowed")
683+
684+
patch = {
685+
"spec": {
686+
"routeAdmission": {
687+
"namespaceOwnership": "InterNamespaceAllowed"
688+
}
689+
}
690+
}
691+
692+
ingressControllerAPI.patch(
693+
body=patch,
694+
name=ingressControllerName,
695+
namespace="openshift-ingress-operator",
696+
content_type="application/merge-patch+json"
697+
)
698+
699+
maxRetries = 5
700+
retryDelay = 5
701+
702+
for attempt in range(maxRetries):
703+
sleep(retryDelay)
704+
try:
705+
updatedController = ingressControllerAPI.get(
706+
name=ingressControllerName,
707+
namespace="openshift-ingress-operator"
708+
)
709+
710+
if (hasattr(updatedController, 'spec') and hasattr(updatedController.spec, 'routeAdmission') and hasattr(updatedController.spec.routeAdmission, 'namespaceOwnership') and updatedController.spec.routeAdmission.namespaceOwnership == "InterNamespaceAllowed"):
711+
712+
logger.info(f"Successfully configured IngressController '{ingressControllerName}' for path-based routing")
713+
return True
714+
715+
except NotFoundError:
716+
logger.warning(f"IngressController '{ingressControllerName}' not found during verification (attempt {attempt + 1}/{maxRetries})")
717+
718+
if attempt < maxRetries - 1:
719+
logger.debug(f"Waiting for IngressController to reconcile (attempt {attempt + 1}/{maxRetries})")
720+
721+
logger.error(f"Failed to verify IngressController configuration after {maxRetries} attempts")
722+
return False
723+
724+
except Exception as e:
725+
logger.error(f"Failed to configure IngressController '{ingressControllerName}': {str(e)}")
726+
return False

src/mas/devops/templates/pipelinerun-install.yml.j2

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,6 @@ spec:
539539
- name: mas_ingress_controller_name
540540
value: "{{ mas_ingress_controller_name }}"
541541
{%- endif %}
542-
{%- if mas_configure_ingress is defined and mas_configure_ingress != "" %}
543-
- name: mas_configure_ingress
544-
value: "{{ mas_configure_ingress }}"
545-
{%- endif %}
546542
{%- if mas_deployment_progression is defined and mas_deployment_progression != "" %}
547543
- name: mas_deployment_progression
548544
value: "{{ mas_deployment_progression }}"

0 commit comments

Comments
 (0)