|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | +trap 'echo "Error at line $LINENO. Exiting."' ERR |
| 19 | + |
| 20 | +read -p "Are you sure you want to delete ALL Dynamo CRDs and their instances? (y/N): " confirm |
| 21 | +if [[ "$confirm" != "y" ]]; then |
| 22 | + echo "Aborting." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Step 1: Get all CRDs with the prefix |
| 27 | +DYNAMO_CRDS="$(kubectl get crds -o name | grep 'nvidia.com' | grep 'dynamo' | cut -d'/' -f2)" |
| 28 | + |
| 29 | +if [ -z "${DYNAMO_CRDS}" ]; then |
| 30 | + echo "Dynamo CRDs not found" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Step 2: Delete all custom resource instances for each CRD |
| 35 | +for CRD in ${DYNAMO_CRDS}; do |
| 36 | + SCOPE=$(kubectl get crd "${CRD}" -o jsonpath='{.spec.scope}') |
| 37 | + |
| 38 | + if [ "$SCOPE" == "Namespaced" ]; then |
| 39 | + echo "Deleting all namespaced instances of ${CRD}..." |
| 40 | + kubectl get "${CRD}" --all-namespaces -o name | xargs -r kubectl delete --wait=false |
| 41 | + else |
| 42 | + echo "Skipping cluster-scoped CRD: ${CRD}" |
| 43 | + fi |
| 44 | +done |
| 45 | + |
| 46 | + |
| 47 | +# Step 3: Wait for the Operator to handle finalizer removal |
| 48 | +echo "Waiting for Dynamo Operator to handle the finalizer removal (30 seconds)..." |
| 49 | +sleep 30 |
| 50 | + |
| 51 | +# Step 4: Verify all Custom Resources have been removed |
| 52 | +for CRD in ${DYNAMO_CRDS}; do |
| 53 | + # Check CRs |
| 54 | + |
| 55 | + echo "Checking instances of ${CRD}" |
| 56 | + kubectl get "${CRD}" --all-namespaces -o name |
| 57 | +done |
| 58 | + |
| 59 | +# Step 5: Delete the CRDs themselves |
| 60 | +echo "Deleting CRDs..." |
| 61 | + |
| 62 | +for CRD in ${DYNAMO_CRDS}; do |
| 63 | + # Delete all CRD's |
| 64 | + |
| 65 | + echo "Deleting CRD: ${CRD}..." |
| 66 | + kubectl delete crd "${CRD}" |
| 67 | +done |
| 68 | + |
| 69 | + |
0 commit comments