Skip to content

Commit bbe69e9

Browse files
author
Bhautik Vala
committed
[patch] Initial changes for supporting mas upgrade for AI Service
1 parent 248e5e8 commit bbe69e9

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/mas/devops/mas.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ def verifyMasInstance(dynClient: DynamicClient, instanceId: str) -> bool:
178178
logger.error(f"Error: Unable to verify MAS instance due to failed authorization: {e}")
179179
return False
180180

181+
def verifyAiServiceInstance(dynClient: DynamicClient, instanceId: str) -> bool:
182+
"""
183+
Validate that the chosen AI Service instance exists
184+
"""
185+
try:
186+
aiserviceAPI = dynClient.resources.get(api_version="aiservice.ibm.com/v1", kind="AIServiceApp")
187+
aiserviceAPI.get(name=instanceId, namespace=f"aiservice-{instanceId}")
188+
return True
189+
except NotFoundError:
190+
print("NOT FOUND")
191+
return False
192+
except ResourceNotFoundError:
193+
# The AIServiceApp CRD has not even been installed in the cluster
194+
print("RESOURCE NOT FOUND")
195+
return False
196+
except UnauthorizedError as e:
197+
logger.error(f"Error: Unable to verify AI Service instance due to failed authorization: {e}")
198+
return False
181199

182200
def verifyAppInstance(dynClient: DynamicClient, instanceId: str, applicationId: str) -> bool:
183201
"""
@@ -224,6 +242,15 @@ def getMasChannel(dynClient: DynamicClient, instanceId: str) -> str:
224242
else:
225243
return masSubscription.spec.channel
226244

245+
def getAiserviceChannel(dynClient: DynamicClient, instanceId: str) -> str:
246+
"""
247+
Get the AI Service channel from the subscription
248+
"""
249+
aiserviceSubscription = getSubscription(dynClient, f"aiservice-{instanceId}", "ibm-aiservice")
250+
if aiserviceSubscription is None:
251+
return None
252+
else:
253+
return aiserviceSubscription.spec.channel
227254

228255
def updateIBMEntitlementKey(dynClient: DynamicClient, namespace: str, icrUsername: str, icrPassword: str, artifactoryUsername: str = None, artifactoryPassword: str = None, secretName: str = "ibm-entitlement") -> ResourceInstance:
229256
if secretName is None:

0 commit comments

Comments
 (0)