Skip to content

Commit 6eeed58

Browse files
authored
Merge pull request #131 from dminnear-rh/common-automatic-update
Common automatic update
2 parents a050428 + b61ecc3 commit 6eeed58

11 files changed

+98
-26
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Run Bash Script on Multiple Distributions
2+
3+
on:
4+
push:
5+
paths:
6+
- "scripts/**"
7+
- "Makefile"
8+
branches:
9+
- main
10+
pull_request:
11+
paths:
12+
- "scripts/**"
13+
- "Makefile"
14+
15+
jobs:
16+
run-script:
17+
name: Run Bash Script
18+
strategy:
19+
matrix:
20+
# Fedora is not an option yet
21+
os: [ubuntu-latest, ubuntu-22.04]
22+
runs-on: ${{ matrix.os }}
23+
24+
steps:
25+
- name: Checkout Repository
26+
uses: actions/checkout@v4
27+
28+
- name: Install Podman on Ubuntu
29+
if: contains(matrix.os, 'ubuntu')
30+
run: |
31+
sudo apt-get update
32+
sudo apt-get install -y podman
33+
34+
# Currently we do not do MacOSX as it is not free, maybe in the future
35+
# - name: Install Podman on macOS
36+
# if: contains(matrix.os, 'macos')
37+
# run: |
38+
# brew install podman
39+
# podman machine init
40+
# podman machine start
41+
42+
- name: Verify Podman Installation
43+
run: podman --version
44+
45+
- name: Run pattern.sh script
46+
run: |
47+
export TARGET_BRANCH=main
48+
./scripts/pattern-util.sh make validate-origin

common/Makefile

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ endif
88
# the command line. I.e. we can set things without having to tweak values files
99
EXTRA_HELM_OPTS ?=
1010

11+
# This variable can be set in order to pass additional ansible-playbook arguments from the
12+
# the command line. I.e. we can set -vvv for more verbose logging
13+
EXTRA_PLAYBOOK_OPTS ?=
14+
1115
# INDEX_IMAGES=registry-proxy.engineering.redhat.com/rh-osbs/iib:394248
1216
# or
1317
# INDEX_IMAGES=registry-proxy.engineering.redhat.com/rh-osbs/iib:394248,registry-proxy.engineering.redhat.com/rh-osbs/iib:394249
@@ -18,7 +22,7 @@ TARGET_ORIGIN ?= origin
1822
# This is because we expect to use tokens for repo authentication as opposed to SSH keys
1923
TARGET_REPO=$(shell git ls-remote --get-url --symref $(TARGET_ORIGIN) | sed -e 's/.*URL:[[:space:]]*//' -e 's%^git@%%' -e 's%^https://%%' -e 's%:%/%' -e 's%^%https://%')
2024
# git branch --show-current is also available as of git 2.22, but we will use this for compatibility
21-
TARGET_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
25+
TARGET_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
2226

2327
UUID_FILE ?= ~/.config/validated-patterns/pattern-uuid
2428
UUID_HELM_OPTS ?=
@@ -111,7 +115,7 @@ secrets-backend-none: ## Edits values files to remove secrets manager + ESO
111115
.PHONY: load-iib
112116
load-iib: ## CI target to install Index Image Bundles
113117
@set -e; if [ x$(INDEX_IMAGES) != x ]; then \
114-
ansible-playbook rhvp.cluster_utils.iib_ci; \
118+
ansible-playbook $(EXTRA_PLAYBOOK_OPTS) rhvp.cluster_utils.iib_ci; \
115119
else \
116120
echo "No INDEX_IMAGES defined. Bailing out"; \
117121
exit 1; \
@@ -159,15 +163,20 @@ validate-cluster: ## Do some cluster validations before installing
159163
validate-schema: ## validates values files against schema in common/clustergroup
160164
$(eval VAL_PARAMS := $(shell for i in ./values-*.yaml; do echo -n "$${i} "; done))
161165
@echo -n "Validating clustergroup schema of: "
162-
@set -e; for i in $(VAL_PARAMS); do echo -n " $$i"; helm template common/clustergroup $(HELM_OPTS) -f "$${i}" >/dev/null; done
166+
@set -e; for i in $(VAL_PARAMS); do echo -n " $$i"; helm template oci://quay.io/hybridcloudpatterns/clustergroup $(HELM_OPTS) -f "$${i}" >/dev/null; done
163167
@echo
164168

165169
.PHONY: validate-prereq
166170
validate-prereq: ## verify pre-requisites
171+
$(eval GLOBAL_PATTERN := $(shell yq -r .global.pattern values-global.yaml))
172+
@if [ $(NAME) != $(GLOBAL_PATTERN) ]; then\
173+
echo "";\
174+
echo "WARNING: folder directory is \"$(NAME)\" and global.pattern is set to \"$(GLOBAL_PATTERN)\"";\
175+
echo "this can create problems. Please make sure they are the same!";\
176+
echo "";\
177+
fi
167178
@if [ ! -f /run/.containerenv ]; then\
168179
echo "Checking prerequisites:";\
169-
for t in $(EXECUTABLES); do if ! which $$t > /dev/null 2>&1; then echo "No $$t in PATH"; exit 1; fi; done;\
170-
echo " Check for '$(EXECUTABLES)': OK";\
171180
echo -n " Check for python-kubernetes: ";\
172181
if ! ansible -m ansible.builtin.command -a "{{ ansible_python_interpreter }} -c 'import kubernetes'" localhost > /dev/null 2>&1; then echo "Not found"; exit 1; fi;\
173182
echo "OK";\
@@ -188,16 +197,16 @@ validate-prereq: ## verify pre-requisites
188197
.PHONY: argo-healthcheck
189198
argo-healthcheck: ## Checks if all argo applications are synced
190199
@echo "Checking argo applications"
191-
$(eval APPS := $(shell oc get applications -A -o jsonpath='{range .items[*]}{@.metadata.namespace}{","}{@.metadata.name}{"\n"}{end}'))
200+
$(eval APPS := $(shell oc get applications.argoproj.io -A -o jsonpath='{range .items[*]}{@.metadata.namespace}{","}{@.metadata.name}{"\n"}{end}'))
192201
@NOTOK=0; \
193202
for i in $(APPS); do\
194203
n=`echo "$${i}" | cut -f1 -d,`;\
195204
a=`echo "$${i}" | cut -f2 -d,`;\
196-
STATUS=`oc get -n "$${n}" application/"$${a}" -o jsonpath='{.status.sync.status}'`;\
205+
STATUS=`oc get -n "$${n}" applications.argoproj.io/"$${a}" -o jsonpath='{.status.sync.status}'`;\
197206
if [[ $$STATUS != "Synced" ]]; then\
198207
NOTOK=$$(( $${NOTOK} + 1));\
199208
fi;\
200-
HEALTH=`oc get -n "$${n}" application/"$${a}" -o jsonpath='{.status.health.status}'`;\
209+
HEALTH=`oc get -n "$${n}" applications.argoproj.io/"$${a}" -o jsonpath='{.status.health.status}'`;\
201210
if [[ $$HEALTH != "Healthy" ]]; then\
202211
NOTOK=$$(( $${NOTOK} + 1));\
203212
fi;\
@@ -214,7 +223,7 @@ argo-healthcheck: ## Checks if all argo applications are synced
214223
.PHONY: qe-tests
215224
qe-tests: ## Runs the tests that QE runs
216225
@set -e; if [ -f ./tests/interop/run_tests.sh ]; then \
217-
./tests/interop/run_tests.sh; \
226+
pushd ./tests/interop; ./run_tests.sh; popd; \
218227
else \
219228
echo "No ./tests/interop/run_tests.sh found skipping"; \
220229
fi

common/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ main:
3434
## Start Here
3535
3636
This repository is never used as standalone. It is usually imported in each pattern as a subtree.
37-
In order to import the common/ the very first time you can use
38-
`https://github.com/validatedpatterns/multicloud-gitops/blob/main/common/scripts/make_common_subtree.sh`
37+
In order to import the common subtree the very first time you can use the script
38+
[make_common_subtree.sh](scripts/make-common-subtree.sh).
3939
4040
In order to update your common subtree inside your pattern repository you can either use
4141
`https://github.com/validatedpatterns/utilities/blob/main/scripts/update-common-everywhere.sh` or
42-
do it manually by doing the following:
42+
do it manually with the following commands:
4343

4444
```sh
45-
git remote add -f upstream-common https://github.com/validatedpatterns/common.git
46-
git merge -s subtree -Xtheirs -Xsubtree=common upstream-common/main
45+
git remote add -f common-upstream https://github.com/validatedpatterns/common.git
46+
git merge -s subtree -Xtheirs -Xsubtree=common common-upstream/main
4747
```
4848

4949
## Secrets

common/scripts/deploy-pattern.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
set -o pipefail
33

4-
RUNS=5
4+
RUNS=10
5+
WAIT=15
56
# Retry five times because the CRD might not be fully installed yet
67
echo -n "Installing pattern: "
78
for i in $(seq 1 ${RUNS}); do \
@@ -13,7 +14,7 @@ for i in $(seq 1 ${RUNS}); do \
1314
break;
1415
else
1516
echo -n "."
16-
sleep 10
17+
sleep "${WAIT}"
1718
fi
1819
done
1920

common/scripts/display-secrets-info.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ fi
2323

2424
PATTERN_NAME=$(basename "`pwd`")
2525

26-
ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" -e secrets_backing_store="${SECRETS_BACKING_STORE}" -e override_no_log=false "rhvp.cluster_utils.display_secrets_info"
26+
EXTRA_PLAYBOOK_OPTS="${EXTRA_PLAYBOOK_OPTS:-}"
27+
28+
ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" -e secrets_backing_store="${SECRETS_BACKING_STORE}" -e hide_sensitive_output=false ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.display_secrets_info"

common/scripts/load-k8s-secrets.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ PATTERNPATH=$(dirname "${COMMONPATH}")
1313

1414
PATTERN_NAME=${1:-$(basename "`pwd`")}
1515

16-
ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" "rhvp.cluster_utils.k8s_secrets"
16+
EXTRA_PLAYBOOK_OPTS="${EXTRA_PLAYBOOK_OPTS:-}"
17+
18+
ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.k8s_secrets"

common/scripts/make_common_subtree.sh renamed to common/scripts/make-common-subtree.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ "$1" = "-h" ]; then
77
echo "$0 <subtree_repo> <subtree_branch> <subtree_remote_name>"
88
echo
99
echo "Run without arguments, the script would run as if these arguments had been passed:"
10-
echo "$0 https://github.com/hybrid-cloud-patterns/common.git main common-subtree"
10+
echo "$0 https://github.com/validatedpatterns/common.git main common-upstream"
1111
echo
1212
echo "Please ensure the git subtree command is available. On RHEL/Fedora, the git subtree command"
1313
echo "is in a separate package called git-subtree"
@@ -41,7 +41,7 @@ fi
4141
if [ "$1" ]; then
4242
subtree_repo=$1
4343
else
44-
subtree_repo=https://github.com/hybrid-cloud-patterns/common.git
44+
subtree_repo=https://github.com/validatedpatterns/common.git
4545
fi
4646

4747
if [ "$2" ]; then
@@ -53,7 +53,7 @@ fi
5353
if [ "$3" ]; then
5454
subtree_remote=$3
5555
else
56-
subtree_remote=common-subtree
56+
subtree_remote=common-upstream
5757
fi
5858

5959
git diff --quiet || (echo "This script must be run on a clean working tree" && exit 1)

common/scripts/pattern-util.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ fi
6464
# if we are using podman machine then we do not bind mount anything (for now!)
6565
REMOTE_PODMAN=$(podman system connection list -q | wc -l)
6666
if [ $REMOTE_PODMAN -eq 0 ]; then # If we are not using podman machine we check the hosts folders
67-
# Use /etc/pki by default and try a couple of fallbacks if it does not exist
68-
if [ -d /etc/pki ]; then
67+
# We check /etc/pki/tls because on ubuntu /etc/pki/fwupd sometimes
68+
# exists but not /etc/pki/tls and we do not want to bind mount in such a case
69+
# as it would find no certificates at all.
70+
if [ -d /etc/pki/tls ]; then
6971
PKI_HOST_MOUNT_ARGS="-v /etc/pki:/etc/pki:ro"
7072
elif [ -d /etc/ssl ]; then
7173
PKI_HOST_MOUNT_ARGS="-v /etc/ssl:/etc/ssl:ro"
@@ -85,6 +87,8 @@ podman run -it --rm --pull=newer \
8587
-e EXTRA_HELM_OPTS \
8688
-e EXTRA_PLAYBOOK_OPTS \
8789
-e TARGET_ORIGIN \
90+
-e TARGET_SITE \
91+
-e TARGET_BRANCH \
8892
-e NAME \
8993
-e TOKEN_SECRET \
9094
-e TOKEN_NAMESPACE \

common/scripts/process-secrets.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ PATTERNPATH=$(dirname "${COMMONPATH}")
1414
PATTERN_NAME=${1:-$(basename "`pwd`")}
1515
SECRETS_BACKING_STORE="$($SCRIPTPATH/determine-secretstore-backend.sh)"
1616

17-
ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" -e secrets_backing_store="${SECRETS_BACKING_STORE}" "rhvp.cluster_utils.process_secrets"
17+
EXTRA_PLAYBOOK_OPTS="${EXTRA_PLAYBOOK_OPTS:-}"
18+
19+
ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" -e secrets_backing_store="${SECRETS_BACKING_STORE}" ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.process_secrets"

common/scripts/vault-utils.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ if [ -z ${TASK} ]; then
2525
exit 1
2626
fi
2727

28-
ansible-playbook -t "${TASK}" -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" "rhvp.cluster_utils.vault"
28+
EXTRA_PLAYBOOK_OPTS="${EXTRA_PLAYBOOK_OPTS:-}"
29+
30+
ansible-playbook -t "${TASK}" -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.vault"

common/scripts/write-token-kubeconfig.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ SCRIPTPATH=$(dirname "${SCRIPT}")
1313
COMMONPATH=$(dirname "${SCRIPTPATH}")
1414
PATTERNPATH=$(dirname "${COMMONPATH}")
1515

16-
ansible-playbook -e pattern_dir="${PATTERNPATH}" -e kubeconfig_file="${OUTPUTFILE}" "rhvp.cluster_utils.write-token-kubeconfig"
16+
EXTRA_PLAYBOOK_OPTS="${EXTRA_PLAYBOOK_OPTS:-}"
17+
18+
ansible-playbook -e pattern_dir="${PATTERNPATH}" -e kubeconfig_file="${OUTPUTFILE}" ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.write-token-kubeconfig"

0 commit comments

Comments
 (0)