Skip to content

Commit 6533d69

Browse files
committed
[patch] Fix bug in listSLSInstances
1 parent 003a078 commit 6533d69

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

setup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ def get_version(rel_path):
5555
description='Python for Maximo Application Suite Dev/Ops',
5656
long_description=long_description,
5757
install_requires=[
58-
'pyyaml', # MIT License
59-
'openshift', # Apache Software License
60-
'kubernetes', # Apache Software License
61-
'kubeconfig', # BSD License
62-
'jinja2', # BSD License
63-
'jinja2-base64-filters' # MIT License
58+
'pyyaml', # MIT License
59+
'openshift', # Apache Software License
60+
'kubernetes', # Apache Software License
61+
'kubeconfig', # BSD License
62+
'jinja2', # BSD License
63+
'jinja2-base64-filters', # MIT License
64+
# 'requests' # Apache Software License
6465
],
6566
extras_require={
6667
'dev': [

src/mas/devops/sls.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
2+
# import requests
23
from openshift.dynamic import DynamicClient
4+
from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError, UnauthorizedError
35

46
logger = logging.getLogger(__name__)
57

@@ -8,19 +10,24 @@ def listSLSInstances(dynClient: DynamicClient) -> list:
810
"""
911
Get a list of SLS instances on the cluster
1012
"""
11-
slsAPI = dynClient.resources.get(api_version="sls.ibm.com/v1", kind="LicenseService")
12-
13-
licenseservices = slsAPI.get().to_dict()['items']
13+
try:
14+
slsAPI = dynClient.resources.get(api_version="sls.ibm.com/v1", kind="LicenseService")
15+
return slsAPI.get().to_dict()['items']
16+
except NotFoundError:
17+
logger.info("There are no SLS instances installed on this cluster")
18+
return []
19+
except ResourceNotFoundError:
20+
# The LicenseService CRD has not even been installed in the cluster
21+
return []
22+
except UnauthorizedError:
23+
logger.error("Error: Unable to verify SLS instance(s) due to failed authorization: {e}")
24+
return []
1425

15-
numSLS = len(licenseservices)
1626

17-
if numSLS == 1:
18-
logger.info("There is 1 SLS instance installed on this cluster:")
19-
logger.info(f" * {licenseservices[0]['metadata']['name']} ({{licenseservices[0]['metadata']['namespace']}}) v{licenseservices[0]['status']['versions']['reconciled']}")
20-
elif numSLS > 0:
21-
logger.info(f"There are {numSLS} SLS instances installed on this cluster:")
22-
for licenseservice in licenseservices:
23-
logger.info(f" * {licenseservice['metadata']['name']} ({{licenseservice['metadata']['namespace']}}) v{licenseservice['status']['versions']['reconciled']}")
24-
else:
25-
logger.info("There are no SLS instances installed on this cluster")
26-
return licenseservices
27+
# def verifySLSConnection(sls_url: str, server_ca: str) -> bool:
28+
# logger.info("Checking SLS connection")
29+
# response = requests.get(f"{sls_url}api/probes/readiness", verify=server_ca)
30+
# if response.status_code == 200:
31+
# return True
32+
# return False
33+
# # response.raise_for_status()

0 commit comments

Comments
 (0)