Skip to content

Commit

Permalink
cleanup and reformat bash syntax in 04 script
Browse files Browse the repository at this point in the history
Cleanup and reforamt bash syntax in 04 script. Also requires fixes
to lib/common.sh, but to keep PR contained, I rather took out the
utility functions and put them in new lib/utils.sh.

Also, fixed some leftover issues I missed first time around in 01, 02
and 03 scripts for consistency.

Signed-off-by: Tuomo Tanskanen <[email protected]>
  • Loading branch information
tuminoid committed Dec 11, 2024
1 parent 887b5b6 commit 3984b9b
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 444 deletions.
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
24 changes: 13 additions & 11 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
Loading

0 comments on commit 3984b9b

Please sign in to comment.