@@ -19,6 +19,7 @@ OPERATOR_NS_LIST=""
1919CONTROL_NS=" "
2020FORCE_DELETE=0
2121DEBUG=0
22+ RETAIN=" false"
2223
2324# ---------- Command variables ----------
2425
@@ -46,7 +47,11 @@ function main() {
4647 delete_rbac_resource
4748 delete_webhook
4849 delete_unavailable_apiservice
49- delete_tenant_ns
50+ if [[ $RETAIN == " false" ]]; then
51+ delete_tenant_ns
52+ else
53+ cleanup_extra_resources
54+ fi
5055}
5156
5257function parse_arguments() {
@@ -69,8 +74,10 @@ function parse_arguments() {
6974 shift
7075 OPERATOR_NS=$1
7176 ;;
77+ --retain-ns)
78+ RETAIN=" true"
79+ ;;
7280 -f)
73- shift
7481 FORCE_DELETE=1
7582 ;;
7683 -v | --debug)
@@ -102,6 +109,7 @@ function print_usage() {
102109 echo " --yq string Optional. File path to yq CLI. Default uses yq in your PATH"
103110 echo " --operator-namespace string Required. Namespace to uninstall Foundational services operators and the whole tenant."
104111 echo " -f Optional. Enable force delete. It will take much more time if you add this label, we suggest run this script without -f label first"
112+ echo " --retain-ns Optional. Prevents script from deleting tenant namespaces during uninstall."
105113 echo " -v, --debug integer Optional. Verbosity of logs. Default is 0. Set to 1 for debug logs"
106114 echo " -h, --help Print usage information"
107115 echo " "
@@ -396,5 +404,21 @@ function cleanup_cs_control() {
396404
397405}
398406
407+ function cleanup_extra_resources() {
408+ info " Deleting excess resources while retaining tenant namespaces..."
409+ for ns in ${TENANT_NAMESPACES// ,/ } ; do
410+ ${OC} delete issuer cs-ss-issuer cs-ca-issuer -n $ns --ignore-not-found
411+ ${OC} delete certificate cs-ca-certificate -n $ns --ignore-not-found
412+ ${OC} delete configmap cloud-native-postgresql-image-list ibm-cpp-config -n $ns --ignore-not-found
413+ ${OC} delete secret common-service-db-im-tls-secret postgresql-operator-controller-manager-config cs-ca-certificate-secret common-service-db-tls-secret common-service-db-replica-tls-secret common-service-db-zen-tls-secret -n $ns --ignore-not-found
414+ ${OC} delete commonservice common-service -n $ns --ignore-not-found
415+ ${OC} delete operandconfig common-service -n $ns --ignore-not-found
416+ ${OC} delete operandregistry common-service -n $ns --ignore-not-found
417+ info " Remaining resources (minus package manifests and events) in namespace $ns :"
418+ ${OC} get " $( ${OC} api-resources --namespaced=true --verbs=list -o name | awk ' {printf "%s%s",sep,$0;sep=","}' ) " --ignore-not-found -n $ns -o=custom-columns=KIND:.kind,NAME:.metadata.name --sort-by=' kind' | grep -v PackageManifest | grep -v Event
419+ done
420+ success " Excess resources cleaned up in retained tenant namespaces."
421+ }
422+
399423
400424main $*
0 commit comments