Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mas/devops/mas.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def getMasChannel(dynClient: DynamicClient, instanceId: str) -> str:
"""
try:
masSubscription = getSubscription(dynClient, f"mas-{instanceId}-core", "ibm-mas")
return masSubscription.items[0]["spec"]["channel"]
return masSubscription.spec.channel
except NotFoundError:
return False
except UnauthorizedError:
Expand Down
25 changes: 10 additions & 15 deletions src/mas/devops/olm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,16 @@ def ensureOperatorGroupExists(dynClient: DynamicClient, env: Environment, namesp


def getSubscription(dynClient: DynamicClient, namespace: str, packageName: str):
try:
labelSelector = f"operators.coreos.com/{packageName}.{namespace}"
logger.debug(f"Get Subscription for {packageName} in {namespace}")
subscriptionsAPI = dynClient.resources.get(
api_version="operators.coreos.com/v1alpha1", kind="Subscription"
)
subscription = subscriptionsAPI.get(
label_selector=labelSelector, namespace=namespace
)
if subscription.items == 0:
raise NotFoundError
except NotFoundError:
labelSelector = f"operators.coreos.com/{packageName}.{namespace}"
logger.debug(f"Get Subscription for {packageName} in {namespace}")
subscriptionsAPI = dynClient.resources.get(api_version="operators.coreos.com/v1alpha1", kind="Subscription")
subscriptions = subscriptionsAPI.get(label_selector=labelSelector, namespace=namespace)
if len(subscriptions.items) == 0:
logger.info(f"No matching Subscription found for {packageName} in {namespace}")
subscription = None
return subscription
return None
elif len(subscriptions.items) > 0:
logger.warning(f"More than one ({len(subscriptions.items)}) Subscriptions found for {packageName} in {namespace}")
return subscriptions.items[0]


def applySubscription(dynClient: DynamicClient, namespace: str, packageName: str, packageChannel: str = None, catalogSource: str = None, catalogSourceNamespace: str = "openshift-marketplace", config: dict = None):
Expand Down Expand Up @@ -184,7 +179,7 @@ def deleteSubscription(dynClient: DynamicClient, namespace: str, packageName: st

def _findAndDeleteResources(api, resourceType: str, labelSelector: str, namespace: str):
resources = api.get(label_selector=labelSelector, namespace=namespace)
if resources.items == 0:
if len(resources.items) == 0:
logger.info(f"No matching {resourceType}s to delete")
else:
for item in resources.items:
Expand Down
14 changes: 14 additions & 0 deletions test/src/test_olm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,26 @@ def test_crud():
assert subscription.metadata.name == "ibm-sls"
assert subscription.metadata.namespace == namespace

subscriptionLookup1 = olm.getSubscription(dynClient, namespace, "ibm-sls")
subscriptionLookup2 = olm.getSubscription(dynClient, namespace, "ibm-truststore-mgr")

assert subscriptionLookup1.metadata.name == "ibm-sls"
assert subscriptionLookup1.metadata.namespace == namespace
assert subscriptionLookup1.spec.channel == "3.x"
assert subscriptionLookup2.metadata.namespace == namespace
assert subscriptionLookup2.spec.channel == "1.x-stable"

# When we install the ibm-sls subscription OLM will automatically create the ibm-truststore-mgr
# subscription, but when we delete the subscription, OLM will not automatically remove the latter
olm.deleteSubscription(dynClient, namespace, "ibm-sls")
olm.deleteSubscription(dynClient, namespace, "ibm-truststore-mgr")
ocp.deleteNamespace(dynClient, namespace)

failedSubscriptionLookup1 = olm.getSubscription(dynClient, namespace, "ibm-sls")
failedSubscriptionLookup2 = olm.getSubscription(dynClient, namespace, "ibm-truststore-mgr")
assert failedSubscriptionLookup1 is None
assert failedSubscriptionLookup2 is None


def test_crud_with_config():
namespace = "cli-fvt-2"
Expand Down
Loading