Check for errors by default in scripts
[icn.git] / deploy / metal3 / scripts / 01_metal3.sh
index 6e6a1e9..dbfa2d3 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/bash
-set +ex
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
 
@@ -15,7 +15,7 @@ fi
 IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE}
 IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum
 
-function get_default_inteface_ipaddress {
+function get_default_interface_ipaddress {
     local _ip=$1
     local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
     local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
@@ -48,7 +48,7 @@ function deprovision_compute_node {
 }
 
 function set_compute_ssh_config {
-    get_default_inteface_ipaddress default_addr
+    get_default_interface_ipaddress default_addr
     cat << EOF
 - path: /root/.ssh/config
     owner: root:root
@@ -93,14 +93,22 @@ function create_userdata {
 }
 
 function launch_baremetal_operator {
-    if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then
-        go get github.com/metal3-io/baremetal-operator
-        git checkout 3d40caa29dce82878d83aeb7f8dab4dc4a856160
-    fi
+    docker pull integratedcloudnative/baremetal-operator:v1.0-icn
+    kubectl apply -f bmo/namespace/namespace.yaml
+    kubectl apply -f bmo/rbac/service_account.yaml -n metal3
+    kubectl apply -f bmo/rbac/role.yaml -n metal3
+    kubectl apply -f bmo/rbac/role_binding.yaml
+    kubectl apply -f bmo/crds/metal3.io_baremetalhosts_crd.yaml
+    kubectl apply -f bmo/operator/no_ironic/operator.yaml -n metal3
+}
 
-    pushd $GOPATH/src/github.com/metal3-io/baremetal-operator
-    make deploy
-    popd
+function remove_baremetal_operator {
+    kubectl delete -f bmo/operator/no_ironic/operator.yaml -n metal3
+    kubectl delete -f bmo/crds/metal3.io_baremetalhosts_crd.yaml
+    kubectl delete -f bmo/rbac/role_binding.yaml
+    kubectl delete -f bmo/rbac/role.yaml -n metal3
+    kubectl delete -f bmo/rbac/service_account.yaml -n metal3
+    kubectl delete -f bmo/namespace/namespace.yaml
 }
 
 function network_config_files {
@@ -192,11 +200,25 @@ function cleanup {
         kubectl delete bmh $name -n metal3
         kubectl delete secrets $name-bmc-secret -n metal3
         kubectl delete secrets $name-user-data -n metal3
+        if [ -f $name-bm-node.yaml ]; then
+            rm -rf $name-bm-node.yaml
+        fi
+
+        if [ -f $name-user-data-credential.yaml ]; then
+            rm -rf $name-user-data-credential.yaml
+        fi
+
+        if [ -f $name-userdata.yaml ]; then
+            rm -rf $name-userdata.yaml
+        fi
     done
 }
 
 function clean_all {
     list_nodes | cleanup
+    if [ -f $IRONIC_DATA_DIR/nodes.json ]; then
+        rm -rf $IRONIC_DATA_DIR/nodes.json
+    fi
 }
 
 function apply_bm_hosts {
@@ -230,11 +252,17 @@ if [ "$1" == "clean" ]; then
     exit 0
 fi
 
+if [ "$1" == "remove" ]; then
+    remove_baremetal_operator
+    exit 0
+fi
+
 echo "Usage: metal3.sh"
 echo "launch      - Launch the metal3 operator"
 echo "provision   - provision baremetal node as specified in common.sh"
 echo "deprovision - deprovision baremetal node as specified in common.sh"
-echo "clean       - clean all the resources"
+echo "clean       - clean all the bmh resources"
+echo "remove      - remove baremetal operator"
 exit 1
 
 #Following code is tested for the offline mode