Skip to content

Commit b18ba56

Browse files
committed
chore: update pattern infrastructure to upstream patternizer
Sync pattern.sh and Makefile-common with upstream reference from: https://github.com/validatedpatterns/patternizer/tree/main/resources pattern.sh changes (full replacement): - Add set -euo pipefail strict mode for fail-fast behavior - Convert PODMAN_ARGS, PKI_HOST_MOUNT_ARGS, EXTRA_ARGS from strings to bash arrays - Add :- defaults on all env var checks for set -u compatibility - Fix KUBECONFIG regex: ^/Users/chbutler* → ^"${HOME}" (was matching wrong char) - Add error handling fallbacks for podman --version and podman system connection list - Quote all variable expansions throughout - Use "$1" instead of "$@" in version() function Makefile-common changes: - Change ANSIBLE_STDOUT_CALLBACK default from null to rhvp.cluster_utils.readable - Change ANSIBLE_RUN from := to ?= to allow environment override - Replace stub uninstall target with experimental implementation (calls rhvp.cluster_utils.uninstall playbook) Improves robustness, maintainability, and alignment with VP framework best practices.
1 parent 1c8287f commit b18ba56

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

Makefile-common

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MAKEFLAGS += --no-print-directory
2-
ANSIBLE_STDOUT_CALLBACK ?= null # null silences all ansible output. Override this with default, minimal, oneline, etc. when debugging.
3-
ANSIBLE_RUN := ANSIBLE_STDOUT_CALLBACK=$(ANSIBLE_STDOUT_CALLBACK) ansible-playbook $(EXTRA_PLAYBOOK_OPTS)
2+
ANSIBLE_STDOUT_CALLBACK ?= rhvp.cluster_utils.readable
3+
ANSIBLE_RUN ?= ANSIBLE_STDOUT_CALLBACK=$(ANSIBLE_STDOUT_CALLBACK) ansible-playbook $(EXTRA_PLAYBOOK_OPTS)
44
DOCS_URL := https://validatedpatterns.io/blog/2025-08-29-new-common-makefile-structure/
55

66
.PHONY: help
@@ -20,9 +20,9 @@ operator-deploy operator-upgrade: ## Installs/updates the pattern on a cluster (
2020
.PHONY: install
2121
install: pattern-install ## Installs the pattern onto a cluster (Loads secrets as well if configured)
2222

23-
.PHONY: uninstall ## Prints a notice that patterns cannot currently be uninstalled
24-
uninstall:
25-
@echo "Uninstall is not possible at the moment so this target is empty. We are working to implement it as well as we can."
23+
.PHONY: uninstall
24+
uninstall: ## (EXPERIMENTAL) See https://validatedpatterns.io/blog/2026-02-16-pattern-uninstall/.
25+
@$(ANSIBLE_RUN) rhvp.cluster_utils.uninstall
2626

2727
.PHONY: pattern-install
2828
pattern-install:

pattern.sh

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
function is_available {
4-
command -v $1 >/dev/null 2>&1 || { echo >&2 "$1 is required but it's not installed. Aborting."; exit 1; }
5+
command -v "$1" >/dev/null 2>&1 || { echo >&2 "$1 is required but it's not installed. Aborting."; exit 1; }
56
}
67

78
function version {
8-
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
9+
echo "$1" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
910
}
1011

11-
if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
12+
if [ -z "${PATTERN_UTILITY_CONTAINER:-}" ]; then
1213
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
1314
fi
1415
# If PATTERN_DISCONNECTED_HOME is set it will be used to populate both PATTERN_UTILITY_CONTAINER
1516
# and PATTERN_INSTALL_CHART automatically
16-
if [ -n "${PATTERN_DISCONNECTED_HOME}" ]; then
17+
if [ -n "${PATTERN_DISCONNECTED_HOME:-}" ]; then
1718
PATTERN_UTILITY_CONTAINER="${PATTERN_DISCONNECTED_HOME}/utility-container"
1819
PATTERN_INSTALL_CHART="oci://${PATTERN_DISCONNECTED_HOME}/pattern-install"
1920
echo "PATTERN_DISCONNECTED_HOME is set to ${PATTERN_DISCONNECTED_HOME}"
@@ -23,10 +24,10 @@ if [ -n "${PATTERN_DISCONNECTED_HOME}" ]; then
2324
fi
2425

2526
readonly commands=(podman)
26-
for cmd in ${commands[@]}; do is_available "$cmd"; done
27+
for cmd in "${commands[@]}"; do is_available "$cmd"; done
2728

2829
UNSUPPORTED_PODMAN_VERSIONS="1.6 1.5"
29-
PODMAN_VERSION_STR=$(podman --version)
30+
PODMAN_VERSION_STR=$(podman --version) || { echo "Failed to get podman version"; exit 1; }
3031
for i in ${UNSUPPORTED_PODMAN_VERSIONS}; do
3132
# We add a space
3233
if echo "${PODMAN_VERSION_STR}" | grep -q -E "\b${i}"; then
@@ -41,19 +42,20 @@ done
4142
PODMAN_VERSION=$(echo "${PODMAN_VERSION_STR}" | awk '{ print $NF }')
4243

4344
# podman < 4.3.0 do not support keep-id:uid=...
44-
if [ $(version "${PODMAN_VERSION}") -lt $(version "4.3.0") ]; then
45-
PODMAN_ARGS="-v ${HOME}:/root"
45+
PODMAN_ARGS=()
46+
if [ "$(version "${PODMAN_VERSION}")" -lt "$(version "4.3.0")" ]; then
47+
PODMAN_ARGS=(-v "${HOME}:/root")
4648
else
4749
# We do not rely on bash's $UID and $GID because on MacOSX $GID is not set
4850
MYNAME=$(id -n -u)
4951
MYUID=$(id -u)
5052
MYGID=$(id -g)
51-
PODMAN_ARGS="--passwd-entry ${MYNAME}:x:${MYUID}:${MYGID}::/pattern-home:/bin/bash --user ${MYUID}:${MYGID} --userns keep-id:uid=${MYUID},gid=${MYGID}"
52-
53+
PODMAN_ARGS=(--passwd-entry "${MYNAME}:x:${MYUID}:${MYGID}::/pattern-home:/bin/bash" --user "${MYUID}:${MYGID}" --userns "keep-id:uid=${MYUID},gid=${MYGID}")
5354
fi
5455

55-
if [ -n "$KUBECONFIG" ]; then
56-
if [[ ! "${KUBECONFIG}" =~ ^$HOME* ]]; then
56+
if [ -n "${KUBECONFIG:-}" ]; then
57+
# Check if KUBECONFIG path starts with HOME directory
58+
if [[ ! "${KUBECONFIG}" =~ ^"${HOME}" ]]; then
5759
echo "${KUBECONFIG} is pointing outside of the HOME folder, this will make it unavailable from the container."
5860
echo "Please move it somewhere inside your $HOME folder, as that is what gets bind-mounted inside the container"
5961
exit 1
@@ -62,20 +64,26 @@ fi
6264

6365
# Detect if we use podman machine. If we do not then we bind mount local host ssl folders
6466
# if we are using podman machine then we do not bind mount anything (for now!)
65-
REMOTE_PODMAN=$(podman system connection list | tail -n +2 | wc -l)
66-
if [ $REMOTE_PODMAN -eq 0 ]; then # If we are not using podman machine we check the hosts folders
67+
REMOTE_PODMAN=$(podman system connection list | tail -n +2 | wc -l) || REMOTE_PODMAN=0
68+
PKI_HOST_MOUNT_ARGS=()
69+
if [ "${REMOTE_PODMAN}" -eq 0 ]; then # If we are not using podman machine we check the hosts folders
6770
# We check /etc/pki/tls because on ubuntu /etc/pki/fwupd sometimes
6871
# exists but not /etc/pki/tls and we do not want to bind mount in such a case
6972
# as it would find no certificates at all.
7073
if [ -d /etc/pki/tls ]; then
71-
PKI_HOST_MOUNT_ARGS="-v /etc/pki:/etc/pki:ro"
74+
PKI_HOST_MOUNT_ARGS=(-v /etc/pki:/etc/pki:ro)
7275
elif [ -d /etc/ssl ]; then
73-
PKI_HOST_MOUNT_ARGS="-v /etc/ssl:/etc/ssl:ro"
76+
PKI_HOST_MOUNT_ARGS=(-v /etc/ssl:/etc/ssl:ro)
7477
else
75-
PKI_HOST_MOUNT_ARGS="-v /usr/share/ca-certificates:/usr/share/ca-certificates:ro"
78+
PKI_HOST_MOUNT_ARGS=(-v /usr/share/ca-certificates:/usr/share/ca-certificates:ro)
7679
fi
77-
else
78-
PKI_HOST_MOUNT_ARGS=""
80+
fi
81+
82+
# Parse EXTRA_ARGS into an array if set
83+
EXTRA_ARGS_ARRAY=()
84+
if [ -n "${EXTRA_ARGS:-}" ]; then
85+
# shellcheck disable=SC2206
86+
EXTRA_ARGS_ARRAY=(${EXTRA_ARGS})
7987
fi
8088

8189
# Copy Kubeconfig from current environment. The utilities will pick up ~/.kube/config if set so it's not mandatory
@@ -106,12 +114,12 @@ podman run -it --rm --pull=newer \
106114
-e TOKEN_SECRET \
107115
-e UUID_FILE \
108116
-e VALUES_SECRET \
109-
${PKI_HOST_MOUNT_ARGS} \
117+
"${PKI_HOST_MOUNT_ARGS[@]}" \
110118
-v "$(pwd -P)":"$(pwd -P)" \
111119
-v "${HOME}":"${HOME}" \
112120
-v "${HOME}":/pattern-home \
113-
${PODMAN_ARGS} \
114-
${EXTRA_ARGS} \
121+
"${PODMAN_ARGS[@]}" \
122+
"${EXTRA_ARGS_ARRAY[@]}" \
115123
-w "$(pwd -P)" \
116124
"$PATTERN_UTILITY_CONTAINER" \
117-
$@
125+
"$@"

0 commit comments

Comments
 (0)