From 7cbcc8124ce74cadcf8b8733341d5f390f64f8a3 Mon Sep 17 00:00:00 2001 From: yuvraj-vansure <81155309+yuvraj-vansure@users.noreply.github.com> Date: Tue, 9 Apr 2024 01:22:41 +0530 Subject: [PATCH] [patch] UDS/DRO migration storage class fix (#849) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yuvraj Vansure Co-authored-by: Lokesh <110647904+lokesh-sreedhara@users.noreply.github.com> Co-authored-by: lokesh-sreedhara Co-authored-by: Sanjay Prabhakar Co-authored-by: André Marcelino <31037381+andrercm@users.noreply.github.com> --- image/cli/mascli/functions/mirror_images | 1 - image/cli/mascli/functions/update | 100 ++++++++++-------- .../mascli/templates/pipelinerun-update.yaml | 4 + tekton/src/pipelines/update.yml.j2 | 16 ++- tekton/src/tasks/dependencies/uds.yml.j2 | 6 +- 5 files changed, 79 insertions(+), 48 deletions(-) diff --git a/image/cli/mascli/functions/mirror_images b/image/cli/mascli/functions/mirror_images index ae13279889..03324054bf 100644 --- a/image/cli/mascli/functions/mirror_images +++ b/image/cli/mascli/functions/mirror_images @@ -55,7 +55,6 @@ Content Selection (Cloud Pak for Data): Content Selection (Other Dependencies): --mirror-cfs Mirror images for IBM Cloud Pak Foundation Services --mirror-uds Mirror images for IBM User Data Services - --mirror-dro Mirror images for IBM Data Reporter Operator --mirror-sls Mirror images for IBM Suite License Service --mirror-tsm Mirror images for IBM Truststore Manager --mirror-mongo Mirror images for MongoDb Community Edition diff --git a/image/cli/mascli/functions/update b/image/cli/mascli/functions/update index fa3795669c..29b1c2e618 100644 --- a/image/cli/mascli/functions/update +++ b/image/cli/mascli/functions/update @@ -19,7 +19,7 @@ Update Dependencies (Optional): --kafka-namespace ${COLOR_YELLOW}KAFKA_NAMESPACE${TEXT_RESET} Namespace where Kafka operator and instance will be updated --kafka-provider ${COLOR_YELLOW}KAFKA_PROVIDER${TEXT_RESET} Set Kafka provider. Supported options are 'redhat' (Red Hat AMQ Streams), or 'strimzi' --dro-migration ${COLOR_YELLOW}DRO_MIGRATION${TEXT_RESET} Confirm the removal of UDS and replacement with DRO as part of the update - + --dro-storage-class ${COLOR_YELLOW}DRO_STORAGE_CLASS${TEXT_RESET} Set Custom RWO Storage Class name for DRO as part of the update Other Commands: --no-confirm Launch the update without prompting for confirmation -h, --help Show this help message @@ -123,57 +123,52 @@ function validate_existing_mongo() { # Validate UDS to DRO Migration # ----------------------------------------------------------------------------- -function validate_dro_migration(){ +function validate_dro_migration() { # warn about DRO migration if UDS is running and MAS catalog is January 2024 or newer MAS_CATALOG_DATE=${MAS_CATALOG_VERSION:3:6} if [[ $MAS_CATALOG_DATE -ge 240227 ]]; then - echo -e "${COLOR_YELLOW}Verifing UDS status." - # If Jan catalog is detected, set DRO_MIGRATION Flag to True - UDS_NAMESPACE="ibm-common-services" - UDS_CSV=`oc get csv -n "${UDS_NAMESPACE}" | grep user-data-services | awk '{print $1}'` - - if [[ -n $UDS_CSV ]]; then - UDS_STATUS=`oc get csv -n "${UDS_NAMESPACE}" "${UDS_CSV}" -o jsonpath='{.status.phase}'` - - if [[ $UDS_STATUS = *'Succeeded'* ]]; then - echo -e "${COLOR_YELLOW}UDS is currently running in namespace ${UDS_NAMESPACE}." - echo -e "UDS will be uninstalled and MAS will migrate to use DRO (Data Reporter Operator). All compatible bascfg configuration will be updated and configured to use DRO ${COLOR_RESET}" - echo - - if [[ "$NO_CONFIRM" != "true" ]]; then - prompt_for_confirm_default_yes "Do you want to proceed with uninstalling UDS and migrate to DRO?" DRO_MIGRATION - fi + if [[ "$NO_CONFIRM" != "true" ]] && [[ -z "${DRO_MIGRATION}" ]]; then + prompt_for_confirm_default_yes "Do you want to proceed with uninstalling UDS and migrate to DRO?" DRO_MIGRATION + fi + if [[ "$DRO_MIGRATION" == "true" ]]; then + echo -e "${COLOR_YELLOW}Verifing UDS status." + # If Jan catalog is detected, set DRO_MIGRATION Flag to True + UDS_NAMESPACE="ibm-common-services" + UDS_CSV=$(oc get csv -n "${UDS_NAMESPACE}" | grep user-data-services | awk '{print $1}') + if [[ -n $UDS_CSV ]]; then + UDS_STATUS=$(oc get csv -n "${UDS_NAMESPACE}" "${UDS_CSV}" -o jsonpath='{.status.phase}') + if [[ $UDS_STATUS = *'Succeeded'* ]]; then + echo -e "${COLOR_YELLOW}UDS is currently running in namespace ${UDS_NAMESPACE}." + echo -e "UDS will be uninstalled and MAS will migrate to use DRO (Data Reporter Operator). All compatible bascfg configuration will be updated and configured to use DRO ${COLOR_RESET}" + echo + if [[ "$NO_CONFIRM" != "true" ]] && [[ -z "${DRO_STORAGE_CLASS}" ]]; then + prompt_for_input "Enter the name of a RWO Storage Class to configure DRO, leave it blank if you want the CLI to autodetect a storage class:" DRO_STORAGE_CLASS + else + DRO_STORAGE_CLASS="" + fi - if [[ "$DRO_MIGRATION" == "true" ]]; then ## Check all avaliable Suite Instances versions , if any of them is 8.9.x cancel the dro migration. Exit mas update throw error. - for suite_namespace in $(oc get Suite --all-namespaces --ignore-not-found -o jsonpath='{.items[*].metadata.namespace}') - do - suite_name=`oc get Suite -n ${suite_namespace} -o NAME` - suite_version=`oc get ${suite_name} -n ${suite_namespace} -o jsonpath='{.status.versions.reconciled}'` + for suite_namespace in $(oc get Suite --all-namespaces --ignore-not-found -o jsonpath='{.items[*].metadata.namespace}'); do + suite_name=$(oc get Suite -n ${suite_namespace} -o NAME) + suite_version=$(oc get ${suite_name} -n ${suite_namespace} -o jsonpath='{.status.versions.reconciled}') - if [[ $suite_version = 9.* ]] || [[ $suite_version = 8.11.* ]] || [[ $suite_version = 8.10.* ]] - then + if [[ $suite_version = 9.* ]] || [[ $suite_version = 8.11.* ]] || [[ $suite_version = 8.10.* ]]; then ## Check if the BASCFG url has a local UDS on all instances, if not then exit and throw error - bascfg_name=`oc get BasCfg -n ${suite_namespace} -o NAME` - bas_url=`oc get ${bascfg_name} -n ${suite_namespace} -o jsonpath='{.spec.config.url}'` - uds_url=`oc get route uds-endpoint -n ibm-common-services -o jsonpath='{.spec.host}'` + bascfg_name=$(oc get BasCfg -n ${suite_namespace} -o NAME) + bas_url=$(oc get ${bascfg_name} -n ${suite_namespace} -o jsonpath='{.spec.config.url}') + uds_url=$(oc get route uds-endpoint -n ibm-common-services -o jsonpath='{.spec.host}') - if [[ -z ${uds_url} ]] - then + if [[ -z ${uds_url} ]]; then echo -e "${COLOR_RED}UDS route is empty, Please fix your UDS installation to proceed with DRO migration, exiting mas update" exit 1 fi - if [[ ${bas_url} == *${uds_url}* ]] - then + if [[ ${bas_url} == *${uds_url}* ]]; then echo -e "${COLOR_YELLOW}UDS Configuration on ${suite_namespace} with MAS version ${suite_version} is compatible for DRO migration" - - elif [[ ${bas_url} == *ibm-data-reporter* ]] - then + elif [[ ${bas_url} == *ibm-data-reporter* ]]; then echo -e "${COLOR_YELLOW}${suite_namespace} is already configured with DRO" - else echo -e "${COLOR_RED}${suite_namespace} appears to use a Remote UDS that is not running locally on this cluster. This setup is not compatible for DRO migration, exiting mas update" exit 1 @@ -185,16 +180,27 @@ function validate_dro_migration(){ echo done else - echo -e "${COLOR_RED}You must accept the migration from UDS to DRO to continue with the update to ${MAS_CATALOG_VERSION}" + echo -e "${COLOR_RED}UDS is in Error state. Please fix your UDS installation to proceed with DRO migration, exiting mas update" exit 1 fi else - echo -e "${COLOR_RED}UDS is in Error state. Please fix your UDS installation to proceed with DRO migration, exiting mas update" - exit 1 + DRO_MIGRATION="false" + echo -e "${COLOR_YELLOW}UDS does not exist, skipping DRO migration and proceeding with mas update" + DRO_NAMESPACE="redhat-marketplace" + DRO_CSV=$(oc get csv -n "${DRO_NAMESPACE}" | grep ibm-data-reporter-operator | awk '{print $1}') + echo $DRO_CSV + if [[ -n $DRO_CSV ]]; then + DRO_STATUS=$(oc get csv -n "${DRO_NAMESPACE}" "${DRO_CSV}" -o jsonpath='{.status.phase}') + if [[ $DRO_STATUS = *'Succeeded'* ]]; then + echo -e "${COLOR_YELLOW}DRO is currently running in namespace ${DRO_NAMESPACE}, skipping DRO migration and proceeding with mas update" + UDS_ACTION="skip" + fi + fi fi else - DRO_MIGRATION="false" - echo -e "${COLOR_YELLOW}UDS does not exist, skipping DRO migration and proceeding with mas update" + echo -e "${COLOR_YELLOW} Skipping the migration from UDS to DRO." + echo -e "${COLOR_YELLOW} By choosing 'Yes', you must confirm the migration from UDS to DRO" + echo -e "${COLOR_YELLOW} Or Add '--dro-migration' argument to the 'mas update' command in order to continue the migration from UDS to DRO" fi else DRO_MIGRATION="false" @@ -202,6 +208,7 @@ function validate_dro_migration(){ } + # Auto-detect Grafana # ----------------------------------------------------------------------------- # Detects whether Grafana V4 Operator is in the target cluster and prints a @@ -344,6 +351,9 @@ function update_noninteractive() { --dro-migration) DRO_MIGRATION=true ;; + --dro-storage-class) + DRO_STORAGE_CLASS=$1 && shift + ;; --no-confirm) NO_CONFIRM=true ;; @@ -442,6 +452,8 @@ function update() { export CERT_MANAGER_ACTION export DRO_MIGRATION export GRAFANA_V5_UPGRADE + export DRO_STORAGE_CLASS + export UDS_ACTION echo_h2 "Review Settings" @@ -494,9 +506,13 @@ function update() { if [ "$DRO_MIGRATION" = "true" ]; then echo_reset_dim "DRO Migration .............................. ${COLOR_GREEN}Yes${TEXT_RESET}" + if [ "$DRO_STORAGE_CLASS" != "" ]; then + echo_reset_dim "DRO Storage Class .............................. ${COLOR_GREEN}${DRO_STORAGE_CLASS}${TEXT_RESET}" + else + echo_reset_dim "DRO Storage Class .............................. ${COLOR_GREEN}None${TEXT_RESET}" + fi else echo_reset_dim "DRO Migration .............................. ${COLOR_RED}No${TEXT_RESET}" - fi # Grafana Operator diff --git a/image/cli/mascli/templates/pipelinerun-update.yaml b/image/cli/mascli/templates/pipelinerun-update.yaml index 829d314db3..0695292d1a 100644 --- a/image/cli/mascli/templates/pipelinerun-update.yaml +++ b/image/cli/mascli/templates/pipelinerun-update.yaml @@ -33,5 +33,9 @@ spec: value: "$CERT_MANAGER_ACTION" - name: dro_migration value: '$DRO_MIGRATION' + - name: uds_storage_class + value: '$DRO_STORAGE_CLASS' + - name: uds_action + value: '$UDS_ACTION' - name: grafana_v5_upgrade value: '$GRAFANA_V5_UPGRADE' diff --git a/tekton/src/pipelines/update.yml.j2 b/tekton/src/pipelines/update.yml.j2 index d22ba0718c..fa510ea41b 100644 --- a/tekton/src/pipelines/update.yml.j2 +++ b/tekton/src/pipelines/update.yml.j2 @@ -114,7 +114,15 @@ spec: - name: dro_migration default: "" type: string - description: Set to 'true' to Migration UDS to DRO + description: Set to 'true' to Migration UDS to DRO + - name: uds_storage_class + default: "" + type: string + description: Set custom storageclass for UDS/DRO + - name: uds_action + default: "install-dro" + type: string + description: set UDS_ACTION, default is install-dro' # grafana operator update - name: grafana_v5_upgrade @@ -298,7 +306,7 @@ spec: value: $(params.kafka_namespace) - name: kafka_provider value: $(params.kafka_provider) - + # UDS/DRO Migration - name: update-uds taskRef: @@ -309,6 +317,10 @@ spec: params: - name: dro_migration value: $(params.dro_migration) + - name: uds_storage_class + value: $(params.uds_storage_class) + - name: uds_action + value: $(params.uds_action) - name: devops_suite_name value: update-uds {% if wait_for_install == true %} diff --git a/tekton/src/tasks/dependencies/uds.yml.j2 b/tekton/src/tasks/dependencies/uds.yml.j2 index fc7f71c17a..e299f44a48 100644 --- a/tekton/src/tasks/dependencies/uds.yml.j2 +++ b/tekton/src/tasks/dependencies/uds.yml.j2 @@ -101,8 +101,7 @@ spec: value: $(params.uds_contact_firstname) - name: UDS_CONTACT_LASTNAME value: $(params.uds_contact_lastname) - - name: DRO_MIGRATION - value: $(params.dro_migration) + # IBM Data Reporter Operator (DRO) # ------------------------------------------------------------------------- @@ -143,7 +142,8 @@ spec: value: $(params.uds_contact_lastname) - name: DRO_MIGRATION value: $(params.dro_migration) - + - name: DRO_STORAGE_CLASS + value: $(params.uds_storage_class) workspaces: - name: configs optional: true