Skip to content

Commit e237048

Browse files
author
Sanjay Prabhakar
committed
[patch] patch pending PVC for tekton postgres
1 parent 1d21abc commit e237048

2 files changed

Lines changed: 67 additions & 2 deletions

File tree

src/mas/devops/ocp.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,55 @@ def waitForDeployment(dynClient: DynamicClient, namespace: str, deploymentName:
157157
sleep(5)
158158
return foundReadyDeployment
159159

160+
def waitForPVC(dynClient: DynamicClient, namespace: str, pvcName: str) -> bool:
161+
pvcAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolumeClaim")
162+
maxRetries = 60
163+
foundReadyPVC = False
164+
retries = 0
165+
while not foundReadyPVC and retries < maxRetries:
166+
retries += 1
167+
try:
168+
pvc = pvcAPI.get(name=pvcName, namespace=namespace)
169+
if pvc.status.phase == "Bound":
170+
foundReadyPVC = True
171+
else:
172+
logger.debug("Waiting 5s for PVC {pvcName} to be ready before checking again ...")
173+
sleep(5)
174+
except NotFoundError:
175+
logger.debug("Waiting 5s for PVC {pvcName} to be created before checking again ...")
176+
sleep(5)
177+
return foundReadyPVC
178+
179+
180+
def patchPendingPVC(dynClient: DynamicClient, namespace: str, pvcName: str, storageClassName: str) -> bool:
181+
pvcAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolumeClaim")
182+
try:
183+
pvc = pvcAPI.get(name=pvcName, namespace=namespace)
184+
if pvc.status.phase == "Pending" and pvc.spec.storageClassName is None:
185+
pvc.spec.storageClassName = storageClassName
186+
pvcAPI.patch(body=pvc, namespace=namespace)
187+
188+
maxRetries = 60
189+
foundReadyPVC = False
190+
retries = 0
191+
while not foundReadyPVC and retries < maxRetries:
192+
retries += 1
193+
try:
194+
patchedPVC = pvcAPI.get(name=pvcName, namespace=namespace)
195+
if patchedPVC.status.phase == "Bound":
196+
foundReadyPVC = True
197+
else:
198+
logger.debug("Waiting 5s for PVC {pvcName} to be bound before checking again ...")
199+
sleep(5)
200+
except NotFoundError:
201+
logger.error("The patched PVC {pvcName} does not exist.")
202+
return False
203+
204+
return foundReadyPVC
205+
206+
except NotFoundError:
207+
logger.error("PVC {pvcName} does not exist")
208+
return False
160209

161210
def getConsoleURL(dynClient: DynamicClient) -> str:
162211
routesAPI = dynClient.resources.get(api_version="route.openshift.io/v1", kind="Route")

src/mas/devops/tekton.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from jinja2 import Environment, FileSystemLoader
2424

25-
from .ocp import getConsoleURL, waitForCRD, waitForDeployment, crdExists
25+
from .ocp import getConsoleURL, waitForCRD, waitForDeployment, waitForPVC, patchPendingPVC, crdExists
2626

2727
logger = logging.getLogger(__name__)
2828

@@ -79,11 +79,27 @@ def installOpenShiftPipelines(dynClient: DynamicClient) -> bool:
7979
foundReadyWebhook = waitForDeployment(dynClient, namespace="openshift-pipelines", deploymentName="tekton-pipelines-webhook")
8080
if foundReadyWebhook:
8181
logger.info("OpenShift Pipelines Webhook is installed and ready")
82-
return True
8382
else:
8483
logger.error("OpenShift Pipelines Webhook is NOT installed and ready")
8584
return False
8685

86+
# Wait for the postgredb-tekton-results-postgres-0 PVC to be ready
87+
# this PVC doesn't come up when there's no default storage class is in the cluster,
88+
# this is causing the pvc to be in pending state and causing the tekton-results-postgres statefulSet in pending,
89+
# due to these resources not coming up, the MAS pre-install check in the pipeline times out checking the health of this statefulSet,
90+
# causing failure in pipeline.
91+
# Refer https://github.com/ibm-mas/cli/issues/1511
92+
logger.debug("Waiting for postgredb-tekton-results-postgres-0 PVC to be ready")
93+
foundReadyPVC = waitForPVC(dynClient, namespace="openshift-pipelines", pvcName="postgredb-tekton-results-postgres-0")
94+
if foundReadyPVC:
95+
logger.info("OpenShift Pipelines postgres is installed and ready")
96+
else:
97+
patchedPVC = patchPVC(dynClient, namespace="openshift-pipelines", pvcName="postgredb-tekton-results-postgres-0")
98+
if patchPVC:
99+
logger.info("OpenShift Pipelines postgres is installed and ready")
100+
else:
101+
logger.error("OpenShift Pipelines postgres PVC is NOT ready")
102+
87103

88104
def updateTektonDefinitions(namespace: str, yamlFile: str) -> None:
89105
"""

0 commit comments

Comments
 (0)