From cd319e8dfa4ee0d3db48dab0762cd8ba1f04515a Mon Sep 17 00:00:00 2001 From: Kobi Hakimi Date: Thu, 2 Jan 2025 00:41:54 +0200 Subject: [PATCH] fix the uninstall of rhoai operator Signed-off-by: Kobi Hakimi --- .../pre-tasks/oc_is_operator_installed.robot | 56 +++++++++++++------ .../RHODS_OLM/uninstall/oc_uninstall.robot | 10 ---- ods_ci/tasks/Tasks/rhods_olm.robot | 3 + ods_ci/tests/Resources/RHOSi.resource | 1 + 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/ods_ci/tasks/Resources/RHODS_OLM/pre-tasks/oc_is_operator_installed.robot b/ods_ci/tasks/Resources/RHODS_OLM/pre-tasks/oc_is_operator_installed.robot index 4e70752c5..c99fbe3bc 100644 --- a/ods_ci/tasks/Resources/RHODS_OLM/pre-tasks/oc_is_operator_installed.robot +++ b/ods_ci/tasks/Resources/RHODS_OLM/pre-tasks/oc_is_operator_installed.robot @@ -5,8 +5,7 @@ Is RHODS Installed IF "${INSTALL_TYPE}" == "Cli" ${result}= Run Keyword And Return Status ... Run Keywords - ... Check A RHODS Family Operator Is Installed namespace=${OPERATOR_NAMESPACE} - ... subscription=rhoai-operator-dev AND + ... Check A RHODS Family Operator Is Installed AND ... Oc Get kind=Namespace field_selector=metadata.name=${MONITORING_NAMESPACE} AND ... Oc Get kind=Namespace field_selector=metadata.name=${APPLICATIONS_NAMESPACE} AND ... Oc Get kind=Namespace field_selector=metadata.name=${OPERATOR_NAMESPACE} AND @@ -15,8 +14,7 @@ Is RHODS Installed ELSE IF "${INSTALL_TYPE}" == "OperatorHub" ${result}= Run Keyword And Return Status ... Run Keywords - ... Check A RHODS Family Operator Is Installed namespace=${OPERATOR_NAMESPACE} - ... subscription=${OPERATOR_NAME} AND + ... Check A RHODS Family Operator Is Installed AND ... Oc Get kind=Namespace field_selector=metadata.name=${MONITORING_NAMESPACE} AND ... Oc Get kind=Namespace field_selector=metadata.name=${APPLICATIONS_NAMESPACE} AND ... Oc Get kind=Namespace field_selector=metadata.name=${OPERATOR_NAMESPACE} @@ -34,8 +32,7 @@ Is RHODS Installed END ${result}= Run Keyword And Return Status ... Run Keywords - ... Check A RHODS Family Operator Is Installed namespace=${OPERATOR_NAMESPACE} - ... subscription=${SUB_NAME} AND + ... Check A RHODS Family Operator Is Installed AND ... Oc Get kind=Namespace field_selector=metadata.name=${MONITORING_NAMESPACE} AND ... Oc Get kind=Namespace field_selector=metadata.name=${APPLICATIONS_NAMESPACE} AND ... Oc Get kind=Namespace field_selector=metadata.name=${OPERATOR_NAMESPACE} AND @@ -49,17 +46,40 @@ Is RHODS Installed RETURN ${result} Check A RHODS Family Operator Is Installed - [Documentation] Returns if an operator with given subscription name has a CSV in the given namespace - [Arguments] ${namespace} ${subscription} - Log Getting CSV from subscription ${subscription} namespace ${namespace} console=yes - ${rc} ${current_csv_name} = Run And Return Rc And Output - ... oc get subscription ${subscription} -n ${namespace} -ojson | jq '.status.currentCSV' | tr -d '"' - Log Got CSV ${current_csv_name} from subscription ${subscription}, result: ${rc} console=yes - IF "${rc}" == "0" and "${current_csv_name}" != "${EMPTY}" - ${result} = Run Keyword And Return Status - ... Oc Get kind=ClusterServiceVersion namespace=${namespace} name=${current_csv_name} - ELSE - ${result} = Set Variable False + [Documentation] Returns if RHODS operator has a CSV + + ${result} = Set Variable False + Log Check if the RHODS operator installed. console=yes + ${subscription}= Get RHODS Subscription Name + ${namespace}= Get RHODS Namespace + IF "${subscription}" != "${EMPTY}" + Log Getting CSV from subscription ${subscription} namespace ${namespace} console=yes + ${rc} ${current_csv_name} = Run And Return Rc And Output + ... oc get subscription ${subscription} -n ${namespace} -ojson | jq '.status.currentCSV' | tr -d '"' + Log Got CSV '${current_csv_name}' from subscription '${subscription}', result: ${rc} console=yes + IF "${rc}" == "0" and "${current_csv_name}" != "${EMPTY}" + ${rc}= Run Keyword And Return Status oc get csv ${current_csv_name} -n ${namespace} + ${result}= Evaluate ${rc} == 0 + Log The csv exists: ${result} console=yes + END END - Log Operator with sub ${subscription} is installed result: ${result} console=yes + Log Operator with sub '${subscription}' is installed result: ${result} console=yes IF not ${result} FAIL The operator with sub ${subscription} is not installed. + +Get RHODS Subscription Name + [Documentation] Returns the subscription name of RHOAI/ODH operator + Log Get the RHODS subscription name by package name: '${RHODS_PACKAGE_NAME}' console=yes + ${rc} ${out}= Run And Return RC And Output + ... oc get sub -A -o json | jq --arg pkgName "${RHODS_PACKAGE_NAME}" -r '.items[] | select(.spec.name==$pkgName) | .metadata.name' + Should Be Equal As Integers ${rc} 0 + Log The RHODS Subscription Name is: '${out}' console=yes + RETURN ${out} + +Get RHODS Namespace + [Documentation] Returns the namespace of RHOAI/ODH operator + Log Get the RHODS namespace by package name: '${RHODS_PACKAGE_NAME}' console=yes + ${rc} ${out}= Run And Return RC And Output + ... oc get sub -A -o json | jq --arg pkgName "${RHODS_PACKAGE_NAME}" -r '.items[] | select(.spec.name==$pkgName) | .metadata.namespace' + Should Be Equal As Integers ${rc} 0 + Log The RHODS Namespace is: '${out}' console=yes + RETURN ${out} diff --git a/ods_ci/tasks/Resources/RHODS_OLM/uninstall/oc_uninstall.robot b/ods_ci/tasks/Resources/RHODS_OLM/uninstall/oc_uninstall.robot index 6404dcbb7..8d8b55e3e 100644 --- a/ods_ci/tasks/Resources/RHODS_OLM/uninstall/oc_uninstall.robot +++ b/ods_ci/tasks/Resources/RHODS_OLM/uninstall/oc_uninstall.robot @@ -11,22 +11,12 @@ Trigger RHODS Uninstall Log Triggered RHODS uninstallation Verify RHODS Uninstallation - IF "${cluster_type}" == "managed" - Run Keyword And Expect Error *Not Found* - ... Oc Get kind=CatalogSource namespace=${OPERATOR_NAMESPACE} - ... field_selector=metadata.name=${CATALOG_NAME} - ELSE IF "${cluster_type}" == "selfmanaged" - Run Keyword And Expect Error *Not Found* - ... Oc Get kind=CatalogSource namespace=openshift-marketplace - ... field_selector=metadata.name=rhoai-catalog-dev - END Verify Project Does Not Exists ${MONITORING_NAMESPACE} Verify Project Does Not Exists ${APPLICATIONS_NAMESPACE} IF "${OPERATOR_NAMESPACE}" != "openshift-marketplace" Verify Project Does Not Exists ${OPERATOR_NAMESPACE} END - Verify Project Does Not Exists [Arguments] ${project} Log ${project} diff --git a/ods_ci/tasks/Tasks/rhods_olm.robot b/ods_ci/tasks/Tasks/rhods_olm.robot index 82d47e4da..34db2e362 100644 --- a/ods_ci/tasks/Tasks/rhods_olm.robot +++ b/ods_ci/tasks/Tasks/rhods_olm.robot @@ -3,6 +3,7 @@ Documentation Perform and verify RHODS OLM tasks Metadata RHODS OLM Version 1.0.0 Resource ../Resources/RHODS_OLM/RHODS_OLM.resource Resource ../../tests/Resources/Common.robot +Resource ../../tests/Resources/RHOSi.resource Library OpenShiftLibrary Library OperatingSystem Library String @@ -22,6 +23,7 @@ ${CATALOG_SOURCE} redhat-operators *** Tasks *** Can Install RHODS Operator [Tags] install + RHOSi Setup IF "${PRODUCT}" == "ODH" Set Global Variable ${OPERATOR_NAMESPACE} opendatahub-operators Set Global Variable ${OPERATOR_NAME_LABEL} opendatahub-operator @@ -43,6 +45,7 @@ Can Install RHODS Operator Can Uninstall RHODS Operator [Tags] uninstall + RHOSi Setup IF "${PRODUCT}" == "ODH" Set Global Variable ${OPERATOR_NAMESPACE} opendatahub-operators IF "${UPDATE_CHANNEL}" == "odh-nightlies" diff --git a/ods_ci/tests/Resources/RHOSi.resource b/ods_ci/tests/Resources/RHOSi.resource index fd36e19a6..4a05437e3 100644 --- a/ods_ci/tests/Resources/RHOSi.resource +++ b/ods_ci/tests/Resources/RHOSi.resource @@ -84,6 +84,7 @@ Initialize Global Variables Set Global Variable ${RHODS_VERSION} Set Prometheus Variables Set Global Variable ${DASHBOARD_APP_NAME} ${PRODUCT.lower()}-dashboard + Set Global Variable ${RHODS_PACKAGE_NAME} rhods-operator Required Global Variables Should Exist [Documentation] Fails if new required global variables are not set