Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: cleanup and reformat bash syntax in 04 script #1482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 01_prepare_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -eux

# shellcheck disable=SC1091
source lib/logging.sh
. lib/logging.sh
# shellcheck disable=SC1091
source lib/common.sh
. lib/common.sh

if [[ "${EUID}" -eq 0 ]]; then
echo "Please run 'make' as a non-root user"
Expand All @@ -28,7 +28,7 @@ if [[ "${OS}" = "ubuntu" ]]; then
ubuntu24)
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 ;;
*) ;;
esac
esac

elif [[ "${OS}" = "centos" ]] || [[ "${OS}" = "rhel" ]]; then
sudo dnf upgrade -y --nobest
Expand All @@ -53,14 +53,14 @@ fi
# NOTE(tuminoid) lib/releases.sh must be after the jq and python installation
# TODO: fix all of the lib/ scripts not to actually run code, but only define functions
# shellcheck disable=SC1091
source lib/releases.sh
. lib/releases.sh
# shellcheck disable=SC1091
source lib/download.sh
. lib/download.sh
# NOTE(fmuyassarov) Make sure to source before runnig install-package-playbook.yml
# because there are some vars exported in network.sh and used by
# install-package-playbook.yml.
# shellcheck disable=SC1091
source lib/network.sh
. lib/network.sh

# NOTE(dtantsur): system-site-packages is required because of certain Python
# packages that cannot be pip-installed (firewalld, selinux, etc).
Expand Down
50 changes: 26 additions & 24 deletions 02_configure_host.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env bash

set -eux

# shellcheck disable=SC1091
source lib/logging.sh
. lib/logging.sh
# shellcheck disable=SC1091
. lib/common.sh
# shellcheck disable=SC1091
source lib/common.sh
. lib/network.sh
# shellcheck disable=SC1091
source lib/network.sh
. lib/releases.sh
# shellcheck disable=SC1091
source lib/releases.sh
# pre-pull node and container images
. lib/image_prepull.sh
# shellcheck disable=SC1091
source lib/image_prepull.sh
. lib/utils.sh

# cleanup ci config file if it exists from earlier run
rm -f "${CI_CONFIG_FILE}"
Expand All @@ -30,7 +32,7 @@ elif grep -q svm /proc/cpuinfo; then
fi

# Clean, copy and extract local IPA
if [[ "${USE_LOCAL_IPA}" == "true" ]]; then
if [[ "${USE_LOCAL_IPA}" = "true" ]]; then
sudo rm -f "${IRONIC_DATA_DIR}/html/images/ironic-python-agent*"
sudo cp "${LOCAL_IPA_PATH}/ironic-python-agent.tar" "${IRONIC_DATA_DIR}/html/images"
sudo tar --extract --file "${IRONIC_DATA_DIR}/html/images/ironic-python-agent.tar" \
Expand Down Expand Up @@ -94,7 +96,7 @@ init_minikube()
fi
}

if [[ "${EPHEMERAL_CLUSTER}" == "minikube" ]]; then
if [[ "${EPHEMERAL_CLUSTER}" = "minikube" ]]; then
init_minikube
fi

Expand Down Expand Up @@ -137,19 +139,19 @@ EOF
sudo virsh pool-autostart default
fi

if [[ "${OS}" == "ubuntu" ]]; then
if [[ "${OS}" = "ubuntu" ]]; then
# source ubuntu_bridge_network_configuration.sh
# shellcheck disable=SC1091
source ubuntu_bridge_network_configuration.sh
# shellcheck disable=SC1091
source disable_apparmor_driver_libvirtd.sh
else
if [[ "${MANAGE_PRO_BRIDGE}" == "y" ]]; then
if [[ "${MANAGE_PRO_BRIDGE}" = "y" ]]; then
# Adding an IP address in the libvirt definition for this network results in
# dnsmasq being run, we don't want that as we have our own dnsmasq, so set
# the IP address here
if [[ ! -e /etc/NetworkManager/system-connections/provisioning.nmconnection ]]; then
if [[ "${BARE_METAL_PROVISIONER_SUBNET_IPV6_ONLY}" == "true" ]]; then
if [[ "${BARE_METAL_PROVISIONER_SUBNET_IPV6_ONLY}" = "true" ]]; then
sudo tee -a /etc/NetworkManager/system-connections/provisioning.nmconnection <<EOF
[connection]
id=provisioning
Expand Down Expand Up @@ -206,7 +208,7 @@ EOF
sudo nmcli con up "${PRO_IF}"
fi

if [[ "${MANAGE_INT_BRIDGE}" == "y" ]]; then
if [[ "${MANAGE_INT_BRIDGE}" = "y" ]]; then
if [[ "$(nmcli con show)" != *"external"* ]]; then
sudo tee /etc/NetworkManager/system-connections/external.nmconnection <<EOF
[connection]
Expand Down Expand Up @@ -250,7 +252,7 @@ EOF
fi

# Restart the libvirt network so it applies an ip to the bridge
if [[ "${MANAGE_EXT_BRIDGE}" == "y" ]]; then
if [[ "${MANAGE_EXT_BRIDGE}" = "y" ]]; then
sudo virsh net-destroy external
sudo virsh net-start external
if [[ -n "${INT_IF}" ]]; then
Expand All @@ -266,7 +268,7 @@ ANSIBLE_FORCE_COLOR=true "${ANSIBLE}-playbook" \
-b vm-setup/firewall.yml

# FIXME(stbenjam): ansbile firewalld module doesn't seem to be doing the right thing
if [[ "${USE_FIREWALLD}" == "True" ]]; then
if [[ "${USE_FIREWALLD}" = "True" ]]; then
sudo firewall-cmd --zone=libvirt --change-interface=provisioning
sudo firewall-cmd --zone=libvirt --change-interface=external
fi
Expand All @@ -281,7 +283,7 @@ fi
reg_state=$(sudo "${CONTAINER_RUNTIME}" inspect registry --format "{{.State.Status}}" || echo "error")

# ubuntu_install_requirements.sh script restarts docker daemon which causes local registry container to be in exited state.
if [[ "${reg_state}" == "exited" ]]; then
if [[ "${reg_state}" = "exited" ]]; then
sudo "${CONTAINER_RUNTIME}" start registry
elif [[ "${reg_state}" != "running" ]]; then
sudo "${CONTAINER_RUNTIME}" rm registry -f || true
Expand All @@ -293,7 +295,7 @@ detect_mismatch()
{
local LOCAL_IMAGE="$1"
local REPO_PATH="$2"
if [[ -z "${LOCAL_IMAGE}" ]] || [[ "${LOCAL_IMAGE}" == "${REPO_PATH}" ]]; then
if [[ -z "${LOCAL_IMAGE}" ]] || [[ "${LOCAL_IMAGE}" = "${REPO_PATH}" ]]; then
echo "Local image: ${LOCAL_IMAGE} and repo path: ${REPO_PATH} are matching!"
else
echo "There is a mismatch between LOCAL_IMAGE:${LOCAL_IMAGE} and IMAGE_PATH:${REPO_PATH}"
Expand Down Expand Up @@ -330,11 +332,11 @@ clone_repo "${IRSOREPO}" "${IRSOBRANCH}" "${IRSOPATH}" "${IRSOCOMMIT}"
# need to clone the repo.
# There is no need to keep the PATH and the IMAGE vars in sync as there
# is no other use of the path variable than cloning
if [[ "${MARIADB_LOCAL_IMAGE:-}" == "${MARIADB_IMAGE_PATH}" ]]; then
if [[ "${MARIADB_LOCAL_IMAGE:-}" = "${MARIADB_IMAGE_PATH}" ]]; then
clone_repo "${MARIADB_IMAGE_REPO}" "${MARIADB_IMAGE_BRANCH}" "${MARIADB_IMAGE_PATH}" "${MARIADB_IMAGE_COMMIT}"
fi

if [[ "${IRONIC_LOCAL_IMAGE:-}" == "${IRONIC_IMAGE_PATH}" ]]; then
if [[ "${IRONIC_LOCAL_IMAGE:-}" = "${IRONIC_IMAGE_PATH}" ]]; then
clone_repo "${IRONIC_IMAGE_REPO}" "${IRONIC_IMAGE_BRANCH}" "${IRONIC_IMAGE_PATH}" "${IRONIC_IMAGE_COMMIT}"
fi

Expand All @@ -352,7 +354,7 @@ for IMAGE_VAR in $(env | grep "_LOCAL_IMAGE=" | grep -o "^[^=]*"); do
IMAGE_DATE="$(date -u +%y_%j_%H%M)"

# Support building ironic-image from source
if [[ "${IMAGE_VAR/_LOCAL_IMAGE}" == "IRONIC" ]] && [[ ${IRONIC_FROM_SOURCE:-} == "true" ]]; then
if [[ "${IMAGE_VAR/_LOCAL_IMAGE}" = "IRONIC" ]] && [[ ${IRONIC_FROM_SOURCE:-} = "true" ]]; then
# NOTE(rpittau): to customize the source origin we need to copy the source code we
# want to use into the sources directory under the ironic-image repository.
for CODE_SOURCE_VAR in $(env | grep -E '^IRONIC_SOURCE=|^IRONIC_INSPECTOR_SOURCE=|^SUSHY_SOURCE=' | grep -o "^[^=]*"); do
Expand All @@ -368,7 +370,7 @@ for IMAGE_VAR in $(env | grep "_LOCAL_IMAGE=" | grep -o "^[^=]*"); do
-t "${IMAGE_URL}:latest" -t "${IMAGE_URL}:${IMAGE_GIT_HASH}_${IMAGE_DATE}" . -f ./Dockerfile

# TODO: Do we want to support CAPI in dev-env? CI just pulls it anyways ...
elif [[ "${IMAGE_VAR/_LOCAL_IMAGE}" == "CAPI" ]]; then
elif [[ "${IMAGE_VAR/_LOCAL_IMAGE}" = "CAPI" ]]; then
CAPI_GO_VERSION=$(grep "GO_VERSION ?= [0-9].*" Makefile | sed -e 's/GO_VERSION ?= //g')
# shellcheck disable=SC2016
CAPI_BASEIMAGE=$(grep "GO_CONTAINER_IMAGE ?=" Makefile | sed -e 's/GO_CONTAINER_IMAGE ?= //g' -e 's/$(GO_VERSION)//g')
Expand All @@ -382,7 +384,7 @@ for IMAGE_VAR in $(env | grep "_LOCAL_IMAGE=" | grep -o "^[^=]*"); do
fi

cd - || exit
if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
if [[ "${CONTAINER_RUNTIME}" = "podman" ]]; then
sudo "${CONTAINER_RUNTIME}" push --tls-verify=false "${IMAGE_URL}"
else
sudo "${CONTAINER_RUNTIME}" push "${IMAGE_URL}"
Expand All @@ -405,7 +407,7 @@ done

# IRONIC_IMAGE is also used in this script so when it is built locally and
# consequently unset, it has to be redefined for local use
if [[ "${BUILD_IRONIC_IMAGE_LOCALLY:-}" == "true" ]] || [[ -n "${IRONIC_LOCAL_IMAGE:-}" ]]; then
if [[ "${BUILD_IRONIC_IMAGE_LOCALLY:-}" = "true" ]] || [[ -n "${IRONIC_LOCAL_IMAGE:-}" ]]; then
IRONIC_IMAGE="${REGISTRY}/localimages/$(basename "${IRONIC_LOCAL_IMAGE}")"
export IRONIC_IMAGE
fi
Expand All @@ -423,15 +425,15 @@ for IMAGE_VAR in $(env | grep -v "_LOCAL_IMAGE=" | grep "_IMAGE=" | grep -o "^[^
LOCAL_IMAGE="${REGISTRY}/localimages/${IMAGE_NAME%@*}"
sudo "${CONTAINER_RUNTIME}" tag "${IMAGE}" "${LOCAL_IMAGE}"

if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
if [[ "${CONTAINER_RUNTIME}" = "podman" ]]; then
sudo "${CONTAINER_RUNTIME}" push --tls-verify=false "${LOCAL_IMAGE}"
else
sudo "${CONTAINER_RUNTIME}" push "${LOCAL_IMAGE}"
fi
done

# Start httpd-infra container
if [[ "${OS}" == "ubuntu" ]]; then
if [[ "${OS}" = "ubuntu" ]]; then
# shellcheck disable=SC2086
sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name httpd-infra ${POD_NAME_INFRA} \
-v "${IRONIC_DATA_DIR}":/shared --entrypoint /bin/runhttpd \
Expand Down
46 changes: 25 additions & 21 deletions 03_launch_mgmt_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
set -eux

# shellcheck disable=SC1091
source lib/logging.sh
. lib/logging.sh
# shellcheck disable=SC1091
source lib/common.sh
. lib/common.sh
# shellcheck disable=SC1091
source lib/releases.sh
. lib/releases.sh
# shellcheck disable=SC1091
source lib/network.sh
. lib/network.sh
# shellcheck disable=SC1091
. lib/utils.sh

# Default CAPI_CONFIG_DIR to $HOME/.config directory if XDG_CONFIG_HOME not set
CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}"
Expand All @@ -36,9 +38,9 @@ sudo mkdir -p "${IRONIC_DATA_DIR}"
sudo chown -R "${USER}:${USER}" "${IRONIC_DATA_DIR}"

# shellcheck disable=SC1091
source lib/ironic_tls_setup.sh
. lib/ironic_tls_setup.sh
# shellcheck disable=SC1091
source lib/ironic_basic_auth.sh
. lib/ironic_basic_auth.sh

# ------------------------------------
# BMO and Ironic deployment functions
Expand Down Expand Up @@ -135,11 +137,11 @@ update_images()
# Assign images from local image registry after update image
# This allows to use cached images for faster downloads
for image_var in $(env | grep -v "_LOCAL_IMAGE=" | grep "_IMAGE=" | grep -o "^[^=]*") ; do
image=${!image_var}
#shellcheck disable=SC2086
image_name="${image##*/}"
local_image="${REGISTRY}/localimages/${image_name}"
eval "${image_var}"="${local_image}"
image=${!image_var}
#shellcheck disable=SC2086
image_name="${image##*/}"
local_image="${REGISTRY}/localimages/${image_name}"
eval "${image_var}"="${local_image}"
done
}

Expand Down Expand Up @@ -397,7 +399,7 @@ make_bm_hosts()
-boot-mode "${BOOT_MODE}" \
"${name}" | \
tee "${WORKING_DIR}/bmhs/node_${i}.yaml" >> "${WORKING_DIR}/bmhosts_crs.yaml"
i=$((i+1))
i=$((i + 1))
done
}

Expand All @@ -412,7 +414,9 @@ apply_bm_hosts()
list_nodes | make_bm_hosts
if [[ -n "$(list_nodes)" ]]; then
echo "bmhosts_crs.yaml is applying"
while ! kubectl apply -f "${WORKING_DIR}/bmhosts_crs.yaml" -n "${namespace}" &>/dev/null; do
# this is most useless loop ever - if it partially fails, it'll never be
# able to recover anyways... but keeping it for some edge cases where it may help
while ! kubectl apply -f "${WORKING_DIR}/bmhosts_crs.yaml" -n "${namespace}" >/dev/null; do
sleep 3
done
echo "bmhosts_crs.yaml is successfully applied"
Expand Down Expand Up @@ -687,23 +691,24 @@ build_ipxe_firmware()

if [[ "${IPXE_ENABLE_TLS}" = "true" ]]; then
export IPXE_ENABLE_TLS_CENV_ARG="IPXE_ENABLE_TLS=true"
certs_mounts+=("-v ${IPXE_CACERT_FILE}:/certs/ca/ipxe/tls.crt")
certs_mounts+=("-v ${IPXE_CERT_FILE}:/certs/ipxe/tls.crt")
certs_mounts+=("-v ${IPXE_KEY_FILE}:/certs/ipxe/tls.key ")
certs_mounts+=(-v "${IPXE_CACERT_FILE}:/certs/ca/ipxe/tls.crt")
certs_mounts+=(-v "${IPXE_CERT_FILE}:/certs/ipxe/tls.crt")
certs_mounts+=(-v "${IPXE_KEY_FILE}:/certs/ipxe/tls.key")
fi

if [[ "${IPXE_ENABLE_IPV6}" = "true" ]]; then
export IPXE_ENABLE_IPV6_CENV_ARG="IPXE_ENABLE_IPV6=true"
fi

# shellcheck disable=SC2086,SC2068
# shellcheck disable=SC2086
sudo "${CONTAINER_RUNTIME}" run \
--net host \
--name ipxe-builder ${POD_NAME} \
--name ipxe-builder \
${POD_NAME} \
-e "${IPXE_ENABLE_TLS_CENV_ARG}" \
-e "${IPXE_ENABLE_IPV6_CENV_ARG}" \
-e "IRONIC_IP=${IRONIC_HOST_IP}" \
${certs_mounts[@]} \
"${certs_mounts[@]}" \
-v "${IRONIC_DATA_DIR}":/shared \
"${ipxe_builder_image}"
}
Expand Down Expand Up @@ -731,8 +736,8 @@ patch_clusterctl
launch_cluster_api_provider_metal3
BMO_NAME_PREFIX="${NAMEPREFIX}"
launch_baremetal_operator
launch_ironic_standalone_operator
if [[ "${USE_IRSO}" = true ]]; then
launch_ironic_standalone_operator
launch_ironic_via_irso
else
launch_ironic
Expand All @@ -757,7 +762,6 @@ if [[ "${SKIP_APPLY_BMH:-false}" = "true" ]]; then
list_nodes | make_bm_hosts
popd
else
# this is coming from lib/common.sh
# shellcheck disable=SC2153
apply_bm_hosts "${NAMESPACE}"
fi
Expand Down
Loading