@@ -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
0 commit comments