@@ -170,8 +170,47 @@ def preparePipelinesNamespace(dynClient: DynamicClient, instanceId: str = None,
170170 sleep (15 )
171171
172172
173- def prepareInstallSecrets (dynClient : DynamicClient , instanceId : str , slsLicenseFile : str = None , additionalConfigs : dict = None , certs : str = None , podTemplates : str = None ) -> None :
174- namespace = f"mas-{ instanceId } -pipelines"
173+ def prepareAiServicePipelinesNamespace (dynClient : DynamicClient , instanceId : str = None , storageClass : str = None , accessMode : str = None , waitForBind : bool = True , configureRBAC : bool = True ):
174+ templateDir = path .join (path .abspath (path .dirname (__file__ )), "templates" )
175+ env = Environment (
176+ loader = FileSystemLoader (searchpath = templateDir )
177+ )
178+ namespace = f"aiservice-{ instanceId } -pipelines"
179+ template = env .get_template ("pipelines-rbac.yml.j2" )
180+
181+ if configureRBAC :
182+ # Create RBAC
183+ renderedTemplate = template .render (mas_instance_id = instanceId )
184+ logger .debug (renderedTemplate )
185+ crb = yaml .safe_load (renderedTemplate )
186+ clusterRoleBindingAPI = dynClient .resources .get (api_version = "rbac.authorization.k8s.io/v1" , kind = "ClusterRoleBinding" )
187+ clusterRoleBindingAPI .apply (body = crb , namespace = namespace )
188+
189+ template = env .get_template ("aiservice-pipelines-pvc.yml.j2" )
190+ renderedTemplate = template .render (
191+ aiservice_instance_id = instanceId ,
192+ pipeline_storage_class = storageClass ,
193+ pipeline_storage_accessmode = accessMode
194+ )
195+ logger .debug (renderedTemplate )
196+ pvc = yaml .safe_load (renderedTemplate )
197+ pvcAPI = dynClient .resources .get (api_version = "v1" , kind = "PersistentVolumeClaim" )
198+ pvcAPI .apply (body = pvc , namespace = namespace )
199+
200+ if waitForBind :
201+ logger .debug ("Waiting for PVC to be bound" )
202+ pvcIsBound = False
203+ while not pvcIsBound :
204+ configPVC = pvcAPI .get (name = "config-pvc" , namespace = namespace )
205+ if configPVC .status .phase == "Bound" :
206+ pvcIsBound = True
207+ else :
208+ logger .debug ("Waiting 15s before checking status of PVC again" )
209+ logger .debug (configPVC )
210+ sleep (15 )
211+
212+
213+ def prepareInstallSecrets (dynClient : DynamicClient , namespace : str , slsLicenseFile : str = None , additionalConfigs : dict = None , certs : str = None , podTemplates : str = None ) -> None :
175214 secretsAPI = dynClient .resources .get (api_version = "v1" , kind = "Secret" )
176215
177216 # 1. Secret/pipeline-additional-configs
@@ -402,24 +441,24 @@ def launchInstallPipeline(dynClient: DynamicClient, params: dict) -> str:
402441 return pipelineURL
403442
404443
405- def launchInstallPipelineForAiservice (dynClient : DynamicClient , params : dict ) -> str :
444+ def launchUpdatePipeline (dynClient : DynamicClient , params : dict ) -> str :
406445 """
407- Create a PipelineRun to install the Aiservice
446+ Create a PipelineRun to update the Maximo Operator Catalog
408447 """
409- instanceId = params ["aiservice_instance_id" ]
410- namespace = f"aiservice-{ instanceId } -pipelines"
411- timestamp = launchPipelineRun (dynClient , namespace , "pipelinerun-aiservice-install" , params )
448+ namespace = "mas-pipelines"
449+ timestamp = launchPipelineRun (dynClient , namespace , "pipelinerun-update" , params )
412450
413- pipelineURL = f"{ getConsoleURL (dynClient )} /k8s/ns/aiservice- { instanceId } - pipelines/tekton.dev~v1beta1~PipelineRun/{ instanceId } -install -{ timestamp } "
451+ pipelineURL = f"{ getConsoleURL (dynClient )} /k8s/ns/mas- pipelines/tekton.dev~v1beta1~PipelineRun/mas-update -{ timestamp } "
414452 return pipelineURL
415453
416454
417- def launchUpdatePipeline (dynClient : DynamicClient , params : dict ) -> str :
455+ def launchAiServiceInstallPipeline (dynClient : DynamicClient , params : dict ) -> str :
418456 """
419- Create a PipelineRun to update the Maximo Operator Catalog
457+ Create a PipelineRun to install the AI Service
420458 """
421- namespace = "mas-pipelines"
422- timestamp = launchPipelineRun (dynClient , namespace , "pipelinerun-update" , params )
459+ instanceId = params ["aiservice_instance_id" ]
460+ namespace = f"aiservice-{ instanceId } -pipelines"
461+ timestamp = launchPipelineRun (dynClient , namespace , "pipelinerun-aiservice-install" , params )
423462
424- pipelineURL = f"{ getConsoleURL (dynClient )} /k8s/ns/mas- pipelines/tekton.dev~v1beta1~PipelineRun/mas-update -{ timestamp } "
463+ pipelineURL = f"{ getConsoleURL (dynClient )} /k8s/ns/aiservice- { instanceId } - pipelines/tekton.dev~v1beta1~PipelineRun/{ instanceId } -install -{ timestamp } "
425464 return pipelineURL
0 commit comments