From a1b23c848c033d24fbe6b33766783eeefc347735 Mon Sep 17 00:00:00 2001 From: Drew Minnear Date: Tue, 7 Oct 2025 13:30:17 -0400 Subject: [PATCH 1/5] add script to validate length of clustergroup chart and pattern names --- Makefile | 10 +---- scripts/validate-names-length.sh | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) create mode 100755 scripts/validate-names-length.sh diff --git a/Makefile b/Makefile index 64dd0811..0d47fcf9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -NAME ?= $(shell basename "`pwd`") +NAME ?= $(shell yq .global.pattern values-global.yaml) ifneq ($(origin TARGET_SITE), undefined) TARGET_SITE_OPT=--set main.clusterGroupName=$(TARGET_SITE) @@ -189,13 +189,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/validate-names-length.sh b/scripts/validate-names-length.sh new file mode 100755 index 00000000..3763832d --- /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 3d7bfad41d0ce1a167bc883aaaa2dc9fa31d1680 Mon Sep 17 00:00:00 2001 From: Drew Minnear Date: Wed, 8 Oct 2025 09:26:22 -0400 Subject: [PATCH 2/5] enforce that pattern name is set in values-global.yaml --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 0d47fcf9..cd017ab7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,12 @@ 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) endif From d286c3c864a1f02e07015cfa492addaebf024ff0 Mon Sep 17 00:00:00 2001 From: Drew Minnear Date: Wed, 8 Oct 2025 09:48:08 -0400 Subject: [PATCH 3/5] update ci workflow to test common updates on MCG --- .github/workflows/pattern-sh-ci.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pattern-sh-ci.yml b/.github/workflows/pattern-sh-ci.yml index 7bffa821..a92289d2 100644 --- a/.github/workflows/pattern-sh-ci.yml +++ b/.github/workflows/pattern-sh-ci.yml @@ -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 From c9ee2e03a69b709bf8c9a4997eebb12e290c11bd Mon Sep 17 00:00:00 2001 From: Drew Minnear Date: Wed, 8 Oct 2025 09:51:42 -0400 Subject: [PATCH 4/5] reference utility container from validatedpatterns quay org --- scripts/pattern-util.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pattern-util.sh b/scripts/pattern-util.sh index 4b75f437..f28294bd 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 From ff07a5f75ee49afa3e92acbd6a991ae2b8670ab8 Mon Sep 17 00:00:00 2001 From: Drew Minnear Date: Wed, 8 Oct 2025 09:52:54 -0400 Subject: [PATCH 5/5] add arm runner for common scripts test --- .github/workflows/pattern-sh-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pattern-sh-ci.yml b/.github/workflows/pattern-sh-ci.yml index a92289d2..a8209013 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