Skip to content

Commit

Permalink
Get current ODF CSV for ROKS cluster from Install Plan
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Balogh <[email protected]>
  • Loading branch information
petr-balogh committed Dec 19, 2024
1 parent ca97ca8 commit 6be7dd4
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ocs_ci/ocs/resources/packagemanifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ def get_current_csv(self, channel=None, csv_pattern=constants.OCS_CSV_PREFIX):
self.check_name_is_specified()
channel = channel if channel else self.get_default_channel()
channels = self.get_channels()
if self.subscription_plan_approval == "Manual":
managed_ibmcloud = (
config.ENV_DATA["platform"] == constants.IBMCLOUD_PLATFORM
and config.ENV_DATA["deployment_type"] == "managed"
)
if self.subscription_plan_approval == "Manual" or managed_ibmcloud:
try:
return self.get_installed_csv_from_install_plans(
pattern=csv_pattern,
approved_only=managed_ibmcloud,
)
except NoInstallPlanForApproveFoundException:
log.debug(
Expand All @@ -188,12 +193,13 @@ def get_current_csv(self, channel=None, csv_pattern=constants.OCS_CSV_PREFIX):
f"Channel: {channel} not found in available channels: " f"{channel_names}"
)

def get_installed_csv_from_install_plans(self, pattern):
def get_installed_csv_from_install_plans(self, pattern, approved_only=False):
"""
Get currently installed CSV out latest approved install plans.
Args:
patter (str): pattern of CSV name to look for.
approved_only (bool): it will ignore if there is no non approved install plan
Raises:
CSVNotFound: In case no CSV found from approved install plans.
Expand All @@ -203,13 +209,14 @@ def get_installed_csv_from_install_plans(self, pattern):
"""
install_plan = InstallPlan(namespace=self.install_plan_namespace)
install_plans = install_plan.get()["items"]
not_approved_install_plans = [
ip for ip in install_plans if not ip["spec"]["approved"]
]
if not not_approved_install_plans:
raise NoInstallPlanForApproveFoundException(
"No insall plan for approve found!"
)
if not approved_only:
not_approved_install_plans = [
ip for ip in install_plans if not ip["spec"]["approved"]
]
if not not_approved_install_plans:
raise NoInstallPlanForApproveFoundException(
"No insall plan for approve found!"
)
sorted_install_plans = sorted(
install_plans,
key=lambda ip: ip["metadata"]["creationTimestamp"],
Expand Down

0 comments on commit 6be7dd4

Please sign in to comment.