|
11 | 11 |
|
12 | 12 | import logging |
13 | 13 | import logging.handlers |
| 14 | +from typing import Callable |
14 | 15 | from halo import Halo |
15 | 16 | from prompt_toolkit import print_formatted_text, HTML |
16 | 17 |
|
|
21 | 22 | from .argParser import updateArgParser |
22 | 23 |
|
23 | 24 | from mas.devops.ocp import createNamespace, getStorageClasses, getConsoleURL |
24 | | -from mas.devops.mas import listMasInstances, getCurrentCatalog |
| 25 | +from mas.devops.mas import listMasInstances, listAiServiceInstances, getCurrentCatalog |
25 | 26 | from mas.devops.tekton import preparePipelinesNamespace, installOpenShiftPipelines, updateTektonDefinitions, launchUpdatePipeline |
26 | 27 |
|
27 | 28 |
|
@@ -94,7 +95,10 @@ def update(self, argv): |
94 | 95 | # deprecated MaximoApplicationSuite ImageContentSourcePolicy instead of the new ImageDigestMirrorSet |
95 | 96 | self.isAirgap() |
96 | 97 | self.reviewCurrentCatalog() |
97 | | - self.reviewMASInstance() |
| 98 | + isMasInstalled = self.reviewMASInstance() |
| 99 | + isAiServiceInstalled = self.reviewAiServiceInstance() |
| 100 | + if not isMasInstalled and not isAiServiceInstalled: |
| 101 | + self.fatalError(["No MAS or AI Service instances were detected on the cluster => nothing to update! See log file for details"]) |
98 | 102 |
|
99 | 103 | if self.args.mas_catalog_version is None: |
100 | 104 | # Interactive mode |
@@ -228,15 +232,23 @@ def reviewCurrentCatalog(self) -> None: |
228 | 232 | f" <u>{catalogInfo['image']}</u>" |
229 | 233 | ]) |
230 | 234 |
|
231 | | - def reviewMASInstance(self) -> None: |
232 | | - self.printH1("Review MAS Instances") |
233 | | - self.printDescription(["The following MAS intances are installed on the target cluster and will be affected by the catalog update:"]) |
| 235 | + def reviewMASInstance(self) -> bool: |
| 236 | + return self.reviewInstances(listMasInstances, 'MAS', 'Suite.core.mas.ibm.com/v1') |
| 237 | + |
| 238 | + def reviewAiServiceInstance(self) -> bool: |
| 239 | + return self.reviewInstances(listAiServiceInstances, 'AI Service', 'AIServiceApp.aiservice.ibm.com/v1') |
| 240 | + |
| 241 | + def reviewInstances(self, getInstances: Callable, name: str, kind: str) -> bool: |
| 242 | + self.printH1(f"Review {name} Instances") |
234 | 243 | try: |
235 | | - suites = listMasInstances(self.dynamicClient) |
236 | | - for suite in suites: |
237 | | - self.printDescription([f"- <u>{suite['metadata']['name']}</u> v{suite['status']['versions']['reconciled']}"]) |
| 244 | + instances = getInstances(self.dynamicClient) |
| 245 | + self.printDescription([f"The following {name} instances are installed on the target cluster and will be affected by the catalog update:"]) |
| 246 | + for instance in instances: |
| 247 | + self.printDescription([f"- <u>{instance['metadata']['name']}</u> v{instance['status']['versions']['reconciled']}"]) |
| 248 | + return True |
238 | 249 | except ResourceNotFoundError: |
239 | | - self.fatalError("No MAS instances were detected on the cluster (Suite.core.mas.ibm.com/v1 API is not available). See log file for details") |
| 250 | + self.printDescription([f"No {name} instances were detected on the cluster ({kind} API is not available)"]) |
| 251 | + return False |
240 | 252 |
|
241 | 253 | def chooseCatalog(self) -> None: |
242 | 254 | self.printH1("Select IBM Maximo Operator Catalog Version") |
|
0 commit comments