|
20 | 20 | from kubernetes.stream import stream |
21 | 21 | from kubernetes.stream.ws_client import ERROR_CHANNEL |
22 | 22 |
|
23 | | -from .mas import getDefaultStorageClasses |
24 | | - |
25 | 23 | import yaml |
26 | 24 |
|
27 | 25 | logger = logging.getLogger(__name__) |
@@ -200,65 +198,6 @@ def crdExists(dynClient: DynamicClient, crdName: str) -> bool: |
200 | 198 | logger.debug(f"CRD does not exist: {crdName}") |
201 | 199 | return False |
202 | 200 |
|
203 | | -def waitForPVC(dynClient: DynamicClient, namespace: str, pvcName: str) -> bool: |
204 | | - pvcAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolumeClaim") |
205 | | - maxRetries = 60 |
206 | | - foundReadyPVC = False |
207 | | - retries = 0 |
208 | | - while not foundReadyPVC and retries < maxRetries: |
209 | | - retries += 1 |
210 | | - try: |
211 | | - pvc = pvcAPI.get(name=pvcName, namespace=namespace) |
212 | | - if pvc.status.phase == "Bound": |
213 | | - foundReadyPVC = True |
214 | | - else: |
215 | | - logger.debug("Waiting 5s for PVC {pvcName} to be ready before checking again ...") |
216 | | - sleep(5) |
217 | | - except NotFoundError: |
218 | | - logger.debug("Waiting 5s for PVC {pvcName} to be created before checking again ...") |
219 | | - sleep(5) |
220 | | - return foundReadyPVC |
221 | | - |
222 | | - |
223 | | -def patchPendingPVC(dynClient: DynamicClient, namespace: str, pvcName: str, storageClassName: str = None) -> bool: |
224 | | - pvcAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolumeClaim") |
225 | | - try: |
226 | | - pvc = pvcAPI.get(name=pvcName, namespace=namespace) |
227 | | - if pvc.status.phase == "Pending" and pvc.spec.storageClassName is None: |
228 | | - if storageClassName is not None and storageClassName(dynClient, name=storageClassName) is not None: |
229 | | - pvc.spec.storageClassName = storageClassName |
230 | | - else: |
231 | | - defaultStorageClasses = getDefaultStorageClasses(dynClient) |
232 | | - if defaultStorageClasses.provider is not None: |
233 | | - pvc.spec.storageClassName = defaultStorageClasses.rwo |
234 | | - else: |
235 | | - logger.error("Unable to set storageClassName in PVC {pvcName}.") |
236 | | - return False |
237 | | - |
238 | | - pvcAPI.patch(body=pvc, namespace=namespace) |
239 | | - |
240 | | - maxRetries = 60 |
241 | | - foundReadyPVC = False |
242 | | - retries = 0 |
243 | | - while not foundReadyPVC and retries < maxRetries: |
244 | | - retries += 1 |
245 | | - try: |
246 | | - patchedPVC = pvcAPI.get(name=pvcName, namespace=namespace) |
247 | | - if patchedPVC.status.phase == "Bound": |
248 | | - foundReadyPVC = True |
249 | | - else: |
250 | | - logger.debug("Waiting 5s for PVC {pvcName} to be bound before checking again ...") |
251 | | - sleep(5) |
252 | | - except NotFoundError: |
253 | | - logger.error("The patched PVC {pvcName} does not exist.") |
254 | | - return False |
255 | | - |
256 | | - return foundReadyPVC |
257 | | - |
258 | | - except NotFoundError: |
259 | | - logger.error("PVC {pvcName} does not exist") |
260 | | - return False |
261 | | - |
262 | 201 |
|
263 | 202 | # Assisted by WCA@IBM |
264 | 203 | # Latest GenAI contribution: ibm/granite-8b-code-instruct |
|
0 commit comments