Skip to content

Commit 45c6b50

Browse files
authored
Merge pull request #43 from dminnear-rh/common-automatic-update
Common automatic update
2 parents 3e2d455 + 3c4ae53 commit 45c6b50

13 files changed

+178
-40
lines changed
+48
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

+40-17
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 ?=
@@ -68,11 +72,7 @@ preview-%:
6872

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

7777
.PHONY: uninstall
7878
uninstall: ## runs helm uninstall
@@ -115,7 +115,7 @@ secrets-backend-none: ## Edits values files to remove secrets manager + ESO
115115
.PHONY: load-iib
116116
load-iib: ## CI target to install Index Image Bundles
117117
@set -e; if [ x$(INDEX_IMAGES) != x ]; then \
118-
ansible-playbook rhvp.cluster_utils.iib-ci; \
118+
ansible-playbook $(EXTRA_PLAYBOOK_OPTS) rhvp.cluster_utils.iib_ci; \
119119
else \
120120
echo "No INDEX_IMAGES defined. Bailing out"; \
121121
exit 1; \
@@ -129,12 +129,22 @@ token-kubeconfig: ## Create a local ~/.kube/config with password (not usually ne
129129

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

139149
.PHONY: validate-cluster
140150
validate-cluster: ## Do some cluster validations before installing
@@ -143,7 +153,7 @@ validate-cluster: ## Do some cluster validations before installing
143153
@oc cluster-info >/dev/null && echo "OK" || (echo "Error"; exit 1)
144154
@echo -n " storageclass: "
145155
@if [ `oc get storageclass -o go-template='{{printf "%d\n" (len .items)}}'` -eq 0 ]; then\
146-
echo "None Found"; exit 1;\
156+
echo "WARNING: No storageclass found";\
147157
else\
148158
echo "OK";\
149159
fi
@@ -153,15 +163,20 @@ validate-cluster: ## Do some cluster validations before installing
153163
validate-schema: ## validates values files against schema in common/clustergroup
154164
$(eval VAL_PARAMS := $(shell for i in ./values-*.yaml; do echo -n "$${i} "; done))
155165
@echo -n "Validating clustergroup schema of: "
156-
@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
157167
@echo
158168

159169
.PHONY: validate-prereq
160170
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
161178
@if [ ! -f /run/.containerenv ]; then\
162179
echo "Checking prerequisites:";\
163-
for t in $(EXECUTABLES); do if ! which $$t > /dev/null 2>&1; then echo "No $$t in PATH"; exit 1; fi; done;\
164-
echo " Check for '$(EXECUTABLES)': OK";\
165180
echo -n " Check for python-kubernetes: ";\
166181
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;\
167182
echo "OK";\
@@ -182,16 +197,16 @@ validate-prereq: ## verify pre-requisites
182197
.PHONY: argo-healthcheck
183198
argo-healthcheck: ## Checks if all argo applications are synced
184199
@echo "Checking argo applications"
185-
$(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}'))
186201
@NOTOK=0; \
187202
for i in $(APPS); do\
188203
n=`echo "$${i}" | cut -f1 -d,`;\
189204
a=`echo "$${i}" | cut -f2 -d,`;\
190-
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}'`;\
191206
if [[ $$STATUS != "Synced" ]]; then\
192207
NOTOK=$$(( $${NOTOK} + 1));\
193208
fi;\
194-
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}'`;\
195210
if [[ $$HEALTH != "Healthy" ]]; then\
196211
NOTOK=$$(( $${NOTOK} + 1));\
197212
fi;\
@@ -205,6 +220,14 @@ argo-healthcheck: ## Checks if all argo applications are synced
205220

206221
##@ Test and Linters Tasks
207222

223+
.PHONY: qe-tests
224+
qe-tests: ## Runs the tests that QE runs
225+
@set -e; if [ -f ./tests/interop/run_tests.sh ]; then \
226+
pushd ./tests/interop; ./run_tests.sh; popd; \
227+
else \
228+
echo "No ./tests/interop/run_tests.sh found skipping"; \
229+
fi
230+
208231
.PHONY: super-linter
209232
super-linter: ## Runs super linter locally
210233
rm -rf .mypy_cache

common/README.md

+5-5
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

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
4+
RUNS=10
5+
WAIT=15
6+
# Retry five times because the CRD might not be fully installed yet
7+
echo -n "Installing pattern: "
8+
for i in $(seq 1 ${RUNS}); do \
9+
exec 3>&1 4>&2
10+
OUT=$( { helm template --include-crds --name-template $* 2>&4 | oc apply -f- 2>&4 1>&3; } 4>&1 3>&1)
11+
ret=$?
12+
exec 3>&- 4>&-
13+
if [ ${ret} -eq 0 ]; then
14+
break;
15+
else
16+
echo -n "."
17+
sleep "${WAIT}"
18+
fi
19+
done
20+
21+
# All the runs failed
22+
if [ ${i} -eq ${RUNS} ]; then
23+
echo "Installation failed [${i}/${RUNS}]. Error:"
24+
echo "${OUT}"
25+
exit 1
26+
fi
27+
echo "Done"

common/scripts/display-secrets-info.sh

+3-1
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

+3-1
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

+3-3
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/manage-secret-app.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ case "$APP" in
1111
APP_NAME="vault"
1212
NAMESPACE="vault"
1313
PROJECT="$MAIN_CLUSTERGROUP_PROJECT"
14-
CHART_LOCATION="common/hashicorp-vault"
14+
CHART_NAME="hashicorp-vault"
15+
CHART_VERSION=0.1.*
16+
1517
;;
1618
"golang-external-secrets")
1719
APP_NAME="golang-external-secrets"
1820
NAMESPACE="golang-external-secrets"
1921
PROJECT="$MAIN_CLUSTERGROUP_PROJECT"
20-
CHART_LOCATION="common/golang-external-secrets"
22+
CHART_NAME="golang-external-secrets"
23+
CHART_VERSION=0.1.*
24+
2125
;;
2226
*)
2327
echo "Error - cannot manage $APP can only manage vault and golang-external-secrets"
@@ -32,13 +36,13 @@ case "$STATE" in
3236
RES=$(yq ".clusterGroup.applications[] | select(.path == \"$CHART_LOCATION\")" "$MAIN_CLUSTERGROUP_FILE" 2>/dev/null)
3337
if [ -z "$RES" ]; then
3438
echo "Application with chart location $CHART_LOCATION not found, adding"
35-
yq -i ".clusterGroup.applications.$APP_NAME = { \"name\": \"$APP_NAME\", \"namespace\": \"$NAMESPACE\", \"project\": \"$PROJECT\", \"path\": \"$CHART_LOCATION\" }" "$MAIN_CLUSTERGROUP_FILE"
39+
yq -i ".clusterGroup.applications.$APP_NAME = { \"name\": \"$APP_NAME\", \"namespace\": \"$NAMESPACE\", \"project\": \"$PROJECT\", \"chart\": \"$CHART_NAME\", \"chartVersion\": \"$CHART_VERSION\"}" "$MAIN_CLUSTERGROUP_FILE"
3640
fi
3741
;;
3842
"absent")
3943
common/scripts/manage-secret-namespace.sh "$NAMESPACE" "$STATE"
4044
echo "Removing application wth chart location $CHART_LOCATION"
41-
yq -i "del(.clusterGroup.applications[] | select(.path == \"$CHART_LOCATION\"))" "$MAIN_CLUSTERGROUP_FILE"
45+
yq -i "del(.clusterGroup.applications[] | select(.chart == \"$CHART_NAME\"))" "$MAIN_CLUSTERGROUP_FILE"
4246
;;
4347
*)
4448
echo "$STATE not supported"

common/scripts/pattern-util.sh

+18-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function version {
1111
if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
1212
PATTERN_UTILITY_CONTAINER="quay.io/hybridcloudpatterns/utility-container"
1313
fi
14+
# If PATTERN_DISCONNECTED_HOME is set it will be used to populate both PATTERN_UTILITY_CONTAINER
15+
# and PATTERN_INSTALL_CHART automatically
16+
if [ -n "${PATTERN_DISCONNECTED_HOME}" ]; then
17+
PATTERN_UTILITY_CONTAINER="${PATTERN_DISCONNECTED_HOME}/utility-container"
18+
PATTERN_INSTALL_CHART="oci://${PATTERN_DISCONNECTED_HOME}/pattern-install"
19+
echo "PATTERN_DISCONNECTED_HOME is set to ${PATTERN_DISCONNECTED_HOME}"
20+
echo "Setting the following variables:"
21+
echo " PATTERN_UTILITY_CONTAINER: ${PATTERN_UTILITY_CONTAINER}"
22+
echo " PATTERN_INSTALL_CHART: ${PATTERN_INSTALL_CHART}"
23+
fi
1424

1525
readonly commands=(podman)
1626
for cmd in ${commands[@]}; do is_available "$cmd"; done
@@ -54,8 +64,10 @@ fi
5464
# if we are using podman machine then we do not bind mount anything (for now!)
5565
REMOTE_PODMAN=$(podman system connection list -q | wc -l)
5666
if [ $REMOTE_PODMAN -eq 0 ]; then # If we are not using podman machine we check the hosts folders
57-
# Use /etc/pki by default and try a couple of fallbacks if it does not exist
58-
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
5971
PKI_HOST_MOUNT_ARGS="-v /etc/pki:/etc/pki:ro"
6072
elif [ -d /etc/ssl ]; then
6173
PKI_HOST_MOUNT_ARGS="-v /etc/ssl:/etc/ssl:ro"
@@ -75,11 +87,15 @@ podman run -it --rm --pull=newer \
7587
-e EXTRA_HELM_OPTS \
7688
-e EXTRA_PLAYBOOK_OPTS \
7789
-e TARGET_ORIGIN \
90+
-e TARGET_SITE \
91+
-e TARGET_BRANCH \
7892
-e NAME \
7993
-e TOKEN_SECRET \
8094
-e TOKEN_NAMESPACE \
8195
-e VALUES_SECRET \
8296
-e KUBECONFIG \
97+
-e PATTERN_INSTALL_CHART \
98+
-e PATTERN_DISCONNECTED_HOME \
8399
-e K8S_AUTH_HOST \
84100
-e K8S_AUTH_VERIFY_SSL \
85101
-e K8S_AUTH_SSL_CA_CERT \

common/scripts/preview.sh

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
# DISCLAIMER
44
#
5-
# - Parsing of applications needs to be more clever. Currently the code assumes that all
6-
# targets will be local charts. This is not true, for example, in industrial-edge.
5+
# - Parsing of applications needs to be more clever.
76
# - There is currently not a mechanism to actually preview against multiple clusters
87
# (i.e. a hub and a remote). All previews will be done against the current.
98
# - Make output can be included in the YAML.
@@ -22,11 +21,22 @@ if [ "${APPNAME}" != "clustergroup" ]; then
2221
# path: charts/all/foo
2322
# So we retrieve the actual index ("foobar") given the name attribute of the application
2423
APP=$(yq ".clusterGroup.applications | with_entries(select(.value.name == \"$APPNAME\")) | keys | .[0]" values-$SITE.yaml)
25-
chart=$(yq ".clusterGroup.applications.$APP.path" values-$SITE.yaml)
24+
isLocalHelmChart=$(yq ".clusterGroup.applications.$APP.path" values-$SITE.yaml)
25+
if [ $isLocalHelmChart != "null" ]; then
26+
chart=$(yq ".clusterGroup.applications.$APP.path" values-$SITE.yaml)
27+
else
28+
helmrepo=$(yq ".clusterGroup.applications.$APP.repoURL" values-$SITE.yaml)
29+
helmrepo="${helmrepo:+oci://quay.io/hybridcloudpatterns}"
30+
chartversion=$(yq ".clusterGroup.applications.$APP.chartVersion" values-$SITE.yaml)
31+
chartname=$(yq ".clusterGroup.applications.$APP.chart" values-$SITE.yaml)
32+
chart="${helmrepo}/${chartname} --version ${chartversion}"
33+
fi
2634
namespace=$(yq ".clusterGroup.applications.$APP.namespace" values-$SITE.yaml)
2735
else
2836
APP=$APPNAME
29-
chart="common/clustergroup"
37+
clusterGroupChartVersion=$(yq ".main.multiSourceConfig.clusterGroupChartVersion" values-global.yaml)
38+
helmrepo="oci://quay.io/hybridcloudpatterns"
39+
chart="${helmrepo}/clustergroup --version ${clusterGroupChartVersion}"
3040
namespace="openshift-operators"
3141
fi
3242
pattern=$(yq ".global.pattern" values-global.yaml)

0 commit comments

Comments
 (0)