Skip to content

Commit

Permalink
Merge pull request #131 from dminnear-rh/common-automatic-update
Browse files Browse the repository at this point in the history
Common automatic update
  • Loading branch information
mbaldessari authored Feb 27, 2025
2 parents a050428 + b61ecc3 commit 6eeed58
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 26 deletions.
48 changes: 48 additions & 0 deletions common/.github/workflows/pattern-sh-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run Bash Script on Multiple Distributions

on:
push:
paths:
- "scripts/**"
- "Makefile"
branches:
- main
pull_request:
paths:
- "scripts/**"
- "Makefile"

jobs:
run-script:
name: Run Bash Script
strategy:
matrix:
# Fedora is not an option yet
os: [ubuntu-latest, ubuntu-22.04]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Podman on Ubuntu
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y podman
# Currently we do not do MacOSX as it is not free, maybe in the future
# - name: Install Podman on macOS
# if: contains(matrix.os, 'macos')
# run: |
# brew install podman
# podman machine init
# podman machine start

- name: Verify Podman Installation
run: podman --version

- name: Run pattern.sh script
run: |
export TARGET_BRANCH=main
./scripts/pattern-util.sh make validate-origin
27 changes: 18 additions & 9 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ endif
# the command line. I.e. we can set things without having to tweak values files
EXTRA_HELM_OPTS ?=

# This variable can be set in order to pass additional ansible-playbook arguments from the
# the command line. I.e. we can set -vvv for more verbose logging
EXTRA_PLAYBOOK_OPTS ?=

# INDEX_IMAGES=registry-proxy.engineering.redhat.com/rh-osbs/iib:394248
# or
# INDEX_IMAGES=registry-proxy.engineering.redhat.com/rh-osbs/iib:394248,registry-proxy.engineering.redhat.com/rh-osbs/iib:394249
Expand All @@ -18,7 +22,7 @@ TARGET_ORIGIN ?= origin
# This is because we expect to use tokens for repo authentication as opposed to SSH keys
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://%')
# git branch --show-current is also available as of git 2.22, but we will use this for compatibility
TARGET_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TARGET_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

UUID_FILE ?= ~/.config/validated-patterns/pattern-uuid
UUID_HELM_OPTS ?=
Expand Down Expand Up @@ -111,7 +115,7 @@ secrets-backend-none: ## Edits values files to remove secrets manager + ESO
.PHONY: load-iib
load-iib: ## CI target to install Index Image Bundles
@set -e; if [ x$(INDEX_IMAGES) != x ]; then \
ansible-playbook rhvp.cluster_utils.iib_ci; \
ansible-playbook $(EXTRA_PLAYBOOK_OPTS) rhvp.cluster_utils.iib_ci; \
else \
echo "No INDEX_IMAGES defined. Bailing out"; \
exit 1; \
Expand Down Expand Up @@ -159,15 +163,20 @@ validate-cluster: ## Do some cluster validations before installing
validate-schema: ## validates values files against schema in common/clustergroup
$(eval VAL_PARAMS := $(shell for i in ./values-*.yaml; do echo -n "$${i} "; done))
@echo -n "Validating clustergroup schema of: "
@set -e; for i in $(VAL_PARAMS); do echo -n " $$i"; helm template common/clustergroup $(HELM_OPTS) -f "$${i}" >/dev/null; done
@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
@echo

.PHONY: validate-prereq
validate-prereq: ## verify pre-requisites
$(eval GLOBAL_PATTERN := $(shell yq -r .global.pattern values-global.yaml))
@if [ $(NAME) != $(GLOBAL_PATTERN) ]; then\
echo "";\
echo "WARNING: folder directory is \"$(NAME)\" and global.pattern is set to \"$(GLOBAL_PATTERN)\"";\
echo "this can create problems. Please make sure they are the same!";\
echo "";\
fi
@if [ ! -f /run/.containerenv ]; then\
echo "Checking prerequisites:";\
for t in $(EXECUTABLES); do if ! which $$t > /dev/null 2>&1; then echo "No $$t in PATH"; exit 1; fi; done;\
echo " Check for '$(EXECUTABLES)': OK";\
echo -n " Check for python-kubernetes: ";\
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;\
echo "OK";\
Expand All @@ -188,16 +197,16 @@ validate-prereq: ## verify pre-requisites
.PHONY: argo-healthcheck
argo-healthcheck: ## Checks if all argo applications are synced
@echo "Checking argo applications"
$(eval APPS := $(shell oc get applications -A -o jsonpath='{range .items[*]}{@.metadata.namespace}{","}{@.metadata.name}{"\n"}{end}'))
$(eval APPS := $(shell oc get applications.argoproj.io -A -o jsonpath='{range .items[*]}{@.metadata.namespace}{","}{@.metadata.name}{"\n"}{end}'))
@NOTOK=0; \
for i in $(APPS); do\
n=`echo "$${i}" | cut -f1 -d,`;\
a=`echo "$${i}" | cut -f2 -d,`;\
STATUS=`oc get -n "$${n}" application/"$${a}" -o jsonpath='{.status.sync.status}'`;\
STATUS=`oc get -n "$${n}" applications.argoproj.io/"$${a}" -o jsonpath='{.status.sync.status}'`;\
if [[ $$STATUS != "Synced" ]]; then\
NOTOK=$$(( $${NOTOK} + 1));\
fi;\
HEALTH=`oc get -n "$${n}" application/"$${a}" -o jsonpath='{.status.health.status}'`;\
HEALTH=`oc get -n "$${n}" applications.argoproj.io/"$${a}" -o jsonpath='{.status.health.status}'`;\
if [[ $$HEALTH != "Healthy" ]]; then\
NOTOK=$$(( $${NOTOK} + 1));\
fi;\
Expand All @@ -214,7 +223,7 @@ argo-healthcheck: ## Checks if all argo applications are synced
.PHONY: qe-tests
qe-tests: ## Runs the tests that QE runs
@set -e; if [ -f ./tests/interop/run_tests.sh ]; then \
./tests/interop/run_tests.sh; \
pushd ./tests/interop; ./run_tests.sh; popd; \
else \
echo "No ./tests/interop/run_tests.sh found skipping"; \
fi
Expand Down
10 changes: 5 additions & 5 deletions common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ main:
## Start Here
This repository is never used as standalone. It is usually imported in each pattern as a subtree.
In order to import the common/ the very first time you can use
`https://github.com/validatedpatterns/multicloud-gitops/blob/main/common/scripts/make_common_subtree.sh`
In order to import the common subtree the very first time you can use the script
[make_common_subtree.sh](scripts/make-common-subtree.sh).
In order to update your common subtree inside your pattern repository you can either use
`https://github.com/validatedpatterns/utilities/blob/main/scripts/update-common-everywhere.sh` or
do it manually by doing the following:
do it manually with the following commands:

```sh
git remote add -f upstream-common https://github.com/validatedpatterns/common.git
git merge -s subtree -Xtheirs -Xsubtree=common upstream-common/main
git remote add -f common-upstream https://github.com/validatedpatterns/common.git
git merge -s subtree -Xtheirs -Xsubtree=common common-upstream/main
```

## Secrets
Expand Down
5 changes: 3 additions & 2 deletions common/scripts/deploy-pattern.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
set -o pipefail

RUNS=5
RUNS=10
WAIT=15
# Retry five times because the CRD might not be fully installed yet
echo -n "Installing pattern: "
for i in $(seq 1 ${RUNS}); do \
Expand All @@ -13,7 +14,7 @@ for i in $(seq 1 ${RUNS}); do \
break;
else
echo -n "."
sleep 10
sleep "${WAIT}"
fi
done

Expand Down
4 changes: 3 additions & 1 deletion common/scripts/display-secrets-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ fi

PATTERN_NAME=$(basename "`pwd`")

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"
EXTRA_PLAYBOOK_OPTS="${EXTRA_PLAYBOOK_OPTS:-}"

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"
4 changes: 3 additions & 1 deletion common/scripts/load-k8s-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ PATTERNPATH=$(dirname "${COMMONPATH}")

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

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

ansible-playbook -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.k8s_secrets"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ "$1" = "-h" ]; then
echo "$0 <subtree_repo> <subtree_branch> <subtree_remote_name>"
echo
echo "Run without arguments, the script would run as if these arguments had been passed:"
echo "$0 https://github.com/hybrid-cloud-patterns/common.git main common-subtree"
echo "$0 https://github.com/validatedpatterns/common.git main common-upstream"
echo
echo "Please ensure the git subtree command is available. On RHEL/Fedora, the git subtree command"
echo "is in a separate package called git-subtree"
Expand Down Expand Up @@ -41,7 +41,7 @@ fi
if [ "$1" ]; then
subtree_repo=$1
else
subtree_repo=https://github.com/hybrid-cloud-patterns/common.git
subtree_repo=https://github.com/validatedpatterns/common.git
fi

if [ "$2" ]; then
Expand All @@ -53,7 +53,7 @@ fi
if [ "$3" ]; then
subtree_remote=$3
else
subtree_remote=common-subtree
subtree_remote=common-upstream
fi

git diff --quiet || (echo "This script must be run on a clean working tree" && exit 1)
Expand Down
8 changes: 6 additions & 2 deletions common/scripts/pattern-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ fi
# if we are using podman machine then we do not bind mount anything (for now!)
REMOTE_PODMAN=$(podman system connection list -q | wc -l)
if [ $REMOTE_PODMAN -eq 0 ]; then # If we are not using podman machine we check the hosts folders
# Use /etc/pki by default and try a couple of fallbacks if it does not exist
if [ -d /etc/pki ]; then
# We check /etc/pki/tls because on ubuntu /etc/pki/fwupd sometimes
# exists but not /etc/pki/tls and we do not want to bind mount in such a case
# as it would find no certificates at all.
if [ -d /etc/pki/tls ]; then
PKI_HOST_MOUNT_ARGS="-v /etc/pki:/etc/pki:ro"
elif [ -d /etc/ssl ]; then
PKI_HOST_MOUNT_ARGS="-v /etc/ssl:/etc/ssl:ro"
Expand All @@ -85,6 +87,8 @@ podman run -it --rm --pull=newer \
-e EXTRA_HELM_OPTS \
-e EXTRA_PLAYBOOK_OPTS \
-e TARGET_ORIGIN \
-e TARGET_SITE \
-e TARGET_BRANCH \
-e NAME \
-e TOKEN_SECRET \
-e TOKEN_NAMESPACE \
Expand Down
4 changes: 3 additions & 1 deletion common/scripts/process-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ PATTERNPATH=$(dirname "${COMMONPATH}")
PATTERN_NAME=${1:-$(basename "`pwd`")}
SECRETS_BACKING_STORE="$($SCRIPTPATH/determine-secretstore-backend.sh)"

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

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"
4 changes: 3 additions & 1 deletion common/scripts/vault-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ if [ -z ${TASK} ]; then
exit 1
fi

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

ansible-playbook -t "${TASK}" -e pattern_name="${PATTERN_NAME}" -e pattern_dir="${PATTERNPATH}" ${EXTRA_PLAYBOOK_OPTS} "rhvp.cluster_utils.vault"
4 changes: 3 additions & 1 deletion common/scripts/write-token-kubeconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ SCRIPTPATH=$(dirname "${SCRIPT}")
COMMONPATH=$(dirname "${SCRIPTPATH}")
PATTERNPATH=$(dirname "${COMMONPATH}")

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

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

0 comments on commit 6eeed58

Please sign in to comment.