version: 0.1 component: command timeoutInSeconds: 900 shell: bash failImmediatelyOnError: true env: variables: APP_NAMESPACE: kagent-demo WAIT_TIMEOUT: 300s OCI_REGION: mx-monterrey-1 OKE_CLUSTER_OCID: ocid1.cluster.oc1.mx-monterrey-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx OKE_ENDPOINT_TYPE: PUBLIC_ENDPOINT steps: - type: Command name: Validate parameters command: | if [ -z "${APP_NAMESPACE}" ]; then echo "APP_NAMESPACE parameter is required" exit 1 fi if [ -z "${WAIT_TIMEOUT}" ]; then echo "WAIT_TIMEOUT parameter is required" exit 1 fi if [ -z "${OCI_REGION}" ]; then echo "OCI_REGION parameter is required" exit 1 fi if [ -z "${OKE_CLUSTER_OCID}" ] || [ "${OKE_CLUSTER_OCID}" = "" ]; then echo "OKE_CLUSTER_OCID parameter is required" exit 1 fi if [ -z "${OKE_ENDPOINT_TYPE}" ]; then echo "OKE_ENDPOINT_TYPE parameter is required" exit 1 fi echo "APP_NAMESPACE=${APP_NAMESPACE}" echo "WAIT_TIMEOUT=${WAIT_TIMEOUT}" echo "OCI_REGION=${OCI_REGION}" echo "OKE_CLUSTER_OCID=${OKE_CLUSTER_OCID}" echo "OKE_ENDPOINT_TYPE=${OKE_ENDPOINT_TYPE}" - type: Command name: Configure kubeconfig command: | mkdir -p "${HOME}/.kube" oci ce cluster create-kubeconfig \ --cluster-id "${OKE_CLUSTER_OCID}" \ --file "${HOME}/.kube/config" \ --region "${OCI_REGION}" \ --token-version 2.0.0 \ --kube-endpoint "${OKE_ENDPOINT_TYPE}" export KUBECONFIG="${HOME}/.kube/config" echo "KUBECONFIG=${KUBECONFIG}" kubectl config current-context kubectl cluster-info - type: Command name: Show cleanup target command: | echo "Deleting kagent demo application resources" kubectl version --client=true kubectl get namespace "${APP_NAMESPACE}" - type: Command name: Delete external entry point first command: | echo "Deleting LoadBalancer service first so OCI can release the public load balancer" kubectl delete service order-service-lb \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true - type: Command name: Delete application workloads command: | kubectl delete deployment order-service inventory-service payment-service \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true kubectl delete cronjob kagent-oke-remediator \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true kubectl delete job -l cronjob-name=kagent-oke-remediator \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true kubectl delete serviceaccount kagent-oke-remediator \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true kubectl wait --for=delete pod \ -l app=order-service \ -n "${APP_NAMESPACE}" \ --timeout="${WAIT_TIMEOUT}" || true kubectl wait --for=delete pod \ -l app=inventory-service \ -n "${APP_NAMESPACE}" \ --timeout="${WAIT_TIMEOUT}" || true kubectl wait --for=delete pod \ -l app=payment-service \ -n "${APP_NAMESPACE}" \ --timeout="${WAIT_TIMEOUT}" || true kubectl wait --for=delete job \ -l cronjob-name=kagent-oke-remediator \ -n "${APP_NAMESPACE}" \ --timeout="${WAIT_TIMEOUT}" || true - type: Command name: Delete internal services and app config command: | kubectl delete service order-service inventory-service payment-service \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true kubectl delete configmap demo-config \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true kubectl delete hpa order-service inventory-service payment-service \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true - type: Command name: Verify cleanup command: | echo "Remaining application resources in ${APP_NAMESPACE}:" kubectl get deployment,svc,configmap,hpa,pod,cronjob,job,serviceaccount \ -n "${APP_NAMESPACE}" \ --ignore-not-found=true || true echo "Application cleanup completed. Namespace and imagePullSecrets were preserved."