Merge "Add job bm_verify_nestedk8s"
[icn.git] / deploy / metal3 / scripts / 01_metal3.sh
index fa9e2ec..75719e3 100755 (executable)
@@ -99,10 +99,28 @@ function launch_baremetal_operator {
     fi
 
     pushd $GOPATH/src/github.com/metal3-io/baremetal-operator
+    docker pull quay.io/metal3-io/baremetal-operator:master
     make deploy
     popd
 }
 
+function remove_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
+
+    pushd $GOPATH/src/github.com/metal3-io/baremetal-operator
+        kubectl delete -f deploy/operator.yaml -n metal3
+        kubectl delete -f deploy/crds/metal3_v1alpha1_baremetalhost_crd.yaml
+        kubectl delete -f deploy/role_binding.yaml
+        kubectl delete -f deploy/role.yaml -n metal3
+        kubectl delete -f deploy/service_account.yaml -n metal3
+        kubectl delete ns metal3
+        docker rmi quay.io/metal3-io/baremetal-operator:master
+    popd
+}
+
 function network_config_files {
     cat << 'EOF'
 write_files:
@@ -116,8 +134,21 @@ write_files:
         sudo ifconfig `basename $intf` up
         sudo dhclient -nw `basename $intf`
     done
+EOF
+cat << EOF
+- path: /opt/user_net.sh
+  owner: root:root
+  permissions: '0777'
+  content: |
+    #!/usr/bin/env bash
+    set -xe
+    route add default gw $PROVIDER_NETWORK_GATEWAY
+    sed -i -e 's/^#DNS=.*/DNS=$PROVIDER_NETWORK_DNS/g' /etc/systemd/resolved.conf
+    systemctl daemon-reload
+    systemctl restart systemd-resolved
 runcmd:
  - [ /opt/ironic_net.sh ]
+ - [ /opt/user_net.sh ]
 EOF
 }
 
@@ -174,6 +205,18 @@ function remove_bm_hosts {
     done
 }
 
+function cleanup {
+    while read -r name username password address; do
+        kubectl delete bmh $name -n metal3
+        kubectl delete secrets $name-bmc-secret -n metal3
+        kubectl delete secrets $name-user-data -n metal3
+    done
+}
+
+function clean_all {
+    list_nodes | cleanup
+}
+
 function apply_bm_hosts {
     list_nodes | make_bm_hosts
 }
@@ -188,19 +231,34 @@ if [ "$1" == "launch" ]; then
 fi
 
 if [ "$1" == "deprovision" ]; then
+    configure_nodes
     deprovision_all_hosts
     exit 0
 fi
 
 if [ "$1" == "provision" ]; then
+    configure_nodes
     apply_bm_hosts
     exit 0
 fi
 
+if [ "$1" == "clean" ]; then
+    configure_nodes
+    clean_all
+    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 bmh resources"
+echo "remove      - remove baremetal operator"
 exit 1
 
 #Following code is tested for the offline mode