diff --git a/.github/workflows/pattern-sh-ci.yml b/.github/workflows/pattern-sh-ci.yml index 7bffa821..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 @@ -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 64dd0811..cd017ab7 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 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 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