Add option to remove DHCP from Ironic
[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 ENABLE_DHCP="${IRONIC_ENABLE_DHCP:-yes}"
12
13 trap err_exit ERR
14 function err_exit {
15     kubectl get all -n ${NAMEPREFIX}-system
16 }
17
18 # This may be used to update the in-place Ironic YAML files from the
19 # upstream project.  We cannot use the upstream sources directly as
20 # they require an envsubst step before kustomize build.
21 function build_source {
22     clone_baremetal_operator_repository
23     export NAMEPREFIX
24     KUSTOMIZATION_FILES=$(find ${BMOPATH}/ironic-deployment/{default,ironic} -type f)
25     for src in ${KUSTOMIZATION_FILES}; do
26         dst=${src/${BMOPATH}\/ironic-deployment/${SCRIPTDIR}\/base}
27         mkdir -p $(dirname ${dst})
28         envsubst <${src} >${dst}
29     done
30     sed -i -e '/name: quay.io\/metal3-io\/ironic/{n;s/newTag:.*/newTag: '"${BMO_VERSION}"'/;}' ${SCRIPTDIR}/icn/kustomization.yaml
31 }
32
33 function deploy {
34     fetch_image
35     local layer="${SCRIPTDIR}/icn"
36     if [[ ${ENABLE_DHCP} != "yes" ]]; then
37         layer="${SCRIPTDIR}/icn-no-dhcp"
38     fi
39     kustomize build ${layer} | kubectl apply -f -
40     kubectl wait --for=condition=Available --timeout=600s deployment/${NAMEPREFIX}-ironic -n ${NAMEPREFIX}-system
41 }
42
43 function clean {
44     kustomize build ${SCRIPTDIR}/icn | kubectl delete -f -
45 }
46
47 case $1 in
48     "build-source") build_source ;;
49     "clean") clean ;;
50     "deploy") deploy ;;
51     *) cat <<EOF
52 Usage: $(basename $0) COMMAND
53
54 Commands:
55   build-source  - Rebuild the in-tree Ironic YAML files
56   clean         - Remove Ironic
57   deploy        - Deploy Ironic
58 EOF
59        ;;
60 esac