Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions common/.github/workflows/pattern-sh-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
# Fedora is not an option yet
os: [ubuntu-latest, ubuntu-22.04]
os: [ubuntu-latest, ubuntu-22.04, ubuntu-24.04-arm]
runs-on: ${{ matrix.os }}
permissions:
contents: read
Expand All @@ -29,12 +29,6 @@ jobs:
with:
persist-credentials: false

- 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')
Expand All @@ -46,7 +40,14 @@ jobs:
- name: Verify Podman Installation
run: podman --version

- name: Clone MCG and update common
run: |
git clone --depth 1 https://github.com/hybrid-cloud-patterns/multicloud-gitops mcg
cp -r scripts/ mcg/common/scripts
cp Makefile mcg/common

- name: Run pattern.sh script
run: |
export TARGET_BRANCH=main
./scripts/pattern-util.sh make validate-origin
cd mcg
./pattern.sh make validate-origin
./pattern.sh make show
29 changes: 15 additions & 14 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
NAME ?= $(shell basename "`pwd`")
PATTERN_NAME ?= $(shell yq .global.pattern values-global.yaml)

ifeq ($(PATTERN_NAME),)
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
endif
ifeq ($(PATTERN_NAME),null)
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
endif

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

.PHONY: help
help: ## This help message
@echo "Pattern: $(NAME)"
@echo "Pattern: $(PATTERN_NAME)"
@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)

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

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

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

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

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

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

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

.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
@common/scripts/validate-names-length.sh
@if [ ! -f /run/.containerenv ]; then\
echo "Checking prerequisites:";\
echo -n " Check for python-kubernetes: ";\
Expand Down
4 changes: 2 additions & 2 deletions common/scripts/pattern-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function version {
}

if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
PATTERN_UTILITY_CONTAINER="quay.io/hybridcloudpatterns/utility-container"
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
fi
# If PATTERN_DISCONNECTED_HOME is set it will be used to populate both PATTERN_UTILITY_CONTAINER
# and PATTERN_INSTALL_CHART automatically
Expand Down Expand Up @@ -89,7 +89,7 @@ podman run -it --rm --pull=newer \
-e TARGET_ORIGIN \
-e TARGET_SITE \
-e TARGET_BRANCH \
-e NAME \
-e PATTERN_NAME \
-e TOKEN_SECRET \
-e TOKEN_NAMESPACE \
-e VALUES_SECRET \
Expand Down
65 changes: 65 additions & 0 deletions common/scripts/validate-names-length.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

MAX_CALCULATED_LENGTH=47

print_explanation() {
echo "--------------------------------------------------------------------------------"
echo "Validation Explanation:"
echo "This script ensures that generated Kubernetes resource names do not exceed the 63-character limit."
echo "A DNS-compatible name is constructed in the 'clustergroup' Helm chart using the following pattern:"
echo " -> {{ .Values.clusterGroup.name }}-gitops-server-{{ .Values.global.pattern }}-{{ .Values.clusterGroup.name }}"
echo ""
echo "The total length is calculated as:"
echo " (2 * length of 'clusterGroup.name') + length of 'global.pattern' + 15 (for '-gitops-server-') + 1 (for the namespace separator '-')"
echo ""
echo "To stay under the 63-character limit, the variable part of the name must be less than $MAX_CALCULATED_LENGTH characters:"
echo " (2 * length of 'clusterGroup.name') + length of 'global.pattern' < $MAX_CALCULATED_LENGTH"
echo "--------------------------------------------------------------------------------"
}

if [ ! -f "values-global.yaml" ]; then
echo "Error: Global values file 'values-global.yaml' not found."
exit 1
fi

global_pattern=$(yq .global.pattern "values-global.yaml")

if [ "$global_pattern" == "null" ] || [ -z "$global_pattern" ]; then
echo "Error: '.global.pattern' not found or is empty in 'values-global.yaml'."
exit 1
fi
pattern_length=${#global_pattern}

echo "Validating that the pattern and clustergroup names don't exceed DNS limits after the pattern is installed."
echo ""

validation_failed=false

for file in values-*.yaml; do
group_name=$(yq .clusterGroup.name "$file")

if [ "$group_name" != "null" ] && [ -n "$group_name" ]; then
group_name_length=${#group_name}
total_length=$(( (2 * group_name_length) + pattern_length ))

echo "Checking file: $file"

if [ "$total_length" -ge "$MAX_CALCULATED_LENGTH" ]; then
echo " -> FAILED: Length of clustergroup '$group_name' and pattern '$global_pattern' will exceed DNS limits in clustergroup chart. Please shorten one or both."
echo ""
validation_failed=true
else
echo " -> PASSED: Length of clustergroup '$group_name' and pattern '$global_pattern' are within clustergroup chart limits."
echo ""
fi
fi
done

if $validation_failed; then
echo "One or more cluster group names failed the length validation."
print_explanation
exit 1
else
echo "All names are within clustergroup chart limits."
exit 0
fi