Uninstalling the Metering service
The Metering service is no longer available starting from version 3.7.x. If you previously installed Metering, then it is still available, but will not receive future updates. You can uninstall this service if you confirm that it is no longer needed.
Required user type or access level: Cluster administrator
Important: Do not uninstall the Metering service unless you are certain that it is no longer needed. Removing the Metering service when it is still required can damage or break your environment. Some IBM Cloud Paks and components might rely on the Metering service.
Scripted uninstall of the Metering service
-
Create a script, for example,
uninstall_metering_operator.sh
and add the following code.#!/bin/bash # Licensed Materials - Property of IBM # Copyright IBM Corporation 2021. All Rights Reserved # US Government Users Restricted Rights - # Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # This is an internal component, bundled with an official IBM product. # Please refer to that particular license for additional information. # # This script intends to clean up the resources installed by the obsolete metering operator # - ibm-metering-operator # Main operand request namespace NAMESPACE=$1 # Main operand request name OPERANDREQUEST_NAME=$2 # Check for arguments if [[ ( -z "${NAMESPACE}" || -z "${OPERANDREQUEST_NAME}" ) ]]; then echo "Usage: $0 NAMESPACE OPERANDREQUEST_NAME" echo "Uninstall obsolete metering operator." echo "" echo "Parameters:" echo "NAMESPACE the main operandrequest namespace" echo "OPERANDREQUEST_NAME the name of the main operandrequest" exit 1 fi # Ensure the operators are not in operandregistry DEFINED_IN_REGISTRY=$(oc -n ibm-common-services get operandregistry common-service -o jsonpath='{.spec} ' --ignore-not-found | grep 'ibm-metering-operator') if [[ ! -z "${DEFINED_IN_REGISTRY}" ]]; then CS_OPERATOR=$(oc -n ibm-common-services get csv | grep ibm-common-service-operator | awk '{print $1}') echo "[ERROR] This script cannot be used with ${CS_OPERATOR}" exit 1 fi # Ensure main operandrequest is present if [[ -z "$(oc -n ${NAMESPACE} get operandrequest ${OPERANDREQUEST_NAME} --no-headers --ignore-not-found)" ]]; then echo "[ERROR] main operandrequest '${OPERANDREQUEST_NAME}' not found in namespace '${NAMESPACE}'" exit 1 fi echo "Start uninstalling obsolete metering operator ..." echo "-------------------------------------------------" # Delete main operand request echo "[INFO] Deleting from main operand request ..." MAIN_OPERANDREQUEST=$(oc -n ${NAMESPACE} get operandrequest ${OPERANDREQUEST_NAME} -o jsonpath='{.spec.requests}' --ignore-not-found) OBSOLETE_OPERATORS=$(echo "${MAIN_OPERANDREQUEST}" | grep -E "ibm-metering-operator") if [[ ! -z "${OBSOLETE_OPERATORS}" ]]; then if [[ ! -z "$(oc -n ${NAMESPACE} apply view-last-applied operandrequest ${OPERANDREQUEST_NAME})" ]]; then oc -n ${NAMESPACE} apply view-last-applied operandrequest ${OPERANDREQUEST_NAME} \ | sed -E "/ibm-metering-operator/d" | oc apply -f - else oc -n ${NAMESPACE} get operandrequest ${OPERANDREQUEST_NAME} -o yaml --export \ | sed -E "/ibm-metering-operator/d" | oc apply -f - fi fi # Delete custom resources echo "[INFO] Deleting custom resources ..." if [[ ! -z "$(oc get crd meteringmulticlouduis.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc -n ibm-common-services delete meteringmulticlouduis.operator.ibm.com meteringmcmui --ignore-not-found fi if [[ ! -z "$(oc get crd meteringreportservers.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc -n ibm-common-services delete meteringreportservers.operator.ibm.com meteringreportserver --ignore-not-found fi if [[ ! -z "$(oc get crd meterings.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc -n ibm-common-services delete meterings.operator.ibm.com metering --ignore-not-found fi if [[ ! -z "$(oc get crd meteringsenders.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc -n ibm-common-services delete meteringsenders.operator.ibm.com meteringsender --ignore-not-found fi if [[ ! -z "$(oc get crd meteringuis.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc -n ibm-common-services delete meteringuis.operator.ibm.com meteringui --ignore-not-found fi # Delete operand requests echo "[INFO] Deleting operand requests ..." oc -n ibm-common-services delete operandrequest ibm-metering-request --ignore-not-found # Delete install plans echo "[INFO] Deleting install plans ..." oc -n ibm-common-services get installplan --no-headers --ignore-not-found \ | grep ibm-metering-operator | awk '{print $1}' \ | xargs oc -n ibm-common-services delete installplan # Delete subscriptions echo "[INFO] Deleting subscriptions ..." oc -n ibm-common-services delete sub ibm-metering-operator --ignore-not-found # Delete cluster service versions echo "[INFO] Deleting cluster service versions ..." oc -n ibm-common-services get csv --no-headers --ignore-not-found -o name \ | grep ibm-metering-operator | xargs oc -n ibm-common-services delete # Delete custom resources echo "[INFO] Deleting custom resources ..." if [[ ! -z "$(oc get crd meteringmulticlouduis.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc delete crd meteringmulticlouduis.operator.ibm.com --ignore-not-found --ignore-not-found --timeout=30s fi # Force delete custom resources if [[ ! -z "$(oc get crd meteringmulticlouduis.operator.ibm.com --ignore-not-found --no-headers)" ]]; then echo "[INFO] Force Deleting custom resources ..." oc -n ibm-common-services patch crd meteringmulticlouduis.operator.ibm.com --type=merge --patch '{"metadata":{"finalizers":[]}}' oc delete crd meteringmulticlouduis.operator.ibm.com --ignore-not-found --timeout=30s fi if [[ ! -z "$(oc get crd meteringreportservers.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc delete crd meteringreportservers.operator.ibm.com --ignore-not-found --ignore-not-found --timeout=30s fi # Force delete custom resources if [[ ! -z "$(oc get crd meteringreportservers.operator.ibm.com --ignore-not-found --no-headers)" ]]; then echo "[INFO] Force Deleting custom resources ..." oc -n ibm-common-services patch crd meteringreportservers.operator.ibm.com --type=merge --patch '{"metadata":{"finalizers":[]}}' oc delete crd meteringreportservers.operator.ibm.com --ignore-not-found --timeout=30s fi if [[ ! -z "$(oc get crd meterings.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc delete crd meterings.operator.ibm.com --ignore-not-found --ignore-not-found --timeout=30s fi # Force delete custom resources if [[ ! -z "$(oc get crd meterings.operator.ibm.com --ignore-not-found --no-headers)" ]]; then echo "[INFO] Force Deleting custom resources ..." oc -n ibm-common-services patch crd meterings.operator.ibm.com --type=merge --patch '{"metadata":{"finalizers":[]}}' oc delete crd meterings.operator.ibm.com --ignore-not-found --timeout=30s fi if [[ ! -z "$(oc get crd meteringsenders.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc delete crd meteringsenders.operator.ibm.com --ignore-not-found --ignore-not-found --timeout=30s fi # Force delete custom resources if [[ ! -z "$(oc get crd meteringsenders.operator.ibm.com --ignore-not-found --no-headers)" ]]; then echo "[INFO] Force Deleting custom resources ..." oc -n ibm-common-services patch crd meteringsenders.operator.ibm.com --type=merge --patch '{"metadata":{"finalizers":[]}}' oc delete crd meteringsenders.operator.ibm.com --ignore-not-found --timeout=30s fi if [[ ! -z "$(oc get crd meteringuis.operator.ibm.com --ignore-not-found --no-headers)" ]]; then oc delete crd meteringuis.operator.ibm.com --ignore-not-found --ignore-not-found --timeout=30s fi # Force delete custom resources if [[ ! -z "$(oc get crd meteringuis.operator.ibm.com --ignore-not-found --no-headers)" ]]; then echo "[INFO] Force Deleting custom resources ..." oc -n ibm-common-services patch crd meteringuis.operator.ibm.com --type=merge --patch '{"metadata":{"finalizers":[]}}' oc delete crd meteringuis.operator.ibm.com --ignore-not-found --timeout=30s fi echo "----------------------------------------------" echo "[INFO] Done"
-
Set the permissions on the script and run it by specifying the namespace and main operand request name. For example,
./uninstall_metering_operator.sh ibm-common-services common-service