Skip to content

Common automatic update #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e9f00b1
Improve validate-origin
mbaldessari Oct 14, 2024
8dfad49
Make the make install output less daunting
mbaldessari Oct 15, 2024
393cc67
Merge pull request #610 from mbaldessari/bettercheck
mbaldessari Oct 19, 2024
fd3330d
Merge pull request #611 from mbaldessari/silence-warning
mbaldessari Oct 19, 2024
c9f1fdd
Record the exit code at the right time
mbaldessari Oct 22, 2024
cacdd23
Merge pull request #612 from mbaldessari/fix-issue
darkdoc Oct 22, 2024
9a24f6f
Fix path when invoking the qe run_test.sh script
mbaldessari Nov 25, 2024
7f6043d
Merge pull request #613 from mbaldessari/fix-qe-command
mbaldessari Nov 25, 2024
0d9d51a
Add a warning when pattern folder and pattern name differ
mbaldessari Dec 19, 2024
0cc13f6
Drop some old and unused prereq test
mbaldessari Dec 19, 2024
c0b5d25
Merge pull request #614 from mbaldessari/warning-fixes
mbaldessari Dec 19, 2024
5063467
Fix validated-schema make target
mbaldessari Jan 7, 2025
6be5db5
Merge pull request #615 from mbaldessari/fix-validated-schema
mbaldessari Jan 7, 2025
250c154
Wait some more before giving up
mbaldessari Jan 14, 2025
b630203
Merge pull request #616 from mbaldessari/wait-more
mbaldessari Jan 14, 2025
cc36e1f
Fix argo-healthcheck target
mbaldessari Jan 22, 2025
a472f72
Merge pull request #617 from mbaldessari/improve-check
mbaldessari Jan 22, 2025
e3e7add
Push TARGET_SITE into the in-container variables
mbaldessari Feb 4, 2025
b9140d1
Merge pull request #618 from mbaldessari/target_site
mbaldessari Feb 4, 2025
0746c6e
Do not bind mount /etc/pki blindly
mbaldessari Feb 7, 2025
c0c2c1e
Merge pull request #619 from mbaldessari/etc-pki
mbaldessari Feb 7, 2025
98744fb
Add a CI job for pattern.sh
mbaldessari Feb 9, 2025
7c950f6
Allow TARGET_BRANCH to be overridden
mbaldessari Feb 10, 2025
46af202
Restrict GH actions only to certain files
mbaldessari Feb 10, 2025
4d4de10
Merge pull request #620 from mbaldessari/pattern-sh-ci-job
mbaldessari Feb 10, 2025
39882c7
propagate the env var EXTRA_PLAYBOOK_OPTS to our ansible-playbook com…
dminnear-rh Feb 25, 2025
5315266
Merge pull request #621 from dminnear-rh/propagate-extra-playbook-opts
mbaldessari Feb 25, 2025
ba9feab
update how to make common subtree
dminnear-rh Feb 27, 2025
7d184fb
Merge pull request #622 from dminnear-rh/update-how-to-use-common-sub…
mbaldessari Feb 27, 2025
f266b7c
Merge remote-tracking branch 'common-upstream/main' into common-autom…
dminnear-rh Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
49 changes: 32 additions & 17 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 @@ -68,11 +72,7 @@ preview-%:

.PHONY: operator-deploy
operator-deploy operator-upgrade: validate-prereq validate-origin validate-cluster ## runs helm install
@set -e -o pipefail
# Retry five times because the CRD might not be fully installed yet
for i in {1..5}; do \
helm template --include-crds --name-template $(NAME) $(PATTERN_INSTALL_CHART) $(HELM_OPTS) | oc apply -f- && break || sleep 10; \
done
@common/scripts/deploy-pattern.sh $(NAME) $(PATTERN_INSTALL_CHART) $(HELM_OPTS)

.PHONY: uninstall
uninstall: ## runs helm uninstall
Expand Down Expand Up @@ -115,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 All @@ -129,12 +129,22 @@ token-kubeconfig: ## Create a local ~/.kube/config with password (not usually ne

# We only check the remote ssh git branch's existance if we're not running inside a container
# as getting ssh auth working inside a container seems a bit brittle
# If the main repoUpstreamURL field is set, then we need to check against
# that and not target_repo
.PHONY: validate-origin
validate-origin: ## verify the git origin is available
@echo "Checking repository:"
@echo -n " $(TARGET_REPO) - branch '$(TARGET_BRANCH)': "
@git ls-remote --exit-code --heads $(TARGET_REPO) $(TARGET_BRANCH) >/dev/null &&\
echo "OK" || (echo "NOT FOUND"; exit 1)
$(eval UPSTREAMURL := $(shell yq -r '.main.git.repoUpstreamURL // (.main.git.repoUpstreamURL = "")' values-global.yaml))
@if [ -z "$(UPSTREAMURL)" ]; then\
echo -n " $(TARGET_REPO) - branch '$(TARGET_BRANCH)': ";\
git ls-remote --exit-code --heads $(TARGET_REPO) $(TARGET_BRANCH) >/dev/null &&\
echo "OK" || (echo "NOT FOUND"; exit 1);\
else\
echo "Upstream URL set to: $(UPSTREAMURL)";\
echo -n " $(UPSTREAMURL) - branch '$(TARGET_BRANCH)': ";\
git ls-remote --exit-code --heads $(UPSTREAMURL) $(TARGET_BRANCH) >/dev/null &&\
echo "OK" || (echo "NOT FOUND"; exit 1);\
fi

.PHONY: validate-cluster
validate-cluster: ## Do some cluster validations before installing
Expand All @@ -153,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 @@ -182,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 @@ -208,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
27 changes: 27 additions & 0 deletions common/scripts/deploy-pattern.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -o pipefail

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 \
exec 3>&1 4>&2
OUT=$( { helm template --include-crds --name-template $* 2>&4 | oc apply -f- 2>&4 1>&3; } 4>&1 3>&1)
ret=$?
exec 3>&- 4>&-
if [ ${ret} -eq 0 ]; then
break;
else
echo -n "."
sleep "${WAIT}"
fi
done

# All the runs failed
if [ ${i} -eq ${RUNS} ]; then
echo "Installation failed [${i}/${RUNS}]. Error:"
echo "${OUT}"
exit 1
fi
echo "Done"
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"