Skip to content

Commit 182660a

Browse files
Aneri11UAneri ThakkarDixit Sathwara
authored
[patch] Add helper functions for applying pre-install RBAC during update and upgrade (#364)
Co-authored-by: Aneri Thakkar <Aneri.Thakkar1@ibm.com> Co-authored-by: Dixit Sathwara <Dixit.Sathwara1@ibm.com>
1 parent 71bfbb3 commit 182660a

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎src/mas/devops/mas/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from .apps import ( # noqa: F401
22
verifyAppInstance,
33
getAppsSubscriptionChannel,
4-
waitForAppReady
4+
waitForAppReady,
5+
getInstalledApps
56
)
67

78
from .suite import ( # noqa: F401

‎src/mas/devops/mas/apps.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,38 @@ def getAppsSubscriptionChannel(dynClient: DynamicClient, instanceId: str) -> lis
216216
except UnauthorizedError:
217217
logger.error("Error: Unable to get MAS app subscriptions due to failed authorization: {e}")
218218
return []
219+
220+
221+
def getInstalledApps(dynClient: DynamicClient, instanceId: str) -> list:
222+
"""
223+
Get list of installed apps for the given MAS instance for RBAC application.
224+
Always includes 'core' since core RBAC is required.
225+
226+
This is a convenience wrapper around getAppsSubscriptionChannel() that:
227+
1. Always includes 'core' in the list
228+
2. Extracts just the appId from the subscription data
229+
3. Handles errors gracefully
230+
231+
Args:
232+
dynClient (DynamicClient): OpenShift dynamic client for cluster API interactions.
233+
instanceId (str): The MAS instance identifier.
234+
235+
Returns:
236+
list: List of app IDs including 'core' (e.g., ['core', 'manage', 'iot'])
237+
"""
238+
# Always include core for RBAC application
239+
installedApps = ["core"]
240+
241+
try:
242+
appsWithSubscriptions = getAppsSubscriptionChannel(dynClient, instanceId)
243+
logger.info(f"Apps with subscriptions detected for {instanceId}: {[app.get('appId') for app in appsWithSubscriptions]}")
244+
245+
for app in appsWithSubscriptions:
246+
appId = app.get("appId")
247+
if appId:
248+
installedApps.append(appId)
249+
except Exception as e:
250+
logger.warning(f"Could not query app subscriptions for {instanceId}: {e}")
251+
# Return at least core if we can't query apps
252+
253+
return installedApps

0 commit comments

Comments
 (0)