Add additional clean targets
[icn.git] / deploy / baremetal-operator / baremetal-operator.sh
1 #!/usr/bin/env bash
2 set -eEux -o pipefail
3
4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
6
7 source $LIBDIR/logging.sh
8 source $LIBDIR/common.sh
9
10 trap err_exit ERR
11 function err_exit {
12     if command -v kubectl; then
13         kubectl get all -n baremetal-operator-system
14     fi
15 }
16
17 # This may be used to update the in-place Bare Metal Operator YAML
18 # files from the upstream project
19 function build_source {
20     clone_baremetal_operator_repository
21     KUSTOMIZATION_FILES=$(find ${BMOPATH}/config/kustomization.yaml ${BMOPATH}/config/{namespace,default,crd,rbac,manager,webhook,certmanager} -type f)
22     for src in ${KUSTOMIZATION_FILES}; do
23         dst=${src/${BMOPATH}\/config/${SCRIPTDIR}\/base}
24         mkdir -p $(dirname ${dst})
25         cp ${src} ${dst}
26     done
27 }
28
29 function deploy {
30     kustomize build ${SCRIPTDIR}/icn | kubectl apply -f -
31     kubectl wait --for=condition=Available --timeout=600s deployment/baremetal-operator-controller-manager -n baremetal-operator-system
32 }
33
34 function clean {
35     kustomize build ${SCRIPTDIR}/icn | kubectl delete --ignore-not-found=true -f -
36 }
37
38 case $1 in
39     "build-source") build_source ;;
40     "clean") clean ;;
41     "deploy") deploy ;;
42     *) cat <<EOF
43 Usage: $(basename $0) COMMAND
44
45 Commands:
46   build-source  - Rebuild the in-tree Bare Metal Operator YAML files
47   clean         - Remove the Bare Metal Operator
48   deploy        - Deploy the Bare Metal Operator
49 EOF
50        ;;
51 esac