Skip to content

Commit

Permalink
Add support for transactional-update based systems (#105)
Browse files Browse the repository at this point in the history
I've introduced support for systems that utilise transactional-update,
e.g. SLE Micro, openSUSE Leap Micro, and openSUSE MicroOS. On these
systems the filesystem is either read-only, or is snapshot based, which
means that the original install locations for CATTLE_AGENT_BIN_PREFIX
and CATTLE_AGENT_VAR_DIR are not typically writeable, depending on
whether transactional-update is being called.

This patch checks to see whether the system is using
transactional-update and if so, adapts the install locations and/or
calls transactional-update to make the appropriate changes.

This patch set supports both manually executing the script, i.e. a
Rancher "custom" installation, and initiating the deployment via
ignition/combustion (where transactional-update is called
automatically).
  • Loading branch information
rdoxenham authored Apr 19, 2023
1 parent e57338e commit 09a4516
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ check_target_ro() {
test $? -ne 0
}

# check_rootfs_rw returns success if the root filesystem is read-write so we can check for transactional-update system
check_rootfs_rw() {
touch /.rootfs-rw-test && rm -rf /.rootfs-rw-test
test $? -eq 0
}

# parse_args will inspect the argv for --server, --token, --controlplane, --etcd, and --worker, --label x=y, and --taint dead=beef:NoSchedule
parse_args() {
while [ $# -gt 0 ]; do
Expand Down Expand Up @@ -388,19 +394,31 @@ setup_env() {
info "Using default agent configuration directory ${CATTLE_AGENT_CONFIG_DIR}"
fi

# --- install to /var/lib/rancher/agent by default, except if we are running within transactional-update
# --- in which case we install into /etc/rancher/agent/var as /var is not mounted to the snapshot.
if [ -z "${CATTLE_AGENT_VAR_DIR}" ]; then
CATTLE_AGENT_VAR_DIR=/var/lib/rancher/agent
info "Using default agent var directory ${CATTLE_AGENT_VAR_DIR}"
if [ -x /usr/sbin/transactional-update ] && check_rootfs_rw; then
CATTLE_AGENT_VAR_DIR=/etc/rancher/agent/var
info "Detected a transactional-update server, using ${CATTLE_AGENT_VAR_DIR} for agent var directory"
else
CATTLE_AGENT_VAR_DIR=/var/lib/rancher/agent
info "Using default agent var directory ${CATTLE_AGENT_VAR_DIR}"
fi
fi

# --- install to /usr/local by default, except if /usr/local is on a separate partition or is read-only
# --- in which case we go into /opt/rancher-system-agent.
# --- in which case we go into /opt/rancher-system-agent. If we are running within transactional-update
# --- we install to /usr as /usr/local and /opt are not mounted to the snapshot.
if [ -z "${CATTLE_AGENT_BIN_PREFIX}" ]; then
CATTLE_AGENT_BIN_PREFIX="/usr/local"
if check_target_mountpoint || check_target_ro; then
CATTLE_AGENT_BIN_PREFIX="/opt/rancher-system-agent"
warn "/usr/local is read-only or a mount point; installing to ${CATTLE_AGENT_BIN_PREFIX}"
fi
if [ -x /usr/sbin/transactional-update ] && check_rootfs_rw; then
CATTLE_AGENT_BIN_PREFIX=/usr
warn "Detected transactional-update in progress; installing to ${CATTLE_AGENT_BIN_PREFIX}"
fi
fi

CATTLE_ADDRESS=$(get_address "${CATTLE_ADDRESS}")
Expand Down

0 comments on commit 09a4516

Please sign in to comment.