From 7e92e29b2d79bc550bcc856e2dba72de830d7641 Mon Sep 17 00:00:00 2001 From: Drew Minnear Date: Thu, 9 Oct 2025 12:24:14 -0400 Subject: [PATCH 1/2] Add script to validate length of clustergroup chart and pattern names (#643) * add script to validate length of clustergroup chart and pattern names * enforce that pattern name is set in values-global.yaml * update ci workflow to test common updates on MCG * reference utility container from validatedpatterns quay org * add arm runner for common scripts test --- .github/workflows/pattern-sh-ci.yml | 19 +++++---- Makefile | 17 ++++---- scripts/pattern-util.sh | 2 +- scripts/validate-names-length.sh | 65 +++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 18 deletions(-) create mode 100755 scripts/validate-names-length.sh diff --git a/.github/workflows/pattern-sh-ci.yml b/.github/workflows/pattern-sh-ci.yml index 7bffa821b..a82090133 100644 --- a/.github/workflows/pattern-sh-ci.yml +++ b/.github/workflows/pattern-sh-ci.yml @@ -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 @@ -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') @@ -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 diff --git a/Makefile b/Makefile index 64dd0811c..cd017ab79 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,11 @@ -NAME ?= $(shell basename "`pwd`") +NAME ?= $(shell yq .global.pattern values-global.yaml) + +ifeq ($(NAME),) +$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern) +endif +ifeq ($(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) @@ -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: ";\ diff --git a/scripts/pattern-util.sh b/scripts/pattern-util.sh index 4b75f4379..f28294bd1 100755 --- a/scripts/pattern-util.sh +++ b/scripts/pattern-util.sh @@ -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 diff --git a/scripts/validate-names-length.sh b/scripts/validate-names-length.sh new file mode 100755 index 000000000..3763832d5 --- /dev/null +++ b/scripts/validate-names-length.sh @@ -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 From 8070bfba3f23168a20c794094fe2928d1ce112bb Mon Sep 17 00:00:00 2001 From: Michele Baldessari Date: Thu, 23 Oct 2025 16:19:13 +0200 Subject: [PATCH 2/2] Rename NAME to PATTERN_NAME Apparently WSL overrides this env variable making things quite confusing so let's use something more unique --- Makefile | 18 +++++++++--------- scripts/pattern-util.sh | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index cd017ab79..96df55a77 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -NAME ?= $(shell yq .global.pattern values-global.yaml) +PATTERN_NAME ?= $(shell yq .global.pattern values-global.yaml) -ifeq ($(NAME),) +ifeq ($(PATTERN_NAME),) $(error Pattern name MUST be set in values-global.yaml with the value .global.pattern) endif -ifeq ($(NAME),null) +ifeq ($(PATTERN_NAME),null) $(error Pattern name MUST be set in values-global.yaml with the value .global.pattern) endif @@ -83,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\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" @@ -102,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 diff --git a/scripts/pattern-util.sh b/scripts/pattern-util.sh index f28294bd1..30f8b219c 100755 --- a/scripts/pattern-util.sh +++ b/scripts/pattern-util.sh @@ -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 \