github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/config/scripts/delete_oke_cluster.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2020, 2022, Oracle and/or its affiliates.
     4  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     5  #
     6  
     7  SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P)
     8  CLUSTER_COUNT=${1:-1}
     9  KUBECONFIG_DIR=${2:-""}
    10  INSTALL_CALICO=${3:-true}
    11  
    12  set +e
    13  
    14  # delete LB given its IP address
    15  function delete_lb() {
    16    if [ ! -z "$1" ]; then
    17      echo "trying to delete LB with IP address $1"
    18      local LB_ID=$(oci lb load-balancer list --compartment-id="${TF_VAR_compartment_id}" --region="${TF_VAR_region}" \
    19      | jq -r --arg IP_ADDRESS "$1" '.data[] | select(."ip-addresses"[0]."ip-address" == ($IP_ADDRESS)) | .id')
    20      if [ ! -z "${LB_ID}" ]; then
    21        echo "LB to be deleted has ID ${LB_ID}"
    22        oci lb load-balancer delete --force --load-balancer-id ${LB_ID} --region ${TF_VAR_region}
    23      fi
    24    fi
    25  }
    26  
    27  function cleanup_vz_resources() {
    28    echo "Deleting the resources created by Verrazzano ..."
    29    # get LB IP
    30    ISTIO_IP=$(kubectl get svc istio-ingressgateway -n istio-system -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')
    31    echo "The LB IP address for istio-ingressgateway is ${ISTIO_IP}"
    32    NGINX_IP=$(kubectl get svc ingress-controller-ingress-nginx-controller -n ingress-nginx -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')
    33    echo "The LB IP address for nginx-controller is ${NGINX_IP}"
    34  
    35    # uninstalling some services to release resources
    36    helm uninstall keycloak --namespace keycloak --timeout 5m0s
    37    helm uninstall verrazzano --namespace verrazzano-system --timeout 5m0s
    38    helm uninstall ingress-controller --namespace ingress-nginx --timeout 5m0s
    39    kubectl delete service istio-ingressgateway -n istio-system --timeout 2m
    40    kubectl delete deployment istio-ingressgateway -n istio-system --timeout 2m
    41  
    42    # delete LB if they are deleted by deleting the services
    43    delete_lb "${ISTIO_IP}"
    44    delete_lb "${NGINX_IP}"
    45  
    46    # clean up PVC
    47    kubectl delete pvc --all -n keycloak --timeout 2m
    48    # wait until OKE cleans up the deleted resources
    49    timeout 2m bash -c 'until kubectl get pv -A 2>&1 | grep "No resources found"; do sleep 10; done'
    50  
    51    # log what still exists, just in case
    52    kubectl get pvc,pv,svc -A
    53  }
    54  
    55  for i in $(seq 1 $CLUSTER_COUNT)
    56  do
    57    if [ "$CLUSTER_COUNT" -gt 1 ]; then
    58      echo "Setting ${KUBECONFIG_DIR}/$i/kube_config to KUBECONFIG"
    59      export KUBECONFIG=${KUBECONFIG_DIR}/$i/kube_config
    60      export VERRAZZANO_KUBECONFIG=$KUBECONFIG
    61    fi
    62    resName=$(kubectl get vz -o jsonpath='{.items[*].metadata.name}')
    63    echo "Deleting verrazzano resource ${resName}"
    64    kubectl delete vz ${resName} --timeout 30m
    65    cleanup_vz_resources
    66  done
    67  
    68  # delete the OKE clusters
    69  cd $SCRIPT_DIR/terraform/cluster
    70  
    71  for i in $(seq 1 $CLUSTER_COUNT)
    72  do
    73    if [ "$CLUSTER_COUNT" -gt 1 ]; then
    74      workspace=cluster-$i
    75      echo "Setting Terraform workspace: $workspace"
    76      ./terraform workspace select $workspace -no-color
    77    fi
    78  
    79    # Set Calico related mandatory variables
    80    export TF_VAR_calico_enabled="${INSTALL_CALICO}"
    81    export TF_VAR_calico_version="$(grep 'calico-version=' ${SCRIPT_DIR}/../../../../.third-party-test-versions | sed 's/calico-version=//g')"
    82  
    83    ./delete-cluster.sh
    84  done