Do not error when a deleted resource is not found 60/3960/2
authorTodd Malsbary <todd.malsbary@intel.com>
Thu, 3 Dec 2020 00:17:22 +0000 (16:17 -0800)
committerTodd Malsbary <todd.malsbary@intel.com>
Tue, 8 Dec 2020 00:45:55 +0000 (16:45 -0800)
Issue-ID: ICN-504
Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Change-Id: I6bf9aa9bba7342258d4d3943fa76ff44e3416166

cmd/bpa-operator/e2etest/bpa_bmh_verifier.sh
cmd/bpa-operator/e2etest/bpa_remote_virtletvm_verifier.sh
cmd/bpa-operator/e2etest/bpa_virtletvm_verifier.sh
cmd/bpa-operator/e2etest/bpa_vm_verifier.sh
deploy/metal3/scripts/01_metal3.sh
deploy/metal3/scripts/03_verify_deprovisioning.sh
env/metal3/03_launch_prereq.sh

index edf93df..aa0d8dc 100755 (executable)
@@ -48,6 +48,6 @@ kubectl logs $podName
 printf "\n\nBeginning BMH E2E Test Teardown\n\n"
 kubectl delete -f e2etest/test_bmh_provisioning_cr.yaml
 kubectl delete job kud-${CLUSTER_NAME}
-kubectl delete configmap ${CLUSTER_NAME}-configmap
+kubectl delete --ignore-not-found=true configmap ${CLUSTER_NAME}-configmap
 rm -rf /opt/kud/multi-cluster/${CLUSTER_NAME}
 make delete
index 78096b5..6f0fa1f 100755 (executable)
@@ -73,5 +73,5 @@ kubectl ${KUBECONFIG} logs $podName
 
 kubectl ${KUBECONFIG} delete -f bpa_remote_virtletvm_cr.yaml
 kubectl ${KUBECONFIG} delete job kud-remotevvm
-kubectl ${KUBECONFIG} delete configmap remotevvm-configmap
+kubectl ${KUBECONFIG} delete --ignore-not-found=true configmap remotevvm-configmap
 kubectl  ${KUBECONFIG} delete -f bpa_remote_virtletvm.yaml
index 946a1f9..949aad2 100755 (executable)
@@ -211,7 +211,7 @@ printf "\n\nBeginning E2E VM Test Teardown\n\n"
 
 kubectl delete -f e2e_bpa_test.yaml
 kubectl delete job kud-vmcluster110
-kubectl delete configmap vmcluster110-configmap
+kubectl delete --ignore-not-found=true configmap vmcluster110-configmap
 kubectl delete -f virtlet_test_vm.yaml
 rm -rf /opt/kud/multi-cluster/vmcluster110
 rm -rf $BPA_DIR
index b1f490e..2d93572 100755 (executable)
@@ -109,7 +109,7 @@ kubectl logs $podName
 printf "\n\nBeginning E2E Test Teardown\n\n"
 kubectl delete -f e2etest/e2e_test_provisioning_cr.yaml
 kubectl delete job kud-${CLUSTER_NAME}
-kubectl delete configmap ${CLUSTER_NAME}-configmap
+kubectl delete --ignore-not-found=true configmap ${CLUSTER_NAME}-configmap
 rm e2etest/e2e_test_provisioning_cr.yaml
 rm -rf /opt/kud/multi-cluster/${CLUSTER_NAME}
 rm /opt/icn/dhcp/dhcpd.leases
index 27a6685..d419b82 100755 (executable)
@@ -59,8 +59,10 @@ EOF
 
 function deprovision_compute_node {
     name="$1"
-    kubectl patch baremetalhost $name -n metal3 --type merge \
-    -p '{"spec":{"image":{"url":"","checksum":""}}}'
+    if kubectl get baremetalhost $name -n metal3 &>/dev/null; then
+        kubectl patch baremetalhost $name -n metal3 --type merge \
+        -p '{"spec":{"image":{"url":"","checksum":""}}}'
+    fi
 }
 
 function set_compute_ssh_config {
@@ -239,9 +241,9 @@ function remove_bm_hosts {
 
 function cleanup {
     while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do
-        kubectl delete bmh $name -n metal3
-        kubectl delete secrets $name-bmc-secret -n metal3
-        kubectl delete secrets $name-user-data -n metal3
+        kubectl delete --ignore-not-found=true bmh $name -n metal3
+        kubectl delete --ignore-not-found=true secrets $name-bmc-secret -n metal3
+        kubectl delete --ignore-not-found=true secrets $name-user-data -n metal3
         if [ -f $name-bm-node.yaml ]; then
             rm -rf $name-bm-node.yaml
         fi
index 4223cd8..5c49d1d 100755 (executable)
@@ -16,10 +16,15 @@ function check_deprovisioned {
     echo "Baremetal state: 1 means deprovisioned & 0 means not yet deprovisioned"
     while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do
         declare -i current_host_state=0
-        state=$(kubectl get baremetalhosts $name -n metal3 -o json | jq -r '.status.provisioning.state')
+        if kubectl get baremetalhost $name -n metal3 &>/dev/null; then
+            state=$(kubectl get baremetalhosts $name -n metal3 -o json | jq -r '.status.provisioning.state')
+        else
+            # When the named BareMetalHost is not found, assume its deprovisioned
+            state="ready"
+        fi
         echo "Baremetal host metal3 state - "$name" : "$state
 
-        if [ $state == "ready" ];then
+        if [ "$state" == "ready" ];then
             current_host_state=1
         fi
 
index 9d58f57..7559f2f 100755 (executable)
@@ -154,7 +154,7 @@ function install_dhcp {
 }
 
 function reset_dhcp {
-    kubectl delete -f $PWD/04_dhcp.yaml
+    kubectl delete --ignore-not-found=true -f $PWD/04_dhcp.yaml
     if [ -d $BS_DHCP_DIR ]; then
         rm -rf $BS_DHCP_DIR
     fi