@@ -105,24 +105,58 @@ def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName:
105105 # due to these resources not coming up, the MAS pre-install check in the pipeline times out checking the health of this statefulSet,
106106 # causing failure in pipeline.
107107 # Refer https://github.com/ibm-mas/cli/issues/1511
108- logger .debug ("Waiting for postgredb-tekton-results-postgres-0 PVC to be ready" )
109- foundReadyPVC = waitForPVC (dynClient , namespace = "openshift-pipelines" , pvcName = "postgredb-tekton-results-postgres-0" )
110- if foundReadyPVC :
111- logger .info ("OpenShift Pipelines postgres is installed and ready" )
108+ logger .debug ("Checking postgredb-tekton-results-postgres-0 PVC status" )
109+
110+ pvcAPI = dynClient .resources .get (api_version = "v1" , kind = "PersistentVolumeClaim" )
111+ pvcName = "postgredb-tekton-results-postgres-0"
112+ pvcNamespace = "openshift-pipelines"
113+
114+ # Wait briefly for PVC to be created (max 30 seconds)
115+ maxInitialRetries = 6
116+ pvc = None
117+ for retry in range (maxInitialRetries ):
118+ try :
119+ pvc = pvcAPI .get (name = pvcName , namespace = pvcNamespace )
120+ break
121+ except NotFoundError :
122+ if retry < maxInitialRetries - 1 :
123+ logger .debug (f"Waiting 5s for PVC { pvcName } to be created (attempt { retry + 1 } /{ maxInitialRetries } )..." )
124+ sleep (5 )
125+
126+ if pvc is None :
127+ logger .error (f"PVC { pvcName } was not created after { maxInitialRetries * 5 } seconds" )
128+ return False
129+
130+ # Check if PVC is already bound
131+ if pvc .status .phase == "Bound" :
132+ logger .info ("OpenShift Pipelines postgres PVC is already bound and ready" )
112133 return True
113- else :
134+
135+ # Check if PVC is pending without a storage class - needs immediate patching
136+ if pvc .status .phase == "Pending" and pvc .spec .storageClassName is None :
137+ logger .info ("PVC is pending without storage class, attempting to patch immediately..." )
114138 tektonPVCisReady = addMissingStorageClassToTektonPVC (
115139 dynClient = dynClient ,
116- namespace = "openshift-pipelines" ,
117- pvcName = "postgredb-tekton-results-postgres-0" ,
140+ namespace = pvcNamespace ,
141+ pvcName = pvcName ,
118142 storageClassName = customStorageClassName
119143 )
120144 if tektonPVCisReady :
121145 logger .info ("OpenShift Pipelines postgres is installed and ready" )
122146 return True
123147 else :
124- logger .error ("OpenShift Pipelines postgres PVC is NOT ready" )
148+ logger .error ("OpenShift Pipelines postgres PVC is NOT ready after patching " )
125149 return False
150+
151+ # PVC exists with storage class but not bound yet - wait for it to bind
152+ logger .debug (f"PVC has storage class '{ pvc .spec .storageClassName } ', waiting for it to be bound..." )
153+ foundReadyPVC = waitForPVC (dynClient , namespace = pvcNamespace , pvcName = pvcName )
154+ if foundReadyPVC :
155+ logger .info ("OpenShift Pipelines postgres is installed and ready" )
156+ return True
157+ else :
158+ logger .error ("OpenShift Pipelines postgres PVC is NOT ready" )
159+ return False
126160
127161
128162def addMissingStorageClassToTektonPVC (dynClient : DynamicClient , namespace : str , pvcName : str , storageClassName : str = None ) -> bool :
0 commit comments