Skip to content

Commit 01f0889

Browse files
authored
Merge pull request #501 from validatedpatterns/main
sync: main to rhdp-deploy
2 parents 68aba71 + 5d48e0e commit 01f0889

File tree

16 files changed

+202
-89
lines changed

16 files changed

+202
-89
lines changed

.github/workflows/ansible-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
persist-credentials: false
1616

1717
- name: Lint Ansible Playbook
18-
uses: ansible/ansible-lint@43e758bad47344f1ce7b699c0020299f486a8026
18+
uses: ansible/ansible-lint@7f6abc5ef97d0fb043a0f3d416dfbc74399fbda0

ansible.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[defaults]
22
localhost_warning=False
33
retry_files_enabled=False
4+
# Retry files disabled to avoid cluttering CI/CD environments
5+
interpreter_python=auto_silent
6+
timeout=30
47
library=~/.ansible/plugins/modules:./ansible/plugins/modules:./common/ansible/plugins/modules:/usr/share/ansible/plugins/modules
58
roles_path=~/.ansible/roles:./ansible/roles:./common/ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
69
filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:./common/ansible/plugins/filter:/usr/share/ansible/plugins/filter

ansible/site.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,31 @@
33
hosts: localhost
44
connection: local
55
tasks:
6+
- name: Verify pattern.sh exists
7+
ansible.builtin.stat:
8+
path: "{{ playbook_dir }}/../pattern.sh"
9+
register: pattern_script
10+
11+
- name: Fail if pattern.sh does not exist
12+
ansible.builtin.fail:
13+
msg: "pattern.sh not found at {{ playbook_dir }}/../pattern.sh"
14+
when: not pattern_script.stat.exists
15+
616
# We cannot use .package or .dnf modules because python3 that is used comes
717
# from a virtualenv
818
- name: Launch the installation
919
ansible.builtin.command: ./pattern.sh make install
1020
args:
11-
chdir: "{{ lookup('env', 'PWD') }}"
21+
chdir: "{{ playbook_dir }}/.."
1222
register: output
13-
changed_when: false
23+
changed_when: output.rc == 0
24+
failed_when: output.rc != 0
1425

1526
- name: Print output of installation
1627
ansible.builtin.debug:
17-
msg: "{{ output }}"
28+
msg: "{{ output.stdout_lines }}"
29+
30+
- name: Print errors if any
31+
ansible.builtin.debug:
32+
msg: "{{ output.stderr_lines }}"
33+
when: output.stderr_lines | length > 0

charts/all/config-demo/templates/config-demo-deployment.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ spec:
1212
deploymentconfig: config-demo
1313
template:
1414
metadata:
15-
creationTimestamp: null
1615
labels:
1716
app: config-demo
1817
deploymentconfig: config-demo
@@ -24,8 +23,8 @@ spec:
2423
type: RuntimeDefault
2524
containers:
2625
- name: apache
27-
image: registry.access.redhat.com/ubi10/httpd-24:10.0-1755779646
28-
#imagePullPolicy: Always
26+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
27+
imagePullPolicy: {{ .Values.image.pullPolicy }}
2928
ports:
3029
- containerPort: 8080
3130
name: http

charts/all/config-demo/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ global:
1313

1414
clusterGroup:
1515
isHubCluster: true
16+
17+
image:
18+
repository: registry.access.redhat.com/ubi10/httpd-24
19+
tag: "10.0-1755779646"
20+
pullPolicy: IfNotPresent

charts/all/hello-world/templates/hello-world-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ spec:
2323
type: RuntimeDefault
2424
containers:
2525
- name: apache
26-
image: registry.access.redhat.com/ubi10/httpd-24:10.0-1755779646
27-
#imagePullPolicy: Always
26+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
27+
imagePullPolicy: {{ .Values.image.pullPolicy }}
2828
ports:
2929
- containerPort: 8080
3030
name: http

charts/all/hello-world/values.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
---
22
global:
33
hubClusterDomain: hub.example.com
4-
localCluster: local.example.com
4+
localClusterDomain: local.example.com
5+
6+
image:
7+
repository: registry.access.redhat.com/ubi10/httpd-24
8+
tag: "10.0-1755779646"
9+
pullPolicy: IfNotPresent

overrides/values-AWS.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# to enable letsencrypt certificates on API endpoint and default
33
# ingress of the cluster
44
# It is currently very experimental and unsupported.
5-
# PLEASE read https://github.com/hybrid-cloud-patterns/common/tree/main/letsencrypt#readme
5+
# PLEASE read https://github.com/validatedpatterns/common/tree/main/letsencrypt#readme
66
# for all the limitations around it
77

88

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+
"$@"

tests/interop/create_ci_badge.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import json
22
import os
33
import subprocess
4+
import sys
45
from datetime import datetime
56

67
from junitparser import JUnitXml
78

8-
oc = os.environ["HOME"] + "/oc_client/oc"
9+
# Use os.environ.get() with fallback to avoid KeyError
10+
home_dir = os.environ.get("HOME", "/tmp")
11+
oc = os.path.join(home_dir, "oc_client", "oc")
912

1013
ci_badge = {
1114
"schemaVersion": 1,
@@ -24,19 +27,34 @@
2427

2528

2629
def get_openshift_version():
30+
"""Get OpenShift version from cluster.
31+
32+
Returns:
33+
tuple: (full_version, major_minor) on success
34+
None: on any error
35+
"""
2736
try:
28-
version_ret = subprocess.run([oc, "version", "-o", "json"], capture_output=True)
37+
version_ret = subprocess.run(
38+
[oc, "version", "-o", "json"], capture_output=True, check=False
39+
)
40+
if version_ret.returncode != 0:
41+
print(f"Error running oc version: {version_ret.stderr.decode('utf-8')}")
42+
return None
2943
version_out = version_ret.stdout.decode("utf-8")
3044
openshift_version = json.loads(version_out)["openshiftVersion"]
3145
major_minor = ".".join(openshift_version.split(".")[:-1])
3246
return openshift_version, major_minor
33-
except KeyError as e:
34-
print("KeyError:" + str(e))
47+
except (KeyError, json.JSONDecodeError, UnicodeDecodeError, OSError) as e:
48+
print(f"Error getting OpenShift version: {type(e).__name__}: {e}")
3549
return None
3650

3751

3852
if __name__ == "__main__":
3953
versions = get_openshift_version()
54+
if versions is None:
55+
print("Failed to get OpenShift version, exiting")
56+
sys.exit(1)
57+
4058
ci_badge["openshiftVersion"] = versions[0]
4159

4260
pattern_repo = subprocess.run(
@@ -51,12 +69,20 @@ def get_openshift_version():
5169

5270
# Check each xml file for failures
5371
results_dir = os.environ.get("WORKSPACE")
72+
if results_dir is None:
73+
print("WORKSPACE environment variable is not set, exiting")
74+
sys.exit(1)
75+
76+
if not os.path.isdir(results_dir):
77+
print(f"WORKSPACE directory does not exist: {results_dir}")
78+
sys.exit(1)
79+
5480
failures = 0
5581

5682
for file in os.listdir(results_dir):
5783
if file.startswith("test_") and file.endswith(".xml"):
58-
with open(os.path.join(results_dir, file), "r") as result_file: # type: ignore
59-
xml = JUnitXml.fromfile(result_file) # type: ignore
84+
with open(os.path.join(results_dir, file), "r") as result_file:
85+
xml = JUnitXml.fromfile(result_file)
6086
for suite in xml:
6187
for case in suite:
6288
if case.result:
@@ -69,15 +95,26 @@ def get_openshift_version():
6995
# For now we assume `message` is the same as patternBranch
7096
ci_badge["message"] = ci_badge["patternBranch"]
7197

98+
# Validate required environment variables for filename
99+
pattern_shortname = os.environ.get("PATTERN_SHORTNAME")
100+
infra_provider = os.environ.get("INFRA_PROVIDER")
101+
102+
if not pattern_shortname:
103+
print("PATTERN_SHORTNAME environment variable is not set, exiting")
104+
sys.exit(1)
105+
if not infra_provider:
106+
print("INFRA_PROVIDER environment variable is not set, exiting")
107+
sys.exit(1)
108+
72109
ci_badge_json_basename = (
73-
os.environ.get("PATTERN_SHORTNAME") # type: ignore
110+
pattern_shortname
74111
+ "-"
75-
+ os.environ.get("INFRA_PROVIDER")
112+
+ infra_provider
76113
+ "-"
77114
+ versions[1]
78115
+ "-stable-badge.json"
79116
)
80-
ci_badge_json_filename = os.path.join(results_dir, ci_badge_json_basename) # type: ignore
117+
ci_badge_json_filename = os.path.join(results_dir, ci_badge_json_basename)
81118
print(f"Creating CI badge file at: {ci_badge_json_filename}")
82119

83120
with open(ci_badge_json_filename, "w") as ci_badge_file:

0 commit comments

Comments
 (0)