Merge "Fix unbound variable error"
[icn.git] / deploy / ironic / ironic.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 NAMEPREFIX="capm3"
11
12 trap err_exit ERR
13 function err_exit {
14     kubectl get all -n ${NAMEPREFIX}-system
15 }
16
17 # This may be used to update the in-place Ironic YAML files from the
18 # upstream project.  We cannot use the upstream sources directly as
19 # they require an envsubst step before kustomize build.
20 function build_source {
21     clone_baremetal_operator_repository
22     export NAMEPREFIX
23     KUSTOMIZATION_FILES=$(find ${BMOPATH}/ironic-deployment/{default,ironic} -type f)
24     for src in ${KUSTOMIZATION_FILES}; do
25         dst=${src/${BMOPATH}\/ironic-deployment/${SCRIPTDIR}\/base}
26         mkdir -p $(dirname ${dst})
27         envsubst <${src} >${dst}
28     done
29 }
30
31 function deploy {
32     fetch_image
33     kustomize build ${SCRIPTDIR}/icn | kubectl apply -f -
34     kubectl wait --for=condition=Available --timeout=600s deployment/${NAMEPREFIX}-ironic -n ${NAMEPREFIX}-system
35 }
36
37 function clean {
38     kustomize build ${SCRIPTDIR}/icn | kubectl delete -f -
39 }
40
41 case $1 in
42     "build-source") build_source ;;
43     "clean") clean ;;
44     "deploy") deploy ;;
45     *) cat <<EOF
46 Usage: $(basename $0) COMMAND
47
48 Commands:
49   build-source  - Rebuild the in-tree Ironic YAML files
50   clean         - Remove Ironic
51   deploy        - Deploy Ironic
52 EOF
53        ;;
54 esac