Skip to content

Commit b34902b

Browse files
authored
Merge pull request #488 from validatedpatterns/main
sync: main to rhdp-deploy
2 parents 6fe5368 + 5895b33 commit b34902b

File tree

6 files changed

+94
-27
lines changed

6 files changed

+94
-27
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@ef53f7802613611d813f0c58e48819c8e9a3a3fe
18+
uses: ansible/ansible-lint@d7cd7cfa2469536527aceaef9ef2ec6f2fb331cb

.github/workflows/sync-rhdp-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
persist-credentials: false
2424
- name: Set up Node
25-
uses: actions/setup-node@v5
25+
uses: actions/setup-node@v6
2626
with:
2727
node-version: 20
2828
- name: Opening pull request

common/.github/workflows/pattern-sh-ci.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
# Fedora is not an option yet
21-
os: [ubuntu-latest, ubuntu-22.04]
21+
os: [ubuntu-latest, ubuntu-22.04, ubuntu-24.04-arm]
2222
runs-on: ${{ matrix.os }}
2323
permissions:
2424
contents: read
@@ -29,12 +29,6 @@ jobs:
2929
with:
3030
persist-credentials: false
3131

32-
- name: Install Podman on Ubuntu
33-
if: contains(matrix.os, 'ubuntu')
34-
run: |
35-
sudo apt-get update
36-
sudo apt-get install -y podman
37-
3832
# Currently we do not do MacOSX as it is not free, maybe in the future
3933
# - name: Install Podman on macOS
4034
# if: contains(matrix.os, 'macos')
@@ -46,7 +40,14 @@ jobs:
4640
- name: Verify Podman Installation
4741
run: podman --version
4842

43+
- name: Clone MCG and update common
44+
run: |
45+
git clone --depth 1 https://github.com/hybrid-cloud-patterns/multicloud-gitops mcg
46+
cp -r scripts/ mcg/common/scripts
47+
cp Makefile mcg/common
48+
4949
- name: Run pattern.sh script
5050
run: |
51-
export TARGET_BRANCH=main
52-
./scripts/pattern-util.sh make validate-origin
51+
cd mcg
52+
./pattern.sh make validate-origin
53+
./pattern.sh make show

common/Makefile

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
NAME ?= $(shell basename "`pwd`")
1+
PATTERN_NAME ?= $(shell yq .global.pattern values-global.yaml)
2+
3+
ifeq ($(PATTERN_NAME),)
4+
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
5+
endif
6+
ifeq ($(PATTERN_NAME),null)
7+
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
8+
endif
29

310
ifneq ($(origin TARGET_SITE), undefined)
411
TARGET_SITE_OPT=--set main.clusterGroupName=$(TARGET_SITE)
@@ -76,14 +83,14 @@ PATTERN_INSTALL_CHART ?= oci://quay.io/hybridcloudpatterns/pattern-install
7683

7784
.PHONY: help
7885
help: ## This help message
79-
@echo "Pattern: $(NAME)"
86+
@echo "Pattern: $(PATTERN_NAME)"
8087
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^(\s|[a-zA-Z_0-9-])+:.*?##/ { printf " \033[36m%-35s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
8188

8289
# Makefiles in the individual patterns should call these targets explicitly
8390
# e.g. from industrial-edge: make -f common/Makefile show
8491
.PHONY: show
8592
show: ## show the starting template without installing it
86-
helm template $(PATTERN_INSTALL_CHART) --name-template $(NAME) $(HELM_OPTS)
93+
helm template $(PATTERN_INSTALL_CHART) --name-template $(PATTERN_NAME) $(HELM_OPTS)
8794

8895
preview-all: ## (EXPERIMENTAL) Previews all applications on hub and managed clusters
8996
@echo "NOTE: This is just a tentative approximation of rendering all hub and managed clusters templates"
@@ -95,21 +102,21 @@ preview-%:
95102

96103
.PHONY: operator-deploy
97104
operator-deploy operator-upgrade: validate-prereq $(VALIDATE_ORIGIN) validate-cluster ## runs helm install
98-
@common/scripts/deploy-pattern.sh $(NAME) $(PATTERN_INSTALL_CHART) $(HELM_OPTS)
105+
@common/scripts/deploy-pattern.sh $(PATTERN_NAME) $(PATTERN_INSTALL_CHART) $(HELM_OPTS)
99106

100107
.PHONY: uninstall
101108
uninstall: ## runs helm uninstall
102109
$(eval CSV := $(shell oc get subscriptions -n openshift-operators openshift-gitops-operator -ojsonpath={.status.currentCSV}))
103-
helm uninstall $(NAME)
110+
helm uninstall $(PATTERN_NAME)
104111
@oc delete csv -n openshift-operators $(CSV)
105112

106113
.PHONY: load-secrets
107114
load-secrets: ## loads the secrets into the backend determined by values-global setting
108-
common/scripts/process-secrets.sh $(NAME)
115+
common/scripts/process-secrets.sh $(PATTERN_NAME)
109116

110117
.PHONY: legacy-load-secrets
111118
legacy-load-secrets: ## loads the secrets into vault (only)
112-
common/scripts/vault-utils.sh push_secrets $(NAME)
119+
common/scripts/vault-utils.sh push_secrets $(PATTERN_NAME)
113120

114121
.PHONY: secrets-backend-vault
115122
secrets-backend-vault: ## Edits values files to use default Vault+ESO secrets config
@@ -189,13 +196,7 @@ validate-schema: ## validates values files against schema in common/clustergroup
189196

190197
.PHONY: validate-prereq
191198
validate-prereq: ## verify pre-requisites
192-
$(eval GLOBAL_PATTERN := $(shell yq -r .global.pattern values-global.yaml))
193-
@if [ $(NAME) != $(GLOBAL_PATTERN) ]; then\
194-
echo "";\
195-
echo "WARNING: folder directory is \"$(NAME)\" and global.pattern is set to \"$(GLOBAL_PATTERN)\"";\
196-
echo "this can create problems. Please make sure they are the same!";\
197-
echo "";\
198-
fi
199+
@common/scripts/validate-names-length.sh
199200
@if [ ! -f /run/.containerenv ]; then\
200201
echo "Checking prerequisites:";\
201202
echo -n " Check for python-kubernetes: ";\

common/scripts/pattern-util.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function version {
99
}
1010

1111
if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
12-
PATTERN_UTILITY_CONTAINER="quay.io/hybridcloudpatterns/utility-container"
12+
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
1313
fi
1414
# If PATTERN_DISCONNECTED_HOME is set it will be used to populate both PATTERN_UTILITY_CONTAINER
1515
# and PATTERN_INSTALL_CHART automatically
@@ -89,7 +89,7 @@ podman run -it --rm --pull=newer \
8989
-e TARGET_ORIGIN \
9090
-e TARGET_SITE \
9191
-e TARGET_BRANCH \
92-
-e NAME \
92+
-e PATTERN_NAME \
9393
-e TOKEN_SECRET \
9494
-e TOKEN_NAMESPACE \
9595
-e VALUES_SECRET \
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
MAX_CALCULATED_LENGTH=47
4+
5+
print_explanation() {
6+
echo "--------------------------------------------------------------------------------"
7+
echo "Validation Explanation:"
8+
echo "This script ensures that generated Kubernetes resource names do not exceed the 63-character limit."
9+
echo "A DNS-compatible name is constructed in the 'clustergroup' Helm chart using the following pattern:"
10+
echo " -> {{ .Values.clusterGroup.name }}-gitops-server-{{ .Values.global.pattern }}-{{ .Values.clusterGroup.name }}"
11+
echo ""
12+
echo "The total length is calculated as:"
13+
echo " (2 * length of 'clusterGroup.name') + length of 'global.pattern' + 15 (for '-gitops-server-') + 1 (for the namespace separator '-')"
14+
echo ""
15+
echo "To stay under the 63-character limit, the variable part of the name must be less than $MAX_CALCULATED_LENGTH characters:"
16+
echo " (2 * length of 'clusterGroup.name') + length of 'global.pattern' < $MAX_CALCULATED_LENGTH"
17+
echo "--------------------------------------------------------------------------------"
18+
}
19+
20+
if [ ! -f "values-global.yaml" ]; then
21+
echo "Error: Global values file 'values-global.yaml' not found."
22+
exit 1
23+
fi
24+
25+
global_pattern=$(yq .global.pattern "values-global.yaml")
26+
27+
if [ "$global_pattern" == "null" ] || [ -z "$global_pattern" ]; then
28+
echo "Error: '.global.pattern' not found or is empty in 'values-global.yaml'."
29+
exit 1
30+
fi
31+
pattern_length=${#global_pattern}
32+
33+
echo "Validating that the pattern and clustergroup names don't exceed DNS limits after the pattern is installed."
34+
echo ""
35+
36+
validation_failed=false
37+
38+
for file in values-*.yaml; do
39+
group_name=$(yq .clusterGroup.name "$file")
40+
41+
if [ "$group_name" != "null" ] && [ -n "$group_name" ]; then
42+
group_name_length=${#group_name}
43+
total_length=$(( (2 * group_name_length) + pattern_length ))
44+
45+
echo "Checking file: $file"
46+
47+
if [ "$total_length" -ge "$MAX_CALCULATED_LENGTH" ]; then
48+
echo " -> FAILED: Length of clustergroup '$group_name' and pattern '$global_pattern' will exceed DNS limits in clustergroup chart. Please shorten one or both."
49+
echo ""
50+
validation_failed=true
51+
else
52+
echo " -> PASSED: Length of clustergroup '$group_name' and pattern '$global_pattern' are within clustergroup chart limits."
53+
echo ""
54+
fi
55+
fi
56+
done
57+
58+
if $validation_failed; then
59+
echo "One or more cluster group names failed the length validation."
60+
print_explanation
61+
exit 1
62+
else
63+
echo "All names are within clustergroup chart limits."
64+
exit 0
65+
fi

0 commit comments

Comments
 (0)