Skip to content

Commit e646c0f

Browse files
authored
Merge branch 'stable' into ibai
2 parents d2b3fd4 + 7a30cf7 commit e646c0f

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @durera @sanjayprab @terenceq @whitfiea @ianBoden @rawa-resul @leo-miran @terc1997
1+
* @ibm-mas/pr-review-team

src/mas/devops/mas.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,29 @@ def listMasInstances(dynClient: DynamicClient) -> list:
123123
"""
124124
Get a list of MAS instances on the cluster
125125
"""
126-
suitesAPI = dynClient.resources.get(api_version="core.mas.ibm.com/v1", kind="Suite")
126+
return listInstances(dynClient, "core.mas.ibm.com/v1", "Suite")
127127

128-
suites = suitesAPI.get().to_dict()['items']
129-
if len(suites) > 0:
130-
logger.info(f"There are {len(suites)} MAS instances installed on this cluster:")
131-
for suite in suites:
132-
logger.info(f" * {suite['metadata']['name']} v{suite['status']['versions']['reconciled']}")
128+
129+
def listAiServiceInstances(dynClient: DynamicClient) -> list:
130+
"""
131+
Get a list of AI Service instances on the cluster
132+
"""
133+
return listInstances(dynClient, "aiservice.ibm.com/v1", "AIServiceApp")
134+
135+
136+
def listInstances(dynClient: DynamicClient, apiVersion: str, kind: str) -> list:
137+
"""
138+
Get a list of instances of a particular CR on the cluster
139+
"""
140+
api = dynClient.resources.get(api_version=apiVersion, kind=kind)
141+
instances = api.get().to_dict()['items']
142+
if len(instances) > 0:
143+
logger.info(f"There are {len(instances)} {kind} instances installed on this cluster:")
144+
for instance in instances:
145+
logger.info(f" * {instance['metadata']['name']} v{instance['status']['versions']['reconciled']}")
133146
else:
134-
logger.info("There are no MAS instances installed on this cluster")
135-
return suites
147+
logger.info(f"There are no {kind} instances installed on this cluster")
148+
return instances
136149

137150

138151
def getWorkspaceId(dynClient: DynamicClient, instanceId: str) -> str:

src/mas/devops/ocp.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,23 @@ def getNamespace(dynClient: DynamicClient, namespace: str) -> dict:
9494
return {}
9595

9696

97-
def createNamespace(dynClient: DynamicClient, namespace: str) -> bool:
97+
def createNamespace(dynClient: DynamicClient, namespace: str, kyvernoLabel: str = None) -> bool:
9898
"""
9999
Create a namespace if it does not exist
100100
"""
101101
namespaceAPI = dynClient.resources.get(api_version="v1", kind="Namespace")
102102
try:
103-
namespaceAPI.get(name=namespace)
104-
logger.debug(f"Namespace {namespace} already exists")
103+
ns = namespaceAPI.get(name=namespace)
104+
logger.info(f"Namespace {namespace} already exists")
105+
if kyvernoLabel is not None:
106+
if ns.metadata.labels is None or "ibm.com/kyverno" not in ns.metadata.labels.keys() or ns.metadata.labels["ibm.com/kyverno"] != kyvernoLabel:
107+
logger.info(f"Patching namespace with Kyverno Labels ibm.com/kyverno: {kyvernoLabel}")
108+
body = {"metadata": {"labels": {"ibm.com/kyverno": kyvernoLabel}}}
109+
namespaceAPI.patch(
110+
name=namespace,
111+
body=body,
112+
content_type="application/merge-patch+json"
113+
)
105114
except NotFoundError:
106115
nsObj = {
107116
"apiVersion": "v1",
@@ -110,6 +119,10 @@ def createNamespace(dynClient: DynamicClient, namespace: str) -> bool:
110119
"name": namespace
111120
}
112121
}
122+
if kyvernoLabel is not None:
123+
nsObj["metadata"]["labels"] = {
124+
"ibm.com/kyverno": kyvernoLabel
125+
}
113126
namespaceAPI.create(body=nsObj)
114127
logger.debug(f"Created namespace {namespace}")
115128
return True

0 commit comments

Comments
 (0)